Skip to content

Commit

Permalink
[2.3] Static Code Analysis for Components
Browse files Browse the repository at this point in the history
  • Loading branch information
kalessil authored and fabpot committed Dec 31, 2015
1 parent 36a5141 commit 6d303c7
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
Expand Up @@ -116,8 +116,8 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
}

// 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);

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/ClassLoader/ClassMapGenerator.php
Expand Up @@ -134,7 +134,7 @@ private static function findClasses($path)
}

if ($isClassConstant) {
continue;
break;
}

// Find the classname
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Expand Up @@ -37,7 +37,7 @@ protected function describeInputArgument(InputArgument $argument, array $options

$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;
}
Expand All @@ -56,7 +56,7 @@ protected function describeInputOption(InputOption $option, array $options = arr
$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()),
Expand Down Expand Up @@ -146,7 +146,7 @@ protected function describeApplication(Application $application, array $options
$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());
Expand All @@ -167,7 +167,7 @@ protected function describeApplication(Application $application, array $options
}

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());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/DialogHelper.php
Expand Up @@ -46,7 +46,7 @@ public function select(OutputInterface $output, $question, $choices, $default =

$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);
Expand Down
Expand Up @@ -48,8 +48,8 @@ public function __construct($savePath = null)
$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);
Expand Down
Expand Up @@ -42,8 +42,8 @@ public function __construct($savePath = null, $name = 'MOCKSESSID', MetadataBag
$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;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Templating/Loader/CacheLoader.php
Expand Up @@ -69,8 +69,8 @@ public function load(TemplateReferenceInterface $template)

$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);
Expand Down
14 changes: 4 additions & 10 deletions src/Symfony/Component/Translation/Dumper/IcuResFileDumper.php
Expand Up @@ -34,8 +34,8 @@ public function dump(MessageCatalogue $messages, $options = array())
$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
Expand Down Expand Up @@ -102,11 +102,7 @@ public function format(MessageCatalogue $messages, $domain = 'messages')
1, 4, 0, 0 // Unicode version
);

$output = $header
.$root
.$data;

return $output;
return $header.$root.$data;
}

private function writePadding($data)
Expand All @@ -120,9 +116,7 @@ private function writePadding($data)

private function getPosition($data)
{
$position = (strlen($data) + 28) / 4;

return $position;
return (strlen($data) + 28) / 4;
}

/**
Expand Down
Expand Up @@ -67,8 +67,8 @@ public function writeTranslations(MessageCatalogue $catalogue, $format, $options
// 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
Expand Down

0 comments on commit 6d303c7

Please sign in to comment.