Skip to content

Commit

Permalink
Fix scrutinizer warnings in several packages.
Browse files Browse the repository at this point in the history
Scrutinizer found a few undefined variable issues and ambiguous boolean
casting issues which I've fixed here.
  • Loading branch information
markstory committed Oct 2, 2015
1 parent d7a4896 commit 673a517
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 19 deletions.
5 changes: 3 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
$versionFile = file(CORE_PATH . 'VERSION.txt');
$config['Cake.version'] = trim(array_pop($versionFile));
return $config;
return [
'Cake.version' => trim(array_pop($versionFile))
];
2 changes: 1 addition & 1 deletion src/Auth/PasswordHasherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function build($passwordHasher)
}

$className = App::className($class, 'Auth', 'PasswordHasher');
if (!$className) {
if ($className === false) {
throw new RuntimeException(sprintf('Password hasher class "%s" was not found.', $class));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cache/CacheEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function key($key)
protected function _key($key)
{
$key = $this->key($key);
if (!$key) {
if ($key === false) {
throw new InvalidArgumentException('An empty value is not valid as a cache key');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Iterator/BufferedIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BufferedIterator extends Collection implements Countable, Serializable
/**
* The in-memory cache containing results from previous iterators
*
* @var callable
* @var \SplDoublyLinkedList
*/
protected $_buffer;

Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Iterator/StoppableIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct($items, callable $condition)
{
$this->_condition = $condition;
parent::__construct($items);
$this->_innnerIterator = $this->getInnerIterator();
$this->_innerIterator = $this->getInnerIterator();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Console/ConsoleIo.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function quiet($message, $newlines = 1)
* @param int $level The message's output level, see above.
* @return int|bool Returns the number of bytes returned from writing to stdout.
*/
public function out($message = null, $newlines = 1, $level = ConsoleIo::NORMAL)
public function out($message = '', $newlines = 1, $level = ConsoleIo::NORMAL)
{
if ($level <= $this->_level) {
$this->_lastWritten = $this->_out->write($message, $newlines);
Expand Down Expand Up @@ -212,7 +212,7 @@ public function overwrite($message, $newlines = 1, $size = null)
* @param int $newlines Number of newlines to append
* @return void
*/
public function err($message = null, $newlines = 1)
public function err($message = '', $newlines = 1)
{
$this->_err->write($message, $newlines);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Component/CookieComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ protected function _encrypt($value, $encrypt)
if (is_array($value)) {
$value = $this->_implode($value);
}
if (!$encrypt) {
if ($encrypt === false) {
return $value;
}
$this->_checkCipher($encrypt);
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Component/RequestHandlerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public function requestedWith($type = null)
list($contentType) = explode(';', $request->header('CONTENT_TYPE'));
}
$response = $this->response;
if (!$type) {
if ($type === null) {
return $response->mapType($contentType);
}
if (is_string($type)) {
Expand Down Expand Up @@ -579,7 +579,7 @@ public function renderAs(Controller $controller, $type, array $options = [])

if (!in_array($helper, $controller->helpers) && empty($controller->helpers[$helper])) {
$helperClass = App::className($helper, 'View/Helper', 'Helper');
if ($helperClass) {
if ($helperClass !== false) {
$controller->helpers[] = $helper;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Component/SecurityComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ protected function _validatePost(Controller $controller)
$locked = explode('|', $locked);
$unlocked = explode('|', $unlocked);

$lockedFields = [];
$fields = Hash::flatten($check);
$fieldList = array_keys($fields);
$multi = [];
$multi = $lockedFields = [];
$isUnlocked = false;

foreach ($fieldList as $i => $key) {
if (preg_match('/(\.\d+){1,10}$/', $key)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static function config($name, ConfigEngineInterface $engine)
*/
public static function configured($name = null)
{
if ($name) {
if ($name !== null) {
return isset(static::$_engines[$name]);
}
return array_keys(static::$_engines);
Expand Down Expand Up @@ -344,7 +344,7 @@ protected static function _getEngine($config)
public static function version()
{
if (!isset(static::$_values['Cake']['version'])) {
require CORE_PATH . 'config/config.php';
$config = require CORE_PATH . 'config/config.php';
static::write($config);
}
return static::$_values['Cake']['version'];
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Configure/FileConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait FileConfigTrait
*
* @var string
*/
protected $_path = null;
protected $_path = '';

/**
* Get file path
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public static function routes($plugin = null)
*/
public static function loaded($plugin = null)
{
if ($plugin) {
if ($plugin !== null) {
return isset(static::$_plugins[$plugin]);
}
$return = array_keys(static::$_plugins);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/StaticConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ public static function parseDsn($dsn)
throw new InvalidArgumentException('Only strings can be passed to parseDsn');
}

$scheme = '';
if (preg_match("/^([\w\\\]+)/", $dsn, $matches)) {
$scheme = $matches[1];
$dsn = preg_replace("/^([\w\\\]+)/", 'file', $dsn);
}

$parsed = parse_url($dsn);

if ($parsed === false) {
return $dsn;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ protected function _decorateStatement($statement)
* Helper function used to build conditions by composing QueryExpression objects.
*
* @param string $part Name of the query part to append the new part to
* @param string|array|ExpressionInterface|callback $append Expression or builder function to append.
* @param string|null|array|ExpressionInterface|callback $append Expression or builder function to append.
* @param string $conjunction type of conjunction to be used to operate part
* @param array $types associative array of type names used to bind values to query
* @return void
Expand Down

0 comments on commit 673a517

Please sign in to comment.