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 Tobion committed Jun 15, 2015
1 parent b1003d5 commit 4a4fea7
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -1161,7 +1161,7 @@ private function splitStringByWidth($string, $width)
$lines[] = str_pad($line, $width);
$line = $char;
}
if (strlen($line)) {
if ('' !== $line) {
$lines[] = count($lines) ? str_pad($line, $width) : $line;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Formatter/OutputFormatter.php
Expand Up @@ -33,7 +33,7 @@ class OutputFormatter implements OutputFormatterInterface
*/
public static function escape($text)
{
return preg_replace('/([^\\\\]?)</is', '$1\\<', $text);
return preg_replace('/([^\\\\]?)</', '$1\\<', $text);
}

/**
Expand Down Expand Up @@ -146,7 +146,7 @@ public function format($message)
$offset = 0;
$output = '';
$tagRegex = '[a-z][a-z0-9_=;-]*';
preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#isx", $message, $matches, PREG_OFFSET_CAPTURE);
preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE);
foreach ($matches[0] as $i => $match) {
$pos = $match[1];
$text = $match[0];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Shell.php
Expand Up @@ -207,7 +207,7 @@ private function readline()
} else {
$this->output->write($this->getPrompt());
$line = fgets(STDIN, 1024);
$line = (!$line && strlen($line) == 0) ? false : rtrim($line);
$line = (false === $line || '' === $line) ? false : rtrim($line);
}

return $line;
Expand Down
Expand Up @@ -271,7 +271,7 @@ private function addOptions($options)
*/
private function dotize($id)
{
return strtolower(preg_replace('/[^\w]/i', '_', $id));
return strtolower(preg_replace('/\W/i', '_', $id));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -675,7 +675,7 @@ public function testRenameOverwritesTheTargetIfItAlreadyExists()
*/
public function testRenameThrowsExceptionOnError()
{
$file = $this->workspace.DIRECTORY_SEPARATOR.uniqid();
$file = $this->workspace.DIRECTORY_SEPARATOR.uniqid('fs_test_', true);
$newPath = $this->workspace.DIRECTORY_SEPARATOR.'new_file';

$this->filesystem->rename($file, $newPath);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Finder/Tests/FinderTest.php
Expand Up @@ -272,7 +272,7 @@ public function testSort($adapter)
public function testFilter($adapter)
{
$finder = $this->buildFinder($adapter);
$this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return preg_match('/test/', $f) > 0; }));
$this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); }));
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
}

Expand Down
Expand Up @@ -39,7 +39,7 @@ public function getAcceptData()
{
return array(
array(array(function (\SplFileInfo $fileinfo) { return false; }), array()),
array(array(function (\SplFileInfo $fileinfo) { return preg_match('/^test/', $fileinfo) > 0; }), array('test.php', 'test.py')),
array(array(function (\SplFileInfo $fileinfo) { return 0 === strpos($fileinfo, 'test'); }), array('test.php', 'test.py')),
array(array('is_dir'), array()),
);
}
Expand Down
Expand Up @@ -51,7 +51,7 @@ public function __construct($param)
public function isFile()
{
if (null === $this->type) {
return preg_match('/file/', $this->getFilename());
return false !== strpos($this->getFilename(), 'file');
};

return self::TYPE_FILE === $this->type;
Expand All @@ -60,7 +60,7 @@ public function isFile()
public function isDir()
{
if (null === $this->type) {
return preg_match('/directory/', $this->getFilename());
return false !== strpos($this->getFilename(), 'directory');
}

return self::TYPE_DIRECTORY === $this->type;
Expand Down
Expand Up @@ -249,7 +249,7 @@ public function getMetadataBag()
*/
protected function generateId()
{
return sha1(uniqid(mt_rand()));
return sha1(uniqid('ss_mock_', true));
}

protected function loadSession()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/HttpCache/Esi.php
Expand Up @@ -183,7 +183,7 @@ public function process(Request $request, Response $response)
$chunks[$i] = sprintf('<?php echo $this->esi->handle($this, %s, %s, %s) ?>'."\n",
var_export($options['src'], true),
var_export(isset($options['alt']) ? $options['alt'] : '', true),
isset($options['onerror']) && 'continue' == $options['onerror'] ? 'true' : 'false'
isset($options['onerror']) && 'continue' === $options['onerror'] ? 'true' : 'false'
);
++$i;
$chunks[$i] = str_replace($this->phpEscapeMap[0], $this->phpEscapeMap[1], $chunks[$i]);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/ProcessUtils.php
Expand Up @@ -49,7 +49,7 @@ public static function escapeArgument($argument)

$escapedArgument = '';
$quote = false;
foreach (preg_split('/(")/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
if ('"' === $part) {
$escapedArgument .= '\\"';
} elseif (self::isSurroundedBy($part, '%')) {
Expand Down
Expand Up @@ -32,7 +32,7 @@
}
$out = (binary) substr($out, $written);
}
if (null === $read && strlen($out) < 1) {
if (null === $read && '' === $out) {
$write = array_diff($write, array(STDOUT));
}

Expand All @@ -43,7 +43,7 @@
}
$err = (binary) substr($err, $written);
}
if (null === $read && strlen($err) < 1) {
if (null === $read && '' === $err) {
$write = array_diff($write, array(STDERR));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Inline.php
Expand Up @@ -45,7 +45,7 @@ public static function parse($value, $exceptionOnInvalidType = false, $objectSup

$value = trim($value);

if (0 == strlen($value)) {
if ('' === $value) {
return '';
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -509,9 +509,9 @@ private function parseFoldedScalar($separator, $indicator = '', $indentation = 0

// deal with trailing newlines as indicated
if ('' === $indicator) {
$text = preg_replace('/\n+$/s', "\n", $text);
$text = preg_replace('/\n+$/', "\n", $text);
} elseif ('-' === $indicator) {
$text = preg_replace('/\n+$/s', '', $text);
$text = preg_replace('/\n+$/', '', $text);
}

return $text;
Expand Down Expand Up @@ -610,7 +610,7 @@ private function cleanup($value)
$value = $trimmedValue;

// remove end of the document marker (...)
$value = preg_replace('#\.\.\.\s*$#s', '', $value);
$value = preg_replace('#\.\.\.\s*$#', '', $value);
}

return $value;
Expand Down

0 comments on commit 4a4fea7

Please sign in to comment.