Skip to content

Commit cc7d5bb

Browse files
committed
Fix [][] deep array false warning.
1 parent a93ac84 commit cc7d5bb

File tree

8 files changed

+33
-17
lines changed

8 files changed

+33
-17
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ end_of_line = crlf
1616
[*.yml]
1717
indent_style = space
1818
indent_size = 2
19+
20+
[*.neon]
21+
indent_style = space

PSR2R/Sniffs/Commenting/DocBlockReturnSelfSniff.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ public function process(File $phpCsFile, $stackPointer) {
7575
}
7676
}
7777

78-
/** @noinspection MoreThanThreeArgumentsInspection */
79-
8078
/**
8179
* @param \PHP_CodeSniffer\Files\File $phpCsFile
8280
* @param int $classNameIndex
83-
* @param array $parts
81+
* @param string[] $parts
8482
* @param string $appendix
8583
*
8684
* @return void

PSR2R/Sniffs/Commenting/FullyQualifiedClassNameInDocBlockSniff.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function fixClassNames(File $phpCsFile, $classNameIndex, array $classN
111111
/**
112112
* @param \PHP_CodeSniffer\Files\File $phpCsFile
113113
* @param int $classNameIndex
114-
* @param array &$classNames
114+
* @param string[] $classNames
115115
*
116116
* @return array
117117
*/
@@ -122,9 +122,9 @@ protected function generateClassNameMap(File $phpCsFile, $classNameIndex, array
122122
if (strpos($className, '\\') !== false) {
123123
continue;
124124
}
125-
$arrayOfObject = false;
126-
if (substr($className, -2) === '[]') {
127-
$arrayOfObject = true;
125+
$arrayOfObject = 0;
126+
while (substr($className, -2) === '[]') {
127+
$arrayOfObject++;
128128
$className = substr($className, 0, -2);
129129
}
130130
if (in_array($className, static::$whitelistedTypes)) {
@@ -139,8 +139,8 @@ protected function generateClassNameMap(File $phpCsFile, $classNameIndex, array
139139
$phpCsFile->addError(sprintf($message, $className), $classNameIndex, 'ClassNameInvalid');
140140
continue;
141141
}
142-
$classNames[$key] = $useStatement . ($arrayOfObject ? '[]' : '');
143-
$result[$className . ($arrayOfObject ? '[]' : '')] = $classNames[$key];
142+
$classNames[$key] = $useStatement . ($arrayOfObject ? str_repeat('[]', $arrayOfObject) : '');
143+
$result[$className . ($arrayOfObject ? str_repeat('[]', $arrayOfObject) : '')] = $classNames[$key];
144144
}
145145

146146
return $result;

PSR2R/Sniffs/ControlStructures/ConditionalExpressionOrderSniff.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected function detectRightEnd(File $phpCsFile, $index, $limit = 0) {
144144
* @param \PHP_CodeSniffer\Files\File $phpCsFile
145145
* @param int $index
146146
* @param int $leftIndexStart
147-
* @param int int $leftIndexEnd
147+
* @param int $leftIndexEnd
148148
* @param int $rightIndexStart
149149
* @param int $rightIndexEnd
150150
*
@@ -198,11 +198,9 @@ protected function getComparisonValue(array $token) {
198198
T_IS_SMALLER_OR_EQUAL => '>=',
199199
];
200200
$comparisonIndexValue = $mapping[$token['code']];
201-
202-
return $comparisonIndexValue;
203201
}
204202

205-
return $comparisonIndexValue;
203+
return (int)$comparisonIndexValue;
206204
}
207205

208206
}

PSR2R/Sniffs/ControlStructures/NoInlineAssignmentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function checkConditions($phpcsFile, $stackPtr) {
9292
* @param \PHP_CodeSniffer\Files\File $phpcsFile
9393
* @param int $startIndex
9494
* @param int $endIndex
95-
* @param int &$indexEqualSign
95+
* @param int $indexEqualSign
9696
*
9797
* @return bool
9898
*/

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
"scripts": {
3434
"docs": "php docs/generate.php",
3535
"docs-listing": "phpcs -e --standard=PSR2R/ruleset.xml",
36-
"cs-check": "phpcs --standard=PSR2R/ruleset.xml -vs --ignore=psr2r-sniffer/vendor/,tests/files/,*.inc,*.fixed ./",
37-
"cs-fix": "phpcbf --standard=PSR2R/ruleset.xml -v --ignore=psr2r-sniffer/vendor/,tests/files/,*.inc,*.fixed ./",
36+
"cs-check": "phpcs --standard=PSR2R/ruleset.xml -p -s --ignore=psr2r-sniffer/vendor/,tests/files/,*.inc,*.fixed ./",
37+
"cs-fix": "phpcbf --standard=PSR2R/ruleset.xml --ignore=psr2r-sniffer/vendor/,tests/files/,*.inc,*.fixed ./",
3838
"test": "php phpunit.phar",
3939
"test-setup": "[ ! -f phpunit.phar ] && wget https://phar.phpunit.de/phpunit-5.7.phar && mv phpunit-5.7.phar phpunit.phar || true",
4040
"test-setup-mac": "[ ! -f phpunit.phar ] && curl -OL https://phar.phpunit.de/phpunit-5.7.phar && mv phpunit-5.7.phar phpunit.phar || true",
41-
"test-coverage": "php phpunit.phar --log-junit tmp/coverage/unitreport.xml --coverage-html tmp/coverage --coverage-clover tmp/coverage/coverage.xml"
41+
"test-coverage": "php phpunit.phar --log-junit tmp/coverage/unitreport.xml --coverage-html tmp/coverage --coverage-clover tmp/coverage/coverage.xml",
42+
"phpstan": "phpstan analyse -c tests/phpstan.neon -l 4 PSR2R/",
43+
"phpstan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan-shim:^0.11 && mv composer.backup composer.json"
4244
}
4345
}

tests/phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
autoload_files:
3+
- %rootDir%/../../../tests/phpstan_bootstrap.php
4+
excludes_analyse:
5+
- %currentWorkingDirectory%/PSR2R/Tools/Sniffer.php
6+
ignoreErrors:
7+
- '#Empty array passed to foreach.#'

tests/phpstan_bootstrap.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
require dirname(__DIR__) . '/vendor/autoload.php';
4+
$manualAutoload = dirname(__DIR__) . '/vendor/squizlabs/php_codesniffer/autoload.php';
5+
if (!class_exists(\PHP_CodeSniffer\Config::class) && file_exists($manualAutoload)) {
6+
require $manualAutoload;
7+
}
8+
\PHP_CodeSniffer\Autoload::load('PHP_CodeSniffer\Util\Tokens');

0 commit comments

Comments
 (0)