Browse Source

Merge pull request #13238 from cakephp/4.x-psalm

Fix return type errors reported by psalm.
Mark Story 6 years ago
parent
commit
ded0aafd65

+ 0 - 98
psalm-baseline.xml

@@ -275,9 +275,6 @@
     </PossiblyNullArrayOffset>
   </file>
   <file src="src/Console/HelperRegistry.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>new $class($this-&gt;_io, $settings)</code>
-    </LessSpecificReturnStatement>
     <MissingConstructor occurrences="1">
       <code>$_io</code>
     </MissingConstructor>
@@ -285,9 +282,6 @@
       <code>$class</code>
       <code>$class</code>
     </MoreSpecificImplementedParamType>
-    <MoreSpecificReturnType occurrences="1">
-      <code>Helper</code>
-    </MoreSpecificReturnType>
   </file>
   <file src="src/Console/Shell.php">
     <DeprecatedClass occurrences="1">
@@ -323,27 +317,15 @@
       <code>static::alias($shell, "$plugin.$shell")</code>
       <code>static::alias($shell)</code>
     </DeprecatedClass>
-    <LessSpecificReturnStatement occurrences="1">
-      <code>$instance</code>
-    </LessSpecificReturnStatement>
-    <MoreSpecificReturnType occurrences="1">
-      <code>Shell</code>
-    </MoreSpecificReturnType>
     <UndefinedConstant occurrences="1">
       <code>CAKE_CORE_INCLUDE_PATH</code>
     </UndefinedConstant>
   </file>
   <file src="src/Console/TaskRegistry.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>new $class($this-&gt;_Shell-&gt;getIo())</code>
-    </LessSpecificReturnStatement>
     <MoreSpecificImplementedParamType occurrences="2">
       <code>$class</code>
       <code>$class</code>
     </MoreSpecificImplementedParamType>
-    <MoreSpecificReturnType occurrences="1">
-      <code>Shell</code>
-    </MoreSpecificReturnType>
   </file>
   <file src="src/Controller/Component/AuthComponent.php">
     <InvalidScalarArgument occurrences="1">
@@ -425,16 +407,10 @@
     </PropertyNotSetInConstructor>
   </file>
   <file src="src/Controller/ComponentRegistry.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>$instance</code>
-    </LessSpecificReturnStatement>
     <MoreSpecificImplementedParamType occurrences="2">
       <code>$class</code>
       <code>$class</code>
     </MoreSpecificImplementedParamType>
-    <MoreSpecificReturnType occurrences="1">
-      <code>Component</code>
-    </MoreSpecificReturnType>
     <PropertyNotSetInConstructor occurrences="1">
       <code>ComponentRegistry</code>
     </PropertyNotSetInConstructor>
@@ -1161,10 +1137,6 @@
     </MoreSpecificImplementedParamType>
   </file>
   <file src="src/Database/Type/DateTimeType.php">
-    <LessSpecificReturnStatement occurrences="2">
-      <code>$date</code>
-      <code>new $class($format, $tz)</code>
-    </LessSpecificReturnStatement>
     <MissingParamType occurrences="1">
       <code>$name</code>
     </MissingParamType>
@@ -1172,9 +1144,6 @@
       <code>$value</code>
       <code>$value</code>
     </MoreSpecificImplementedParamType>
-    <MoreSpecificReturnType occurrences="1">
-      <code>?DateTimeInterface</code>
-    </MoreSpecificReturnType>
     <PossiblyInvalidArgument occurrences="2">
       <code>$value</code>
       <code>$value</code>
@@ -1211,14 +1180,6 @@
       <code>$this-&gt;_driver</code>
     </PossiblyNullArgument>
   </file>
-  <file src="src/Database/TypeFactory.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>static::$_builtTypes[$name] = new static::$_types[$name]($name)</code>
-    </LessSpecificReturnStatement>
-    <MoreSpecificReturnType occurrences="1">
-      <code>TypeInterface</code>
-    </MoreSpecificReturnType>
-  </file>
   <file src="src/Datasource/ConnectionManager.php">
     <PossiblyNullArgument occurrences="1">
       <code>$config</code>
@@ -1276,11 +1237,6 @@
       <code>$end</code>
     </PossiblyNullOperand>
   </file>
