Browse Source

Fix scrutinizer warnings in several packages.

Scrutinizer found a few undefined variable issues and ambiguous boolean
casting issues which I've fixed here.
Mark Story 10 years ago
parent
commit
673a5175f1

+ 3 - 2
config/config.php

@@ -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))
+];

+ 1 - 1
src/Auth/PasswordHasherFactory.php

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

+ 1 - 1
src/Cache/CacheEngine.php

@@ -265,7 +265,7 @@ abstract class CacheEngine
     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');
         }
 

+ 1 - 1
src/Collection/Iterator/BufferedIterator.php

@@ -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;
 

+ 1 - 1
src/Collection/Iterator/StoppableIterator.php

@@ -57,7 +57,7 @@ class StoppableIterator extends Collection
     {
         $this->_condition = $condition;
         parent::__construct($items);
-        $this->_innnerIterator = $this->getInnerIterator();
+        $this->_innerIterator = $this->getInnerIterator();
     }
 
     /**

+ 2 - 2
src/Console/ConsoleIo.php

@@ -162,7 +162,7 @@ class ConsoleIo
      * @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);
@@ -212,7 +212,7 @@ class ConsoleIo
      * @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);
     }

+ 1 - 1
src/Controller/Component/CookieComponent.php

@@ -363,7 +363,7 @@ class CookieComponent extends Component
         if (is_array($value)) {
             $value = $this->_implode($value);
         }
-        if (!$encrypt) {
+        if ($encrypt === false) {
             return $value;
         }
         $this->_checkCipher($encrypt);

+ 2 - 2
src/Controller/Component/RequestHandlerComponent.php

@@ -448,7 +448,7 @@ class RequestHandlerComponent extends Component
             list($contentType) = explode(';', $request->header('CONTENT_TYPE'));
         }
         $response = $this->response;
-        if (!$type) {
+        if ($type === null) {
             return $response->mapType($contentType);
         }
         if (is_string($type)) {
@@ -579,7 +579,7 @@ class RequestHandlerComponent extends Component
 
         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;
             }
         }

+ 2 - 2
src/Controller/Component/SecurityComponent.php

@@ -300,10 +300,10 @@ class SecurityComponent extends Component
         $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)) {

+ 2 - 2
src/Core/Configure.php

@@ -208,7 +208,7 @@ class Configure
      */
     public static function configured($name = null)
     {
-        if ($name) {
+        if ($name !== null) {
             return isset(static::$_engines[$name]);
         }
         return array_keys(static::$_engines);
@@ -344,7 +344,7 @@ class Configure
     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'];

+ 1 - 1
src/Core/Configure/FileConfigTrait.php

@@ -27,7 +27,7 @@ trait FileConfigTrait
      *
      * @var string
      */
-    protected $_path = null;
+    protected $_path = '';
 
     /**
      * Get file path

+ 1 - 1
src/Core/Plugin.php

@@ -350,7 +350,7 @@ class Plugin
      */
     public static function loaded($plugin = null)
     {
-        if ($plugin) {
+        if ($plugin !== null) {
             return isset(static::$_plugins[$plugin]);
         }
         $return = array_keys(static::$_plugins);

+ 1 - 1
src/Core/StaticConfigTrait.php

@@ -190,13 +190,13 @@ trait StaticConfigTrait
             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;
         }

+ 1 - 1
src/Database/Query.php

@@ -1694,7 +1694,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      * 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