Skip to content
Permalink
Browse files

Fix a few things that scrutinizer complains about.

* Consistent return types.
* Handle 'error' cases better.
  • Loading branch information...
markstory committed Jul 10, 2015
1 parent 14a2bad commit 9233b3ed8400a66f4ce4a0235562f57a77ea13af
@@ -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)
@@ -218,7 +218,7 @@ public function groups()
* 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)
{
@@ -67,7 +67,7 @@ public function read($key)
*/
public function readMany($keys)
{
return false;
return [];
}
/**
@@ -96,7 +96,7 @@ public function delete($key)
*/
public function deleteMany($keys)
{
return false;
return [];
}
/**
@@ -183,7 +183,7 @@ protected function _setExtension($request, $response)
$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 @@ public function responseType()
* 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)
{
@@ -148,7 +148,7 @@ protected function _parseNestedValues($values)
* @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 @@ public function dump($key, array $data)
$contents = trim(implode("\n", $result));
$filename = $this->_getFilePath($key);
return file_put_contents($filename, $contents);
return file_put_contents($filename, $contents) > 0;
}
/**
@@ -88,11 +88,11 @@ public function read($key)
* @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;
}
}
@@ -25,7 +25,6 @@
* 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 @@ public function __construct($path = null)
* 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 @@ public function read($key)
* @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;
}
}
@@ -237,7 +237,7 @@ public function prepare($sql)
*/
public function execute($query, array $params = [], array $types = [])
{
if ($params) {
if (!empty($params)) {
$statement = $this->prepare($query);
$statement->bind($params, $types);
$statement->execute();
@@ -109,7 +109,7 @@ protected function _quoteParts($query)
}
$result = $this->_basicQuoter($contents);
if ($result) {
if (!empty($result)) {
$query->{$part}($result, true);
}
}
@@ -75,7 +75,7 @@ public function authentication(Request $request, array $credentials)
*
* @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 @@ protected function _getServerInfo(Request $request, $credentials)
);
if (!$response->header('WWW-Authenticate')) {
return false;
return [];
}
preg_match_all(
'@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@',

0 comments on commit 9233b3e

Please sign in to comment.
You can’t perform that action at this time.