Browse Source

Fix a few things that scrutinizer complains about.

* Consistent return types.
* Handle 'error' cases better.
Mark Story 10 years ago
parent
commit
9233b3ed84

+ 1 - 1
src/Auth/DefaultPasswordHasher.php

@@ -44,7 +44,7 @@ class DefaultPasswordHasher extends AbstractPasswordHasher
      * Generates password hash.
      *
      * @param string $password Plain text password to hash.
-     * @return string Password hash
+     * @return bool|string Password hash or false on failure
      * @link http://book.cakephp.org/3.0/en/core-libraries/components/authentication.html#hashing-passwords
      */
     public function hash($password)

+ 1 - 1
src/Cache/CacheEngine.php

@@ -218,7 +218,7 @@ abstract class CacheEngine
      * Generates a safe key for use with cache engine storage engines.
      *
      * @param string $key the key passed over
-     * @return mixed string $key or false
+     * @return bool|string string key or false
      */
     public function key($key)
     {

+ 2 - 2
src/Cache/Engine/NullEngine.php

@@ -67,7 +67,7 @@ class NullEngine extends CacheEngine
      */
     public function readMany($keys)
     {
-        return false;
+        return [];
     }
 
     /**
@@ -96,7 +96,7 @@ class NullEngine extends CacheEngine
      */
     public function deleteMany($keys)
     {
-        return false;
+        return [];
     }
 
     /**

+ 4 - 3
src/Controller/Component/RequestHandlerComponent.php

@@ -183,7 +183,7 @@ class RequestHandlerComponent extends Component
         $extensions = Router::extensions();
         foreach ($accepts as $types) {
             $ext = array_intersect($extensions, $types);
-            if ($ext) {
+            if (!empty($ext)) {
                 $this->ext = current($ext);
                 break;
             }
@@ -647,8 +647,9 @@ class RequestHandlerComponent extends Component
      * Maps a content type alias back to its mime-type(s)
      *
      * @param string|array $alias String alias to convert back into a content type. Or an array of aliases to map.
-     * @return string|null Null on an undefined alias. String value of the mapped alias type. If an
-     *   alias maps to more than one content type, the first one will be returned.
+     * @return string|null|array Null on an undefined alias. String value of the mapped alias type. If an
+     *   alias maps to more than one content type, the first one will be returned. If an array is provided
+     *   for $alias, an array of mapped types will be returned.
      */
     public function mapAlias($alias)
     {

+ 2 - 2
src/Core/Configure/Engine/IniConfig.php

@@ -148,7 +148,7 @@ class IniConfig implements ConfigEngineInterface
      * @param string $key The identifier to write to. If the key has a . it will be treated
      *  as a plugin prefix.
      * @param array $data The data to convert to ini file.
-     * @return int Bytes saved.
+     * @return bool Success.
      */
     public function dump($key, array $data)
     {
@@ -172,7 +172,7 @@ class IniConfig implements ConfigEngineInterface
         $contents = trim(implode("\n", $result));
 
         $filename = $this->_getFilePath($key);
-        return file_put_contents($filename, $contents);
+        return file_put_contents($filename, $contents) > 0;
     }
 
     /**

+ 2 - 2
src/Core/Configure/Engine/JsonConfig.php

@@ -88,11 +88,11 @@ class JsonConfig implements ConfigEngineInterface
      * @param string $key The identifier to write to. If the key has a . it will
      *  be treated as a plugin prefix.
      * @param array $data Data to dump.
-     * @return int Bytes saved.
+     * @return bool Success
      */
     public function dump($key, array $data)
     {
         $filename = $this->_getFilePath($key);
-        return file_put_contents($filename, json_encode($data));
+        return file_put_contents($filename, json_encode($data)) > 0;
     }
 }

+ 4 - 3
src/Core/Configure/Engine/PhpConfig.php

@@ -25,7 +25,6 @@ use Cake\Core\Exception\Exception;
  * Files compatible with PhpConfig should return an array that
  * contains all of the configuration data contained in the file.
  *
- * @deprecated 3.0.0 Setting a `$config` variable is deprecated. Use `return` instead.
  */
 class PhpConfig implements ConfigEngineInterface
 {
@@ -58,6 +57,8 @@ class PhpConfig implements ConfigEngineInterface
      * Files with `.` in the name will be treated as values in plugins. Instead of
      * reading from the initialized path, plugin keys will be located using Plugin::path().
      *
+     * Setting a `$config` variable is deprecated. Use `return` instead.
+     *
      * @param string $key The identifier to read from. If the key has a . it will be treated
      *  as a plugin prefix.
      * @return array Parsed configuration values.
@@ -87,13 +88,13 @@ class PhpConfig implements ConfigEngineInterface
      * @param string $key The identifier to write to. If the key has a . it will be treated
      *  as a plugin prefix.
      * @param array $data Data to dump.
-     * @return int Bytes saved.
+     * @return bool Success
      */
     public function dump($key, array $data)
     {
         $contents = '<?php' . "\n" . 'return ' . var_export($data, true) . ';';
 
         $filename = $this->_getFilePath($key);
-        return file_put_contents($filename, $contents);
+        return file_put_contents($filename, $contents) > 0;
     }
 }

+ 1 - 1
src/Database/Connection.php

@@ -237,7 +237,7 @@ class Connection
      */
     public function execute($query, array $params = [], array $types = [])
     {
-        if ($params) {
+        if (!empty($params)) {
             $statement = $this->prepare($query);
             $statement->bind($params, $types);
             $statement->execute();

+ 1 - 1
src/Database/IdentifierQuoter.php

@@ -109,7 +109,7 @@ class IdentifierQuoter
             }
 
             $result = $this->_basicQuoter($contents);
-            if ($result) {
+            if (!empty($result)) {
                 $query->{$part}($result, true);
             }
         }

+ 2 - 2
src/Network/Http/Auth/Digest.php

@@ -75,7 +75,7 @@ class Digest
      *
      * @param \Cake\Network\Http\Request $request The request object.
      * @param array $credentials Authentication credentials.
-     * @return Array modified credentials.
+     * @return array modified credentials.
      */
     protected function _getServerInfo(Request $request, $credentials)
     {
@@ -86,7 +86,7 @@ class Digest
         );
 
         if (!$response->header('WWW-Authenticate')) {
-            return false;
+            return [];
         }
         preg_match_all(
             '@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@',