Skip to content

Commit 1b15ac3

Browse files
committed
minor symfony#17085 [2.3] Static Code Analysis for Components (kalessil)
This PR was squashed before being merged into the 2.3 branch (closes symfony#17085). 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): - remaining mkdir race conditions - continue miss-usage in switch Commits ------- 6d303c7 [2.3] Static Code Analysis for Components
2 parents e9dcc04 + 6d303c7 commit 1b15ac3

File tree

9 files changed

+20
-26
lines changed

9 files changed

+20
-26
lines changed

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
116116
}
117117

118118
// cache the core classes
119-
if (!is_dir(dirname($cache))) {
120-
mkdir(dirname($cache), 0777, true);
119+
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
120+
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
121121
}
122122
self::writeCacheFile($cache, '<?php '.$content);
123123

src/Symfony/Component/ClassLoader/ClassMapGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private static function findClasses($path)
134134
}
135135

136136
if ($isClassConstant) {
137-
continue;
137+
break;
138138
}
139139

140140
// Find the classname

src/Symfony/Component/Console/Descriptor/TextDescriptor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function describeInputArgument(InputArgument $argument, array $options
3737

3838
$nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName());
3939
$output = str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription());
40-
$output = sprintf(" <info>%-${nameWidth}s</info> %s%s", $argument->getName(), $output, $default);
40+
$output = sprintf(" <info>%-{$nameWidth}s</info> %s%s", $argument->getName(), $output, $default);
4141

4242
return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
4343
}
@@ -56,7 +56,7 @@ protected function describeInputOption(InputOption $option, array $options = arr
5656
$nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName());
5757
$nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2;
5858

59-
$output = sprintf(" <info>%s</info> %-${nameWithShortcutWidth}s%s%s%s",
59+
$output = sprintf(" <info>%s</info> %-{$nameWithShortcutWidth}s%s%s%s",
6060
'--'.$option->getName(),
6161
$option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '',
6262
str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $option->getDescription()),
@@ -146,7 +146,7 @@ protected function describeApplication(Application $application, array $options
146146
$width = $this->getColumnWidth($description->getCommands());
147147

148148
foreach ($description->getCommands() as $command) {
149-
$messages[] = sprintf("%-${width}s %s", $command->getName(), $command->getDescription());
149+
$messages[] = sprintf("%-{$width}s %s", $command->getName(), $command->getDescription());
150150
}
151151
} else {
152152
$width = $this->getColumnWidth($description->getCommands());
@@ -167,7 +167,7 @@ protected function describeApplication(Application $application, array $options
167167
}
168168

169169
foreach ($namespace['commands'] as $name) {
170-
$messages[] = sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription());
170+
$messages[] = sprintf(" <info>%-{$width}s</info> %s", $name, $description->getCommand($name)->getDescription());
171171
}
172172
}
173173
}

src/Symfony/Component/Console/Helper/DialogHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function select(OutputInterface $output, $question, $choices, $default =
4646

4747
$messages = (array) $question;
4848
foreach ($choices as $key => $value) {
49-
$messages[] = sprintf(" [<info>%-${width}s</info>] %s", $key, $value);
49+
$messages[] = sprintf(" [<info>%-{$width}s</info>] %s", $key, $value);
5050
}
5151

5252
$output->writeln($messages);

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public function __construct($savePath = null)
4848
$baseDir = ltrim(strrchr($savePath, ';'), ';');
4949
}
5050

51-
if ($baseDir && !is_dir($baseDir)) {
52-
mkdir($baseDir, 0777, true);
51+
if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) {
52+
throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $baseDir));
5353
}
5454

5555
ini_set('session.save_path', $savePath);

src/Symfony/Component/HttpFoundation/Session/Storage/MockFileSessionStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function __construct($savePath = null, $name = 'MOCKSESSID', MetadataBag
4242
$savePath = sys_get_temp_dir();
4343
}
4444

45-
if (!is_dir($savePath)) {
46-
mkdir($savePath, 0777, true);
45+
if (!is_dir($savePath) && !@mkdir($savePath, 0777, true) && !is_dir($savePath)) {
46+
throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $savePath));
4747
}
4848

4949
$this->savePath = $savePath;

src/Symfony/Component/Templating/Loader/CacheLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function load(TemplateReferenceInterface $template)
6969

7070
$content = $storage->getContent();
7171

72-
if (!is_dir($dir)) {
73-
mkdir($dir, 0777, true);
72+
if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
73+
throw new \RuntimeException(sprintf('Cache Loader was not able to create directory "%s"', $dir));
7474
}
7575

7676
file_put_contents($path, $content);

src/Symfony/Component/Translation/Dumper/IcuResFileDumper.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function dump(MessageCatalogue $messages, $options = array())
3434
$file = $messages->getLocale().'.'.$this->getExtension();
3535
$path = $options['path'].'/'.$domain.'/';
3636

37-
if (!file_exists($path)) {
38-
mkdir($path);
37+
if (!is_dir($path) && !@mkdir($path) && !is_dir($path)) {
38+
throw new \RuntimeException(sprintf('File Dumper was not able to create directory "%s"', $path));
3939
}
4040

4141
// backup
@@ -102,11 +102,7 @@ public function format(MessageCatalogue $messages, $domain = 'messages')
102102
1, 4, 0, 0 // Unicode version
103103
);
104104

105-
$output = $header
106-
.$root
107-
.$data;
108-
109-
return $output;
105+
return $header.$root.$data;
110106
}
111107

112108
private function writePadding($data)
@@ -120,9 +116,7 @@ private function writePadding($data)
120116

121117
private function getPosition($data)
122118
{
123-
$position = (strlen($data) + 28) / 4;
124-
125-
return $position;
119+
return (strlen($data) + 28) / 4;
126120
}
127121

128122
/**

src/Symfony/Component/Translation/Writer/TranslationWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public function writeTranslations(MessageCatalogue $catalogue, $format, $options
6767
// get the right dumper
6868
$dumper = $this->dumpers[$format];
6969

70-
if (isset($options['path']) && !is_dir($options['path'])) {
71-
mkdir($options['path'], 0777, true);
70+
if (isset($options['path']) && !is_dir($options['path']) && !@mkdir($options['path'], 0777, true) && !is_dir($options['path'])) {
71+
throw new \RuntimeException(sprintf('Translation Writer was not able to create directory "%s"', $options['path']));
7272
}
7373

7474
// save

0 commit comments

Comments
 (0)