Browse Source

Fix errors reported by psalm.

ADmad 7 years ago
parent
commit
8684c7db74

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

@@ -553,7 +553,7 @@ class SecurityComponent extends Component
         ?string $stringKeyMessage
     ): array {
         $messages = [];
-        foreach ((array)$dataFields as $key => $value) {
+        foreach ($dataFields as $key => $value) {
             if (is_int($key)) {
                 $foundKey = array_search($value, (array)$expectedFields);
                 if ($foundKey === false) {
@@ -561,7 +561,7 @@ class SecurityComponent extends Component
                 } else {
                     unset($expectedFields[$foundKey]);
                 }
-            } elseif (is_string($key)) {
+            } else {
                 if (isset($expectedFields[$key]) && $value !== $expectedFields[$key]) {
                     $messages[] = sprintf($stringKeyMessage, $key, $expectedFields[$key], $value);
                 }

+ 1 - 0
src/Core/Configure/Engine/IniConfig.php

@@ -157,6 +157,7 @@ class IniConfig implements ConfigEngineInterface
         $result = [];
         foreach ($data as $k => $value) {
             $isSection = false;
+            /** @psalm-suppress InvalidArrayAccess */
             if ($k[0] !== '[') {
                 $result[] = "[$k]";
                 $isSection = true;

+ 5 - 3
src/Database/Expression/Comparison.php

@@ -265,9 +265,11 @@ class Comparison implements ExpressionInterface, FieldInterface
     protected function _flattenValue(iterable $value, $generator, $type = 'string'): string
     {
         $parts = [];
-        foreach ($this->_valueExpressions as $k => $v) {
-            $parts[$k] = $v->sql($generator);
-            unset($value[$k]);
+        if (is_array($value)) {
+            foreach ($this->_valueExpressions as $k => $v) {
+                $parts[$k] = $v->sql($generator);
+                unset($value[$k]);
+            }
         }
 
         if (!empty($value)) {

+ 1 - 0
src/Database/Expression/QueryExpression.php

@@ -605,6 +605,7 @@ class QueryExpression implements ExpressionInterface, Countable
         if (is_string($c)) {
             return false;
         }
+        /** @psalm-suppress RedundantCondition */
         if (is_object($c) && is_callable($c)) {
             return true;
         }

+ 4 - 4
src/Event/EventManager.php

@@ -103,14 +103,14 @@ class EventManager implements EventManagerInterface
             return $this;
         }
         $argCount = func_num_args();
-        if ($argCount === 2) {
+        if ($eventKey && $argCount === 2) {
             $this->_listeners[$eventKey][static::$defaultPriority][] = [
                 'callable' => $options,
             ];
 
             return $this;
         }
-        if ($argCount === 3) {
+        if ($eventKey && $argCount === 3) {
             $priority = $options['priority'] ?? static::$defaultPriority;
             $this->_listeners[$eventKey][$priority][] = [
                 'callable' => $callable,
@@ -368,9 +368,9 @@ class EventManager implements EventManagerInterface
     /**
      * Returns the event list.
      *
-     * @return \Cake\Event\EventList
+     * @return \Cake\Event\EventList|null
      */
-    public function getEventList()
+    public function getEventList(): ?EventList
     {
         return $this->_eventList;
     }