-  <file src="src/Error/Middleware/ErrorHandlerMiddleware.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>new $class($exception, $request)</code>
-    </LessSpecificReturnStatement>
-  </file>
   <file src="src/Event/Decorator/SubjectFilterDecorator.php">
     <PossiblyInvalidArgument occurrences="1">
       <code>$this-&gt;_options['allowedSubject']</code>
@@ -1647,14 +1603,6 @@
       <code>static::$niceFormat</code>
     </PossiblyInvalidArgument>
   </file>
-  <file src="src/I18n/TranslatorFactory.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>new $class($locale, $package, $formatter, $fallback)</code>
-    </LessSpecificReturnStatement>
-    <MoreSpecificReturnType occurrences="1">
-      <code>\Cake\I18n\Translator</code>
-    </MoreSpecificReturnType>
-  </file>
   <file src="src/I18n/TranslatorRegistry.php">
     <ImplementedReturnTypeMismatch occurrences="1">
       <code>\Aura\Intl\TranslatorInterface|null</code>
@@ -1933,18 +1881,12 @@
     </MissingClosureReturnType>
   </file>
   <file src="src/ORM/Behavior/TranslateBehavior.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>new $className($this-&gt;_table, $config)</code>
-    </LessSpecificReturnStatement>
     <MissingClosureParamType occurrences="1">
       <code>$query</code>
     </MissingClosureParamType>
     <MissingClosureReturnType occurrences="1">
       <code>function ($query) use ($locales, $targetAlias) {</code>
     </MissingClosureReturnType>
-    <MoreSpecificReturnType occurrences="1">
-      <code>\Cake\ORM\Behavior\Translate\TranslateStrategyInterface</code>
-    </MoreSpecificReturnType>
     <PossiblyInvalidMethodCall occurrences="1">
       <code>getTableLocator</code>
     </PossiblyInvalidMethodCall>
@@ -1975,16 +1917,10 @@
     </PropertyNotSetInConstructor>
   </file>
   <file src="src/ORM/BehaviorRegistry.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>$instance</code>
-    </LessSpecificReturnStatement>
     <MoreSpecificImplementedParamType occurrences="2">
       <code>$class</code>
       <code>$class</code>
     </MoreSpecificImplementedParamType>
-    <MoreSpecificReturnType occurrences="1">
-      <code>Behavior</code>
-    </MoreSpecificReturnType>
     <PropertyNotSetInConstructor occurrences="2">
       <code>$_table</code>
       <code>BehaviorRegistry</code>
@@ -2043,14 +1979,6 @@
       <code>indexBy</code>
     </PossiblyUndefinedMethod>
   </file>
-  <file src="src/ORM/Locator/TableLocator.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>new $options['className']($options)</code>
-    </LessSpecificReturnStatement>
-    <MoreSpecificReturnType occurrences="1">
-      <code>Table</code>
-    </MoreSpecificReturnType>
-  </file>
   <file src="src/ORM/Marshaller.php">
     <InvalidArgument occurrences="1">
       <code>$key</code>
@@ -2085,9 +2013,6 @@
     <ImplementedReturnTypeMismatch occurrences="1">
       <code>$this</code>
     </ImplementedReturnTypeMismatch>
-    <LessSpecificReturnStatement occurrences="1">
-      <code>new $decorator($this-&gt;_results)</code>
-    </LessSpecificReturnStatement>
     <MissingParamType occurrences="3">
       <code>$config</code>
       <code>$method</code>
@@ -2096,9 +2021,6 @@
     <MoreSpecificImplementedParamType occurrences="1">
       <code>$table</code>
     </MoreSpecificImplementedParamType>
-    <MoreSpecificReturnType occurrences="1">
-      <code>ResultSetInterface</code>
-    </MoreSpecificReturnType>
     <NullArgument occurrences="1">
       <code>null</code>
     </NullArgument>
@@ -2129,9 +2051,6 @@
     </PossiblyInvalidMethodCall>
   </file>
   <file src="src/ORM/Table.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>new $class([], ['source' =&gt; $this-&gt;getRegistryAlias()])</code>
-    </LessSpecificReturnStatement>
     <MissingClosureParamType occurrences="5">
       <code>$results</code>
       <code>$results</code>
@@ -2147,9 +2066,6 @@
     <MoreSpecificImplementedParamType occurrences="1">
       <code>$options</code>
     </MoreSpecificImplementedParamType>
-    <MoreSpecificReturnType occurrences="1">
-      <code>EntityInterface</code>
-    </MoreSpecificReturnType>
     <PossiblyInvalidArgument occurrences="3">
       <code>$options</code>
       <code>$options</code>
@@ -2611,12 +2527,6 @@
       <code>ShellDispatcher</code>
       <code>parent::__construct($args, $bootstrap)</code>
     </DeprecatedClass>
-    <LessSpecificReturnStatement occurrences="1">
-      <code>$instance</code>
-    </LessSpecificReturnStatement>
-    <MoreSpecificReturnType occurrences="1">
-      <code>Shell</code>
-    </MoreSpecificReturnType>
     <PossiblyNullPropertyAssignmentValue occurrences="1">
       <code>$io</code>
     </PossiblyNullPropertyAssignmentValue>
@@ -3012,14 +2922,6 @@
       <code>include func_get_arg(0)</code>
     </UnresolvableInclude>
   </file>
-  <file src="src/View/ViewBuilder.php">
-    <LessSpecificReturnStatement occurrences="1">
-      <code>new $className($request, $response, $events, $data)</code>
-    </LessSpecificReturnStatement>
-    <MoreSpecificReturnType occurrences="1">
-      <code>View</code>
-    </MoreSpecificReturnType>
-  </file>
   <file src="src/View/Widget/MultiCheckboxWidget.php">
     <PossiblyInvalidArgument occurrences="1">
       <code>$labelAttrs</code>

+ 1 - 0
src/Console/HelperRegistry.php

@@ -96,6 +96,7 @@ class HelperRegistry extends ObjectRegistry
      */
     protected function _create($class, string $alias, array $settings): Helper
     {
+        /** @var \Cake\Console\Helper */
         return new $class($this->_io, $settings);
     }
 }

