Browse Source

Merge pull request #14401 from cakephp/psalm

Improve psalm annotations
othercorey 6 years ago
parent
commit
dabb56c4af

+ 0 - 5
phpstan-baseline.neon

@@ -626,11 +626,6 @@ parameters:
 			path: src/TestSuite/IntegrationTestCase.php
 
 		-
-			message: "#^Unable to resolve the template type RealInstanceType in call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:getMockBuilder\\(\\)$#"
-			count: 1
-			path: src/TestSuite/TestCase.php
-
-		-
 			message: "#^Return type \\(array\\<string, array\\|string\\>\\) of method Cake\\\\View\\\\Exception\\\\MissingCellTemplateException\\:\\:getAttributes\\(\\) should be compatible with return type \\(array\\<string, array\\|string\\>\\) of method Cake\\\\View\\\\Exception\\\\MissingTemplateException\\:\\:getAttributes\\(\\)$#"
 			count: 1
 			path: src/View/Exception/MissingCellTemplateException.php

+ 1 - 0
src/Database/TypeFactory.php

@@ -115,6 +115,7 @@ class TypeFactory
      * @param string $type Name of type to map.
      * @param string $className The classname to register.
      * @return void
+     * @psalm-param class-string<\Cake\Database\TypeInterface> $className
      */
     public static function map(string $type, string $className): void
     {

+ 1 - 0
src/Mailer/Email.php

@@ -100,6 +100,7 @@ class Email implements JsonSerializable, Serializable
      * Message class name.
      *
      * @var string
+     * @psalm-var class-string<\Cake\Mailer\Message>
      */
     protected $messageClass = Message::class;
 

+ 4 - 1
src/ORM/Behavior/TranslateBehavior.php

@@ -67,7 +67,8 @@ class TranslateBehavior extends Behavior implements PropertyMarshalInterface
     /**
      * Default strategy class name.
      *
-     * @var class-string<\Cake\ORM\Behavior\Translate\TranslateStrategyInterface>
+     * @var string
+     * @psalm-var class-string<\Cake\ORM\Behavior\Translate\TranslateStrategyInterface>
      */
     protected static $defaultStrategyClass = EavStrategy::class;
 
@@ -132,6 +133,7 @@ class TranslateBehavior extends Behavior implements PropertyMarshalInterface
      * @param string $class Class name.
      * @return void
      * @since 4.0.0
+     * @psalm-var class-string<\Cake\ORM\Behavior\Translate\TranslateStrategyInterface>
      */
     public static function setDefaultStrategyClass(string $class)
     {
@@ -143,6 +145,7 @@ class TranslateBehavior extends Behavior implements PropertyMarshalInterface
      *
      * @return string
      * @since 4.0.0
+     * @psalm-return class-string<\Cake\ORM\Behavior\Translate\TranslateStrategyInterface>
      */
     public static function getDefaultStrategyClass(): string
     {

+ 1 - 1
src/ORM/RulesChecker.php

@@ -83,7 +83,7 @@ class RulesChecker extends BaseRulesChecker
      *
      * @param string|string[] $field The field or list of fields to check for existence by
      * primary key lookup in the other table.
-     * @param object|string $table The table name where the fields existence will be checked.
+     * @param \Cake\ORM\Table|\Cake\ORM\Association|string $table The table name where the fields existence will be checked.
      * @param string|array|null $message The error message to show in case the rule does not pass. Can
      *   also be an array of options. When an array, the 'message' key can be used to provide a message.
      * @return \Cake\Datasource\RuleInvoker

+ 2 - 1
src/ORM/Table.php

@@ -735,8 +735,9 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
      */
     public function setEntityClass(string $name)
     {
+        /** @psalm-var class-string<\Cake\Datasource\EntityInterface>|null */
         $class = App::className($name, 'Model/Entity');
-        if (!$class) {
+        if ($class === null) {
             throw new MissingEntityException([$name]);
         }
 

+ 1 - 0
src/TestSuite/MiddlewareDispatcher.php

@@ -48,6 +48,7 @@ class MiddlewareDispatcher
      * The application class name
      *
      * @var string
+     * @psalm-var class-string
      */
     protected $_class;
 

+ 2 - 0
src/TestSuite/TestCase.php

@@ -213,6 +213,7 @@ abstract class TestCase extends BaseTestCase
     public function loadRoutes(?array $appArgs = null): void
     {
         $appArgs = $appArgs ?? [rtrim(CONFIG, DIRECTORY_SEPARATOR)];
+        /** @psalm-var class-string */
         $className = Configure::read('App.namespace') . '\\Application';
         try {
             $reflect = new ReflectionClass($className);
@@ -834,6 +835,7 @@ abstract class TestCase extends BaseTestCase
      * @param array $options The config data for the mock's constructor.
      * @return string
      * @throws \Cake\ORM\Exception\MissingTableClassException
+     * @psalm-return class-string<\Cake\ORM\Table>
      */
     protected function _getTableClassName(string $alias, array $options): string
     {

+ 1 - 0
src/Validation/RulesProvider.php

@@ -43,6 +43,7 @@ class RulesProvider
      *
      * @param string|object $class the default class to proxy
      * @throws \ReflectionException
+     * @psalm-param class-string|object $class
      */
     public function __construct($class = Validation::class)
     {

+ 1 - 0
src/View/Helper/NumberHelper.php

@@ -66,6 +66,7 @@ class NumberHelper extends Helper
 
         $config = $this->_config;
 
+        /** @psalm-var class-string<\Cake\I18n\Number>|null $engineClass */
         $engineClass = App::className($config['engine'], 'Utility');
         if ($engineClass === null) {
             throw new Exception(sprintf('Class for %s could not be found', $config['engine']));

+ 5 - 3
src/View/Helper/TextHelper.php

@@ -82,12 +82,14 @@ class TextHelper extends Helper
         parent::__construct($view, $config);
 
         $config = $this->_config;
+
+        /** @psalm-var class-string<\Cake\Utility\Text>|null $engineClass */
         $engineClass = App::className($config['engine'], 'Utility');
-        if ($engineClass) {
-            $this->_engine = new $engineClass($config);
-        } else {
+        if ($engineClass === null) {
             throw new Exception(sprintf('Class for %s could not be found', $config['engine']));
         }
+
+        $this->_engine = new $engineClass($config);
     }
 
     /**

+ 1 - 0
src/View/View.php

@@ -273,6 +273,7 @@ class View implements EventDispatcherInterface
      * ViewBlock class.
      *
      * @var string
+     * @psalm-var class-string<\Cake\View\ViewBlock>
      */
     protected $_viewBlockClass = ViewBlock::class;