Skip to content

Commit 3296496

Browse files
committed
minor symfony#13995 [2.3] Static Code Analysis for Components (kalessil)
This PR was squashed before being merged into the 2.3 branch (closes symfony#13995). Discussion ---------- [2.3] Static Code Analysis for Components | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Static Code Analysis with Php Inspections (EA Extended), no functional changes: - [Filesystem] : nested ifs, not optimal ifs - in_array() miss-uses - class re-implements an interface of super(s) - array_keys/array_values as foreach array - fixed cases where changes has sense Commits ------- 4abfabf [2.3] Static Code Analysis for Components
2 parents c73c34a + 4abfabf commit 3296496

File tree

15 files changed

+28
-31
lines changed

15 files changed

+28
-31
lines changed

src/Symfony/Component/CssSelector/Exception/ExpressionErrorException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
*
2020
* @author Jean-François Simon <[email protected]>
2121
*/
22-
class ExpressionErrorException extends ParseException implements ExceptionInterface
22+
class ExpressionErrorException extends ParseException
2323
{
2424
}

src/Symfony/Component/CssSelector/Exception/InternalErrorException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
*
2020
* @author Jean-François Simon <[email protected]>
2121
*/
22-
class InternalErrorException extends ParseException implements ExceptionInterface
22+
class InternalErrorException extends ParseException
2323
{
2424
}

src/Symfony/Component/CssSelector/Exception/SyntaxErrorException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Jean-François Simon <[email protected]>
2323
*/
24-
class SyntaxErrorException extends ParseException implements ExceptionInterface
24+
class SyntaxErrorException extends ParseException
2525
{
2626
/**
2727
* @param string $expectedValue

src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private function findNodes()
173173
foreach ($container->getServiceIds() as $id) {
174174
$service = $container->get($id);
175175

176-
if (in_array($id, array_keys($container->getAliases()))) {
176+
if (array_key_exists($id, $container->getAliases())) {
177177
continue;
178178
}
179179

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ public function copy($originFile, $targetFile, $override = false)
4141

4242
$this->mkdir(dirname($targetFile));
4343

44-
if (!$override && is_file($targetFile) && null === parse_url($originFile, PHP_URL_HOST)) {
44+
$doCopy = true;
45+
if (!$override && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) {
4546
$doCopy = filemtime($originFile) > filemtime($targetFile);
46-
} else {
47-
$doCopy = true;
4847
}
4948

5049
if ($doCopy) {
@@ -274,7 +273,7 @@ public function rename($origin, $target, $overwrite = false)
274273
*/
275274
public function symlink($originDir, $targetDir, $copyOnWindows = false)
276275
{
277-
if (!function_exists('symlink') && $copyOnWindows) {
276+
if ($copyOnWindows && !function_exists('symlink')) {
278277
$this->mirror($originDir, $targetDir);
279278

280279
return;
@@ -291,16 +290,14 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
291290
}
292291
}
293292

294-
if (!$ok) {
295-
if (true !== @symlink($originDir, $targetDir)) {
296-
$report = error_get_last();
297-
if (is_array($report)) {
298-
if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
299-
throw new IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
300-
}
293+
if (!$ok && true !== @symlink($originDir, $targetDir)) {
294+
$report = error_get_last();
295+
if (is_array($report)) {
296+
if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
297+
throw new IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
301298
}
302-
throw new IOException(sprintf('Failed to create symbolic link from %s to %s', $originDir, $targetDir));
303299
}
300+
throw new IOException(sprintf('Failed to create symbolic link from %s to %s', $originDir, $targetDir));
304301
}
305302
}
306303

@@ -339,9 +336,9 @@ public function makePathRelative($endPath, $startPath)
339336
$endPathRemainder = implode('/', array_slice($endPathArr, $index));
340337

341338
// Construct $endPath from traversing to the common path, then to the remaining $endPath
342-
$relativePath = $traverser.(strlen($endPathRemainder) > 0 ? $endPathRemainder.'/' : '');
339+
$relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.'/' : '');
343340

344-
return (strlen($relativePath) === 0) ? './' : $relativePath;
341+
return '' === $relativePath ? './' : $relativePath;
345342
}
346343

347344
/**

src/Symfony/Component/Form/NativeRequestHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ private static function fixPhpFilesArray($data)
184184
unset($files[$k]);
185185
}
186186

187-
foreach (array_keys($data['name']) as $key) {
187+
foreach ($data['name'] as $key => $name) {
188188
$files[$key] = self::fixPhpFilesArray(array(
189189
'error' => $data['error'][$key],
190-
'name' => $data['name'][$key],
190+
'name' => $name,
191191
'type' => $data['type'][$key],
192192
'tmp_name' => $data['tmp_name'][$key],
193193
'size' => $data['size'][$key],

src/Symfony/Component/HttpFoundation/FileBag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ protected function fixPhpFilesArray($data)
140140
unset($files[$k]);
141141
}
142142

143-
foreach (array_keys($data['name']) as $key) {
143+
foreach ($data['name'] as $key => $name) {
144144
$files[$key] = $this->fixPhpFilesArray(array(
145145
'error' => $data['error'][$key],
146-
'name' => $data['name'][$key],
146+
'name' => $name,
147147
'type' => $data['type'][$key],
148148
'tmp_name' => $data['tmp_name'][$key],
149149
'size' => $data['size'][$key],

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ public function getLanguages()
15491549
foreach (array_keys($languages) as $lang) {
15501550
if (strstr($lang, '-')) {
15511551
$codes = explode('-', $lang);
1552-
if ($codes[0] == 'i') {
1552+
if ('i' === $codes[0]) {
15531553
// Language not listed in ISO 639 that are not variants
15541554
// of any listed language, which can be registered with the
15551555
// i-prefix, such as i-cherokee
@@ -1558,7 +1558,7 @@ public function getLanguages()
15581558
}
15591559
} else {
15601560
for ($i = 0, $max = count($codes); $i < $max; $i++) {
1561-
if ($i == 0) {
1561+
if ($i === 0) {
15621562
$lang = strtolower($codes[0]);
15631563
} else {
15641564
$lang .= '_'.strtoupper($codes[$i]);

src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testGuessWithNonReadablePath()
7575
$this->markTestSkipped('Can not verify chmod operations on Windows');
7676
}
7777

78-
if (in_array(get_current_user(), array('root'))) {
78+
if ('root' === get_current_user()) {
7979
$this->markTestSkipped('This test will fail if run under superuser');
8080
}
8181

src/Symfony/Component/Translation/Loader/CsvFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @api
2424
*/
25-
class CsvFileLoader extends ArrayLoader implements LoaderInterface
25+
class CsvFileLoader extends ArrayLoader
2626
{
2727
private $delimiter = ';';
2828
private $enclosure = '"';

0 commit comments

Comments
 (0)