+ 1 - 0
src/Console/ShellDispatcher.php

@@ -381,6 +381,7 @@ class ShellDispatcher
     protected function _createShell(string $className, string $shortName): Shell
     {
         [$plugin] = pluginSplit($shortName);
+        /** @var \Cake\Console\Shell $instance */
         $instance = new $className();
         $instance->plugin = trim((string)$plugin, '.');
 

+ 1 - 0
src/Console/TaskRegistry.php

@@ -87,6 +87,7 @@ class TaskRegistry extends ObjectRegistry
      */
     protected function _create($class, string $alias, array $settings): Shell
     {
+        /** @var \Cake\Console\Shell */
         return new $class($this->_Shell->getIo());
     }
 }

+ 1 - 0
src/Controller/ComponentRegistry.php

@@ -124,6 +124,7 @@ class ComponentRegistry extends ObjectRegistry implements EventDispatcherInterfa
      */
     protected function _create($class, string $alias, array $config): Component
     {
+        /** @var \Cake\Controller\Component $instance */
         $instance = new $class($this, $config);
         $enable = $config['enabled'] ?? true;
         if ($enable) {

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

@@ -425,6 +425,7 @@ class QueryExpression implements ExpressionInterface, Countable
             return $conditions(new static([], $this->getTypeMap()->setTypes($types)));
         }
 
+        /** @var \Cake\Database\Expression\QueryExpression */
         return new static($conditions, $this->getTypeMap()->setTypes($types));
     }
 
@@ -443,6 +444,7 @@ class QueryExpression implements ExpressionInterface, Countable
             return $conditions(new static([], $this->getTypeMap()->setTypes($types), 'OR'));
         }
 
+        /** @var \Cake\Database\Expression\QueryExpression */
         return new static($conditions, $this->getTypeMap()->setTypes($types), 'OR');
     }
 // phpcs:enable
@@ -656,6 +658,7 @@ class QueryExpression implements ExpressionInterface, Countable
             $numericKey = is_numeric($k);
 
             if ($this->isCallable($c)) {
+                /** @var \Cake\Database\Expression\QueryExpression $expr */
                 $expr = new static([], $typeMap);
                 $c = $c($expr, $this);
             }
@@ -687,6 +690,7 @@ class QueryExpression implements ExpressionInterface, Countable
             }
 
             if ($numericKey && $isArray || $isOperator) {
+                /** @var \Cake\Database\Expression\QueryExpression $this->_conditions[] */
                 $this->_conditions[] = new static($c, $typeMap, $numericKey ? 'AND' : $k);
                 continue;
             }

