Skip to content

Commit 009e6ff

Browse files
committed
Merge pull request #111 from kalessil/SCA-Dec-2015
Php Inspections (EA Extended): Static Code Analysis
2 parents 80f9280 + 99da217 commit 009e6ff

28 files changed

+54
-66
lines changed

data/bin/sandbox_installer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
$seen = array();
2727
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(sfConfig::get('sf_root_dir')), RecursiveIteratorIterator::CHILD_FIRST) as $path => $item)
2828
{
29-
if ($item->isDir() && !$item->isLink() && !isset($seen[$path]))
29+
if (!isset($seen[$path]) && $item->isDir() && !$item->isLink())
3030
{
3131
touch($item->getRealPath().'/.sf');
3232
}

lib/cache/sfFileCache.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ protected function write($path, $data, $timeout)
277277
$current_umask = umask();
278278
umask(0000);
279279

280-
if (!is_dir(dirname($path)))
280+
$cacheDir = dirname($path);
281+
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir))
281282
{
282-
// create directory structure if needed
283-
mkdir(dirname($path), 0777, true);
283+
throw new \sfCacheException(sprintf('Cache was not able to create a directory "%s".', $cacheDir));
284284
}
285285

286-
$tmpFile = tempnam(dirname($path), basename($path));
286+
$tmpFile = tempnam($cacheDir, basename($path));
287287

288288
if (!$fp = @fopen($tmpFile, 'wb'))
289289
{

lib/cache/sfSQLiteCache.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function clean($mode = sfCache::ALL)
142142
{
143143
$res = $this->dbh->exec("DELETE FROM cache".(sfCache::OLD == $mode ? sprintf(" WHERE timeout < '%s'", time()) : ''));
144144

145-
if ($res);
145+
if ($res)
146146
{
147147
return (boolean) $this->dbh->changes();
148148
}

lib/command/sfAnsiColorFormatter.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function formatSection($section, $text, $size = null, $style = 'INFO')
9898
$style = array_key_exists($style, $this->styles) ? $style : 'INFO';
9999
$width = 9 + strlen($this->format('', $style));
100100

101-
return sprintf(">> %-{$width}s %s", $this->format($section, $style), $this->excerpt($text, $size - 4 - (strlen($section) > 9 ? strlen($section) : 9)));
101+
return sprintf(">> %-${width}s %s", $this->format($section, $style), $this->excerpt($text, $size - 4 - (strlen($section) > 9 ? strlen($section) : 9)));
102102
}
103103

104104
/**

lib/config/sfConfigCache.class.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,13 @@ protected function loadConfigHandlers()
333333
protected function writeCacheFile($config, $cache, $data)
334334
{
335335
$current_umask = umask(0000);
336-
if (!is_dir(dirname($cache)))
336+
$cacheDir = dirname($cache);
337+
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir))
337338
{
338-
if (false === @mkdir(dirname($cache), 0777, true))
339-
{
340-
throw new sfCacheException(sprintf('Failed to make cache directory "%s" while generating cache for configuration file "%s".', dirname($cache), $config));
341-
}
339+
throw new \sfCacheException(sprintf('Failed to make cache directory "%s" while generating cache for configuration file "%s".', $cacheDir, $config));
342340
}
343341

344-
$tmpFile = tempnam(dirname($cache), basename($cache));
342+
$tmpFile = tempnam($cacheDir, basename($cache));
345343

346344
if (!$fp = @fopen($tmpFile, 'wb'))
347345
{

lib/database/sfPDODatabase.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function connect()
4242
$password = $this->getParameter('password');
4343
$persistent = $this->getParameter('persistent');
4444

45-
$options = ($persistent) ? array(PDO::ATTR_PERSISTENT => true) : array();
45+
$options = $persistent ? array(PDO::ATTR_PERSISTENT => true) : array();
4646

4747
$this->connection = new $pdo_class($dsn, $username, $password, $options);
4848

lib/debug/sfWebDebugPanelMemory.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class sfWebDebugPanelMemory extends sfWebDebugPanel
2020
{
2121
public function getTitle()
2222
{
23-
$totalMemory = sprintf('%.1f', (memory_get_peak_usage(true) / 1024));
23+
$totalMemory = sprintf('%.1f', memory_get_peak_usage(true) / 1024);
2424

2525
return '<img src="'.$this->webDebug->getOption('image_root_path').'/memory.png" alt="Memory" /> '.$totalMemory.' KB';
2626
}

lib/generator/sfGeneratorManager.class.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ public function save($path, $content)
8080
{
8181
$path = $this->getBasePath().DIRECTORY_SEPARATOR.$path;
8282

83-
if (!is_dir(dirname($path)))
83+
$cacheDir = dirname($path);
84+
if (!is_dir($cacheDir))
8485
{
8586
$current_umask = umask(0000);
86-
if (false === @mkdir(dirname($path), 0777, true))
87+
if (!@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir))
8788
{
88-
throw new sfCacheException(sprintf('Failed to make cache directory "%s".', dirname($path)));
89+
throw new \sfCacheException(sprintf('Failed to make cache directory "%s".', $cacheDir));
8990
}
9091
umask($current_umask);
9192
}

lib/helper/TagHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function tag($name, $options = array(), $open = false)
3434
return '';
3535
}
3636

37-
return '<'.$name._tag_options($options).(($open) ? '>' : ' />');
37+
return '<'.$name._tag_options($options).($open ? '>' : ' />');
3838
}
3939

4040
function content_tag($name, $content = '', $options = array())

lib/helper/TextHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function truncate_text($text, $length = 30, $truncate_string = '...', $truncate_
4545
$old_encoding = mb_internal_encoding();
4646
@mb_internal_encoding(mb_detect_encoding($text));
4747
}
48-
$strlen = ($mbstring) ? 'mb_strlen' : 'strlen';
49-
$substr = ($mbstring) ? 'mb_substr' : 'substr';
48+
$strlen = $mbstring ? 'mb_strlen' : 'strlen';
49+
$substr = $mbstring ? 'mb_substr' : 'substr';
5050

5151
if ($strlen($text) > $length)
5252
{

0 commit comments

Comments
 (0)