Browse Source

SCA with Php Inspections (EA Ultimate): random fixes (CS, control flow)

Vladimir Reznichenko 8 years ago
parent
commit
fd0e9b8433

+ 2 - 4
src/Console/ConsoleIo.php

@@ -455,9 +455,8 @@ class ConsoleIo
             $defaultText = "[$default] ";
         }
         $this->_out->write('<question>' . $prompt . "</question>$optionsText\n$defaultText> ", 0);
-        $result = $this->_in->read();
 
-        $result = trim($result);
+        $result = trim($this->_in->read());
         if ($default !== null && ($result === '' || $result === null)) {
             return $default;
         }
@@ -551,8 +550,7 @@ class ConsoleIo
 
         if (file_exists($path) && $forceOverwrite === false) {
             $this->warning("File `{$path}` exists");
-            $key = $this->askChoice('Do you want to overwrite?', ['y', 'n', 'a', 'q'], 'n');
-            $key = strtolower($key);
+            $key = strtolower($this->askChoice('Do you want to overwrite?', ['y', 'n', 'a', 'q'], 'n'));
 
             if ($key === 'q') {
                 $this->error('Quitting.', 2);

+ 1 - 2
src/Core/Plugin.php

@@ -241,8 +241,7 @@ class Plugin
             }
         }
         if (Configure::check('plugins')) {
-            $plugins = array_merge($plugins, array_keys(Configure::read('plugins')));
-            $plugins = array_unique($plugins);
+            $plugins = array_unique(array_merge($plugins, array_keys(Configure::read('plugins'))));
         }
 
         $collection = static::getCollection();

+ 1 - 1
src/Core/PluginCollection.php