+ 3 - 0
src/Database/Type/DateTimeType.php

@@ -234,10 +234,12 @@ class DateTimeType extends BaseType
             }
             $isString = is_string($value);
             if (ctype_digit($value)) {
+                /** @var \DateTimeInterface $date */
                 $date = new $class('@' . $value);
             } elseif ($isString && $this->_useLocaleParser) {
                 return $this->_parseValue($value);
             } elseif ($isString) {
+                /** @var \DateTimeInterface $date */
                 $date = new $class($value);
                 $compare = true;
             }
@@ -278,6 +280,7 @@ class DateTimeType extends BaseType
         );
         $tz = $value['timezone'] ?? null;
 
+        /** @var \DateTimeInterface */
         return new $class($format, $tz);
     }
 

+ 1 - 0
src/Database/TypeFactory.php

@@ -73,6 +73,7 @@ class TypeFactory
             throw new InvalidArgumentException(sprintf('Unknown type "%s"', $name));
         }
 
+        /** @var \Cake\Database\TypeInterface */
         return static::$_builtTypes[$name] = new static::$_types[$name]($name);
     }
 

+ 1 - 0
src/Error/Middleware/ErrorHandlerMiddleware.php

@@ -159,6 +159,7 @@ class ErrorHandlerMiddleware implements MiddlewareInterface
                 ));
             }
 
+            /** @var \Cake\Error\ExceptionRendererInterface */
             return new $class($exception, $request);
         }
 

+ 1 - 0
src/I18n/TranslatorFactory.php

@@ -60,6 +60,7 @@ class TranslatorFactory extends BaseTranslatorFactory
             ));
         }
 
+        /** @var \Cake\I18n\Translator */
         return new $class($locale, $package, $formatter, $fallback);
     }
 }

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

@@ -158,6 +158,7 @@ class TranslateBehavior extends Behavior implements PropertyMarshalInterface
         );
         $className = $this->getConfig('strategyClass', static::$defaultStrategyClass);
 
+        /** @var \Cake\ORM\Behavior\Translate\TranslateStrategyInterface */
         return new $className($this->_table, $config);
     }
 

+ 1 - 0
src/ORM/BehaviorRegistry.php

@@ -141,6 +141,7 @@ class BehaviorRegistry extends ObjectRegistry implements EventDispatcherInterfac
      */
     protected function _create($class, string $alias, array $config): Behavior
     {
+        /** @var \Cake\ORM\Behavior $instance */
         $instance = new $class($this->_table, $config);
         $enable = $config['enabled'] ?? true;
         if ($enable) {

+ 1 - 0
src/ORM/Locator/TableLocator.php

@@ -258,6 +258,7 @@ class TableLocator implements LocatorInterface
      */
     protected function _create(array $options): Table
     {
+        /** @var \Cake\ORM\Table */
         return new $options['className']($options);
     }
 

+ 1 - 0
src/ORM/Query.php

@@ -1084,6 +1084,7 @@ class Query extends DatabaseQuery implements JsonSerializable, QueryInterface
         if ($this->_results) {
             $decorator = $this->_decoratorClass();
 
+            /** @var \Cake\Datasource\ResultSetInterface */
             return new $decorator($this->_results);
         }
 

+ 1 - 0
src/ORM/Table.php

@@ -2411,6 +2411,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     {
         $class = $this->getEntityClass();
 
+        /** @var \Cake\Datasource\EntityInterface */
         return new $class([], ['source' => $this->getRegistryAlias()]);
     }
 

+ 1 - 0
src/TestSuite/LegacyShellDispatcher.php

@@ -52,6 +52,7 @@ class LegacyShellDispatcher extends ShellDispatcher
     protected function _createShell(string $className, string $shortName): Shell
     {
         [$plugin] = pluginSplit($shortName);
+        /** @var \Cake\Console\Shell $instance */
         $instance = new $className($this->_io);
         if ($plugin) {
             $instance->plugin = trim($plugin, '.');

+ 1 - 0
src/View/ViewBuilder.php

@@ -526,6 +526,7 @@ class ViewBuilder implements JsonSerializable, Serializable
         ];
         $data += $this->_options;
 
+        /** @var \Cake\View\View */
         return new $className($request, $response, $events, $data);
     }