minor #17085 [2.3] Static Code Analysis for Components (kalessil)
This PR was squashed before being merged into the 2.3 branch (closes #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
This commit is contained in:
commit
1b15ac3bdc
@ -116,8 +116,8 @@ class ClassCollectionLoader
|
||||
}
|
||||
|
||||
// cache the core classes
|
||||
if (!is_dir(dirname($cache))) {
|
||||
mkdir(dirname($cache), 0777, true);
|
||||
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
|
||||
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
|
||||
}
|
||||
self::writeCacheFile($cache, '<?php '.$content);
|
||||
|
||||
|
@ -134,7 +134,7 @@ class ClassMapGenerator
|
||||
}
|
||||
|
||||
if ($isClassConstant) {
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
// Find the classname
|
||||
|
@ -37,7 +37,7 @@ class TextDescriptor extends Descriptor
|
||||
|
||||
$nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName());
|
||||
$output = str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription());
|
||||
$output = sprintf(" <info>%-${nameWidth}s</info> %s%s", $argument->getName(), $output, $default);
|
||||
$output = sprintf(" <info>%-{$nameWidth}s</info> %s%s", $argument->getName(), $output, $default);
|
||||
|
||||
return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
|
||||
}
|
||||
@ -56,7 +56,7 @@ class TextDescriptor extends Descriptor
|
||||
$nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName());
|
||||
$nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2;
|
||||
|
||||
$output = sprintf(" <info>%s</info> %-${nameWithShortcutWidth}s%s%s%s",
|
||||
$output = sprintf(" <info>%s</info> %-{$nameWithShortcutWidth}s%s%s%s",
|
||||
'--'.$option->getName(),
|
||||
$option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '',
|
||||
str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $option->getDescription()),
|
||||
@ -146,7 +146,7 @@ class TextDescriptor extends Descriptor
|
||||
$width = $this->getColumnWidth($description->getCommands());
|
||||
|
||||
foreach ($description->getCommands() as $command) {
|
||||
$messages[] = sprintf("%-${width}s %s", $command->getName(), $command->getDescription());
|
||||
$messages[] = sprintf("%-{$width}s %s", $command->getName(), $command->getDescription());
|
||||
}
|
||||
} else {
|
||||
$width = $this->getColumnWidth($description->getCommands());
|
||||
@ -167,7 +167,7 @@ class TextDescriptor extends Descriptor
|
||||
}
|
||||
|
||||
foreach ($namespace['commands'] as $name) {
|
||||
$messages[] = sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription());
|
||||
$messages[] = sprintf(" <info>%-{$width}s</info> %s", $name, $description->getCommand($name)->getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class DialogHelper extends Helper
|
||||
|
||||
$messages = (array) $question;
|
||||
foreach ($choices as $key => $value) {
|
||||
$messages[] = sprintf(" [<info>%-${width}s</info>] %s", $key, $value);
|
||||
$messages[] = sprintf(" [<info>%-{$width}s</info>] %s", $key, $value);
|
||||
}
|
||||
|
||||
$output->writeln($messages);
|
||||
|
@ -48,8 +48,8 @@ class NativeFileSessionHandler extends NativeSessionHandler
|
||||
$baseDir = ltrim(strrchr($savePath, ';'), ';');
|
||||
}
|
||||
|
||||
if ($baseDir && !is_dir($baseDir)) {
|
||||
mkdir($baseDir, 0777, true);
|
||||
if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) {
|
||||
throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $baseDir));
|
||||
}
|
||||
|
||||
ini_set('session.save_path', $savePath);
|
||||
|
@ -42,8 +42,8 @@ class MockFileSessionStorage extends MockArraySessionStorage
|
||||
$savePath = sys_get_temp_dir();
|
||||
}
|
||||
|
||||
if (!is_dir($savePath)) {
|
||||
mkdir($savePath, 0777, true);
|
||||
if (!is_dir($savePath) && !@mkdir($savePath, 0777, true) && !is_dir($savePath)) {
|
||||
throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s"', $savePath));
|
||||
}
|
||||
|
||||
$this->savePath = $savePath;
|
||||
|
@ -69,8 +69,8 @@ class CacheLoader extends Loader
|
||||
|
||||
$content = $storage->getContent();
|
||||
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
|
||||
throw new \RuntimeException(sprintf('Cache Loader was not able to create directory "%s"', $dir));
|
||||
}
|
||||
|
||||
file_put_contents($path, $content);
|
||||
|
@ -34,8 +34,8 @@ class IcuResFileDumper implements DumperInterface
|
||||
$file = $messages->getLocale().'.'.$this->getExtension();
|
||||
$path = $options['path'].'/'.$domain.'/';
|
||||
|
||||
if (!file_exists($path)) {
|
||||
mkdir($path);
|
||||
if (!is_dir($path) && !@mkdir($path) && !is_dir($path)) {
|
||||
throw new \RuntimeException(sprintf('File Dumper was not able to create directory "%s"', $path));
|
||||
}
|
||||
|
||||
// backup
|
||||
@ -102,11 +102,7 @@ class IcuResFileDumper implements DumperInterface
|
||||
1, 4, 0, 0 // Unicode version
|
||||
);
|
||||
|
||||
$output = $header
|
||||
.$root
|
||||
.$data;
|
||||
|
||||
return $output;
|
||||
return $header.$root.$data;
|
||||
}
|
||||
|
||||
private function writePadding($data)
|
||||
@ -120,9 +116,7 @@ class IcuResFileDumper implements DumperInterface
|
||||
|
||||
private function getPosition($data)
|
||||
{
|
||||
$position = (strlen($data) + 28) / 4;
|
||||
|
||||
return $position;
|
||||
return (strlen($data) + 28) / 4;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,8 +67,8 @@ class TranslationWriter
|
||||
// get the right dumper
|
||||
$dumper = $this->dumpers[$format];
|
||||
|
||||
if (isset($options['path']) && !is_dir($options['path'])) {
|
||||
mkdir($options['path'], 0777, true);
|
||||
if (isset($options['path']) && !is_dir($options['path']) && !@mkdir($options['path'], 0777, true) && !is_dir($options['path'])) {
|
||||
throw new \RuntimeException(sprintf('Translation Writer was not able to create directory "%s"', $options['path']));
|
||||
}
|
||||
|
||||
// save
|
||||
|
Reference in New Issue
Block a user