Skip to content

Commit

Permalink
Merge pull request #19 from BaguettePHP/fix/range-of-array-list
Browse files Browse the repository at this point in the history
Fix @int[] type to accept 0
  • Loading branch information
zonuexe authored Sep 2, 2022
2 parents 2ecdb2e + e47771a commit 010a014
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Replacer/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function replaceHolder($pdo, $key, $type, $value, &$bind_values)
throw new \LogicException('Validation Error.');
}

if ($value !== '0' && !\preg_match('/\A(?:-?[1-9][0-9]*)(?:,-?[1-9][0-9]*)*\z/', $valuesString)) {
if ($valuesString !== '0' && !\preg_match('/\A(?:-?[1-9][0-9]*|0)(?:,(?:-?[1-9][0-9]*|0))*\z/', $valuesString)) {
throw new \DomainException(\sprintf('param "%s" must be int array', $key));
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Replacer/PlaceholderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,20 @@ public function acceptDataProvider()
['int', '0', 0],
['int', '9223372036854775807', 9223372036854775807],
['int', '-9223372036854775808', (int)'-9223372036854775808'],
['int[]', [0], '0'],
['int[]', ['0'], '0'],
['int[]', [0, 0], '0,0'],
['int[]', ['0', '0'], '0,0'],
['int[]', [1, 2, 3], '1,2,3'],
['int[]', ['1', '2', '3'], '1,2,3'],
['int[]', [0, 1, 2, 3], '0,1,2,3'],
['int[]', ['0', '1', '2', '3'], '0,1,2,3'],
['int[]', [1, 0, 2, 3], '1,0,2,3'],
['int[]', ['1', '0', '2', '3'], '1,0,2,3'],
['int[]', [1, 2, 0, 3], '1,2,0,3'],
['int[]', ['1', '2', '0', '3'], '1,2,0,3'],
['int[]', [1, 2, 3, 0], '1,2,3,0'],
['int[]', ['1', '2', '3', '0'], '1,2,3,0'],
['int[]',
['9223372036854775807', '-9223372036854775808'],
'9223372036854775807,-9223372036854775808',
Expand Down Expand Up @@ -105,11 +117,15 @@ public function rejeceptDataProvider()
['@piyo', null, 'unexpected type "@piyo"'],
['@ascdesc', 'foo', 'param ":key" must be "ASC", "DESC", "asc" or "desc"'],
['@int', '-0', 'param ":key" is unexpected integer notation'],
['@int', '00', 'param ":key" is unexpected integer notation'],
['@int', '9223372036854775808', 'param ":key" is integer out of range.'],
['@int', '-9223372036854775809', 'param ":key" is integer out of range.'],
['@int[]', 0, 'param ":key" must be int array'],
['@int[]', [], 'param ":key" must be not empty int array'],
['@int[]', ['1', 'a', '3'], 'param ":key[1]" is integer out of range.'],
['@int[]', ['00'], 'param ":key" must be int array'],
['@int[]', ['9223372036854775808'], 'param ":key[0]" is integer out of range.'],
['@int[]', ['-9223372036854775809'], 'param ":key[0]" is integer out of range.'],
['@string', [], 'param ":key" must be string or numeric'],
['@string[]', '', 'param ":key" must be string array'],
['@string[]', [], 'param ":key" must be not empty string array'],
Expand Down
2 changes: 1 addition & 1 deletion tools/.phpstan/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"require": {
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.2"
"phpstan/phpstan-strict-rules": "^1.4"
},
"config": {
"optimize-autoloader": true,
Expand Down

0 comments on commit 010a014

Please sign in to comment.