@@ -131,7 +131,7 @@ class PluginCollection implements Iterator, Countable
      */
     public function next()
     {
-        $this->position += 1;
+        ++$this->position;
     }
 
     /**

+ 1 - 1
src/Core/functions.php

@@ -51,7 +51,7 @@ if (!function_exists('h')) {
             } else {
                 $text = '(object)' . get_class($text);
             }
-        } elseif (is_bool($text) || is_null($text) || is_int($text)) {
+        } elseif (is_bool($text) || is_int($text) || $text === null) {
             return $text;
         }
 

+ 1 - 1
src/Database/Dialect/SqliteDialectTrait.php

@@ -120,7 +120,7 @@ trait SqliteDialectTrait
                     ->setConjunction(' ,')
                     ->iterateParts(function ($p, $key) {
                         if ($key === 0) {
-                            $value = rtrim(strtolower($p), 's');
+                            $value = strtolower(rtrim($p, 's'));
                             if (isset($this->_dateParts[$value])) {
                                 $p = ['value' => '%' . $this->_dateParts[$value], 'type' => null];
                             }

+ 1 - 1
src/Database/Driver/PDODriverTrait.php

@@ -158,7 +158,7 @@ trait PDODriverTrait
             return false;
         }
 
-        return $this->_connection->rollback();
+        return $this->_connection->rollBack();
     }
 
     /**

+ 1 - 1
src/Database/Schema/SqlserverSchema.php

@@ -120,7 +120,7 @@ class SqlserverSchema extends BaseSchema
         // SqlServer schema reflection returns double length for unicode
         // columns because internally it uses UTF16/UCS2
         if ($col === 'nvarchar' || $col === 'nchar' || $col === 'ntext') {
-            $length = $length / 2;
+            $length /= 2;
         }
         if (strpos($col, 'varchar') !== false && $length < 0) {
             return ['type' => TableSchema::TYPE_TEXT, 'length' => null];

+ 1 - 1
src/Database/Statement/StatementDecorator.php

@@ -239,7 +239,7 @@ class StatementDecorator implements StatementInterface, Countable, IteratorAggre
         $result = $this->fetch(static::FETCH_TYPE_NUM);
         if (isset($result[$position])) {
             return $result[$position];
-        };
+        }
 
         return false;
     }

+ 1 - 1
src/Datasource/EntityTrait.php

@@ -1356,7 +1356,7 @@ trait EntityTrait
             get_called_class() . '::source() is deprecated. ' .
             'Use setSource()/getSource() instead.'
         );
-        if (is_null($alias)) {
+        if ($alias === null) {
             return $this->getSource();
         }
 

+ 1 - 2
src/Event/EventManager.php

@@ -366,8 +366,7 @@ class EventManager implements EventManagerInterface
         $globalListeners = static::instance()->prioritisedListeners($eventKey);
         $globalListeners = empty($globalListeners) ? [] : $globalListeners;
 
-        $priorities = array_merge(array_keys($globalListeners), array_keys($localListeners));
-        $priorities = array_unique($priorities);
+        $priorities = array_unique(array_merge(array_keys($globalListeners), array_keys($localListeners)));
         asort($priorities);
 
         $result = [];

+ 1 - 1
src/Http/Response.php

@@ -592,7 +592,7 @@ class Response implements ResponseInterface
         if ($charset) {
             $this->_setHeader('Content-Type', "{$this->_contentType}; charset={$this->_charset}");
         } else {
-            $this->_setHeader('Content-Type', "{$this->_contentType}");
+            $this->_setHeader('Content-Type', (string)$this->_contentType);
         }
     }
 

+ 1 - 1
src/Mailer/Transport/SmtpTransport.php

@@ -342,7 +342,7 @@ class SmtpTransport extends AbstractTransport
         $lines = $email->message();
         $messages = [];
         foreach ($lines as $line) {
-            if ((!empty($line)) && ($line[0] === '.')) {
+            if (!empty($line) && ($line[0] === '.')) {
                 $messages[] = '.' . $line;
             } else {
                 $messages[] = $line;

+ 1 - 1
src/ORM/Behavior/TreeBehavior.php

@@ -905,7 +905,7 @@ class TreeBehavior extends Behavior
             $exp = $query->newExpr();
 
             $movement = clone $exp;
-            $movement->add($field)->add("$shift")->setConjunction($dir);
+            $movement->add($field)->add((string)$shift)->setConjunction($dir);
 
             $inverse = clone $exp;
             $movement = $mark ?

+ 1 - 1
src/Shell/CommandListShell.php

@@ -49,7 +49,7 @@ class CommandListShell extends Shell
         $this->hr();
         $this->out(sprintf('App : %s', APP_DIR));
         $this->out(sprintf('Path: %s', APP));
-        $this->out(sprintf('PHP : %s', phpversion()));
+        $this->out(sprintf('PHP : %s', PHP_VERSION));
         $this->hr();
     }
 

+ 1 - 2
src/Utility/Hash.php

@@ -712,8 +712,7 @@ class Hash
     {
         $result = [];
         foreach ($data as $flat => $value) {
-            $keys = explode($separator, $flat);
-            $keys = array_reverse($keys);
+            $keys = array_reverse(explode($separator, $flat));
             $child = [
                 $keys[0] => $value
             ];

+ 1 - 1
src/Utility/Text.php

@@ -878,7 +878,7 @@ class Text
         $phraseLen = mb_strlen($phrase);
         $textLen = mb_strlen($text);
 
-        $pos = mb_strpos(mb_strtolower($text), mb_strtolower($phrase));
+        $pos = mb_stripos($text, $phrase);
         if ($pos === false) {
             return mb_substr($text, 0, $radius) . $ellipsis;
         }

+ 1 - 1
src/View/Helper/FormHelper.php

@@ -1465,7 +1465,7 @@ class FormHelper extends Helper
 
         if ($allowOverride && substr($fieldName, -5) === '._ids') {
             $options['type'] = 'select';
-            if ((!isset($options['multiple']) || ($options['multiple'] && $options['multiple'] != 'checkbox'))) {
+            if (!isset($options['multiple']) || ($options['multiple'] && $options['multiple'] != 'checkbox')) {
                 $options['multiple'] = true;
             }
         }

+ 1 - 2
src/View/Helper/HtmlHelper.php

@@ -355,8 +355,7 @@ class HtmlHelper extends Helper
             unset($options['fullBase']);
         } else {
             $url = $this->Url->build($title);
-            $title = htmlspecialchars_decode($url, ENT_QUOTES);
-            $title = h(urldecode($title));
+            $title = h(urldecode(htmlspecialchars_decode($url, ENT_QUOTES)));
             $escapeTitle = false;
         }