Browse Source

Merge pull request #14083 from cakephp/psalm

Fix errors reported by psalm
othercorey 6 years ago
parent
commit
40f515b7f4

+ 1 - 0
src/Core/StaticConfigTrait.php

@@ -105,6 +105,7 @@ trait StaticConfigTrait
             $config['className'] = $config['engine'];
             unset($config['engine']);
         }
+        /** @psalm-suppress InvalidPropertyAssignmentValue */
         static::$_config[$key] = $config;
     }
 

+ 0 - 1
src/Event/EventManager.php

@@ -157,7 +157,6 @@ class EventManager implements EventManagerInterface
      * @param array $function the array taken from a handler definition for an event
      * @param \Cake\Event\EventListenerInterface $object The handler object
      * @return array
-     * @psalm-return array{callable, array}
      */
     protected function _extractCallable(array $function, EventListenerInterface $object): array
     {

+ 1 - 0
src/I18n/Translator.php

@@ -105,6 +105,7 @@ class Translator extends BaseTranslator
                 return $message['_context'][''] === '' ? $key : $message['_context'][''];
             }
 
+            /** @psalm-suppress PossiblyUndefinedArrayOffset */
             return current($message['_context']);
         }
         if (!isset($message['_context'][$context])) {

+ 3 - 9
src/ORM/Behavior/CounterCacheBehavior.php

@@ -21,7 +21,7 @@ use Cake\Datasource\EntityInterface;
 use Cake\Event\EventInterface;
 use Cake\ORM\Association;
 use Cake\ORM\Behavior;
-use RuntimeException;
+use Closure;
 
 /**
  * CounterCache behavior
@@ -241,10 +241,7 @@ class CounterCacheBehavior extends Behavior
                 continue;
             }
 
-            if (is_callable($config)) {
-                if (is_string($config)) {
-                    throw new RuntimeException('You must not use a string as callable.');
-                }
+            if ($config instanceof Closure) {
                 $count = $config($event, $entity, $this->_table, false);
             } else {
                 $count = $this->_getCount($config, $countConditions);
@@ -254,10 +251,7 @@ class CounterCacheBehavior extends Behavior
             }
 
             if (isset($updateOriginalConditions)) {
-                if (is_callable($config)) {
-                    if (is_string($config)) {
-                        throw new RuntimeException('You must not use a string as callable.');
-                    }
+                if ($config instanceof Closure) {
                     $count = $config($event, $entity, $this->_table, true);
                 } else {
                     $count = $this->_getCount($config, $countOriginalConditions);

+ 1 - 0
src/ORM/TableRegistry.php

@@ -68,6 +68,7 @@ class TableRegistry
      * Default LocatorInterface implementation class.
      *
      * @var string
+     * @psalm-var class-string<\Cake\ORM\Locator\TableLocator>
      */
     protected static $_defaultLocatorClass = Locator\TableLocator::class;
 

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

@@ -873,7 +873,7 @@ class HtmlHelper extends Helper
         if (!empty($options['escape'])) {
             $text = h($text);
         }
-        if ($class && !empty($class)) {
+        if ($class) {
             $options['class'] = $class;
         }
         $tag = 'para';

+ 1 - 0
src/View/HelperRegistry.php

@@ -96,6 +96,7 @@ class HelperRegistry extends ObjectRegistry implements EventDispatcherInterface
             return $this->_loaded[$name];
         }
         if (isset($this->{$name})) {
+            /** @psalm-suppress InvalidReturnStatement */
             return $this->_loaded[$name];
         }
 

+ 1 - 0
src/View/StringTemplateTrait.php

@@ -77,6 +77,7 @@ trait StringTemplateTrait
     public function templater(): StringTemplate
     {
         if ($this->_templater === null) {
+            /** @psalm-var class-string<\Cake\View\StringTemplate> $class */
             $class = $this->getConfig('templateClass') ?: StringTemplate::class;
             $this->_templater = new $class();