Browse Source

Fix few errors reported by phpstan level 3

ADmad 8 years ago
parent
commit
4efa6b60ad

+ 1 - 1
src/Auth/Storage/MemoryStorage.php

@@ -23,7 +23,7 @@ class MemoryStorage implements StorageInterface
     /**
      * User record.
      *
-     * @var array|null
+     * @var \ArrayAccess|array|null
      */
     protected $_user;
 

+ 1 - 1
src/Auth/Storage/SessionStorage.php

@@ -34,7 +34,7 @@ class SessionStorage implements StorageInterface
      * Stores user record array if fetched from session or false if session
      * does not have user record.
      *
-     * @var array|bool
+     * @var \ArrayAccess|array|bool
      */
     protected $_user;
 

+ 1 - 1
src/Console/ConsoleIo.php

@@ -166,7 +166,7 @@ class ConsoleIo
     public function out($message = '', $newlines = 1, $level = ConsoleIo::NORMAL)
     {
         if ($level <= $this->_level) {
-            $this->_lastWritten = $this->_out->write($message, $newlines);
+            $this->_lastWritten = (int)$this->_out->write($message, $newlines);
 
             return $this->_lastWritten;
         }

+ 1 - 1
src/Console/ConsoleOptionParser.php

@@ -739,7 +739,7 @@ class ConsoleOptionParser
                 return $formatter->text($width);
             }
             if ($format === 'xml') {
-                return $formatter->xml();
+                return (string)$formatter->xml();
             }
         }
 

+ 1 - 1
src/Console/ShellDispatcher.php

@@ -200,7 +200,7 @@ class ShellDispatcher
      * to be dispatched.
      * Built-in extra parameter is :
      * - `requested` : if used, will prevent the Shell welcome message to be displayed
-     * @return bool
+     * @return bool|int|null
      * @throws \Cake\Console\Exception\MissingShellMethodException
      */
     protected function _dispatch($extra = [])

+ 1 - 1
src/Core/App.php

@@ -48,7 +48,7 @@ class App
      * @param string $class Class name
      * @param string $type Type of class
      * @param string $suffix Class name suffix
-     * @return bool|string False if the class is not found or namespaced class name
+     * @return false|string False if the class is not found or namespaced class name
      */
     public static function className($class, $type = '', $suffix = '')
     {

+ 2 - 2
src/Database/Type/DateTimeType.php

@@ -127,7 +127,7 @@ class DateTimeType extends Type implements TypeInterface
      *
      * @param string $value The value to convert.
      * @param \Cake\Database\Driver $driver The driver instance to convert with.
-     * @return \Cake\I18n\Time|\DateTime
+     * @return \Cake\I18n\Time|\DateTime|null
      */
     public function toPHP($value, Driver $driver)
     {
@@ -148,7 +148,7 @@ class DateTimeType extends Type implements TypeInterface
      * Convert request data into a datetime object.
      *
      * @param mixed $value Request data
-     * @return \Cake\I18n\Time|\DateTime
+     * @return \DateTimeInterface
      */
     public function marshal($value)
     {

+ 1 - 1
src/Database/Type/DateType.php

@@ -66,7 +66,7 @@ class DateType extends DateTimeType
      * Convert request data into a datetime object.
      *
      * @param mixed $value Request data
-     * @return \DateTime
+     * @return \DateTimeInterface
      */
     public function marshal($value)
     {

+ 1 - 1
src/Datasource/RepositoryInterface.php

@@ -132,7 +132,7 @@ interface RepositoryInterface
      *
      * @param \Cake\Datasource\EntityInterface $entity the entity to be saved
      * @param array|\ArrayAccess $options The options to use when saving.
-     * @return \Cake\Datasource\EntityInterface|bool
+     * @return \Cake\Datasource\EntityInterface|false
      */
     public function save(EntityInterface $entity, $options = []);
 

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

@@ -61,7 +61,7 @@ class ErrorHandlerMiddleware
     /**
      * Exception render.
      *
-     * @var \Cake\Error\ExceptionRendererInterface|string|null
+     * @var \Cake\Error\ExceptionRendererInterface|callable|string|null
      */
     protected $exceptionRenderer;
 

+ 1 - 1
src/Event/EventManager.php

@@ -42,7 +42,7 @@ class EventManager
     /**
      * List of listener callbacks associated to
      *
-     * @var object
+     * @var array
      */
     protected $_listeners = [];
 

+ 1 - 1
src/Filesystem/Folder.php

@@ -131,7 +131,7 @@ class Folder
      *
      * @param string|null $path Path to folder
      * @param bool $create Create folder if not found
-     * @param int|bool $mode Mode (CHMOD) to apply to created folder, false to ignore
+     * @param int|false $mode Mode (CHMOD) to apply to created folder, false to ignore
      */
     public function __construct($path = null, $create = false, $mode = false)
     {

+ 1 - 0
src/Http/Client.php

@@ -503,6 +503,7 @@ class Client
 
         $request = new Request($url, $method, $headers, $data);
         $cookies = isset($options['cookies']) ? $options['cookies'] : [];
+        /** @var \Cake\Http\Client\Request $request */
         $request = $this->_cookies->addToRequest($request, $cookies);
         if (isset($options['auth'])) {
             $request = $this->_addAuthentication($request, $options);

+ 7 - 0
src/Mailer/Email.php

@@ -1591,6 +1591,13 @@ class Email implements JsonSerializable, Serializable
         $config = static::$_transportConfig[$name];
 
         if (is_object($config['className'])) {
+            if (!$config['className'] instanceof AbstractTransport) {
+                throw new InvalidArgumentException(sprintf(
+                    'Transport object must be of type "AbstractTransport". Found invalid type: "%s".',
+                    get_class($config['className'])
+                ));
+            }
+
             return $config['className'];
         }
 

+ 1 - 1
src/ORM/Association/BelongsTo.php

@@ -182,7 +182,7 @@ class BelongsTo extends Association
     /**
      * {@inheritDoc}
      *
-     * @return callable
+     * @return \Closure
      */
     public function eagerLoader(array $options)
     {

+ 1 - 1
src/ORM/Association/BelongsToMany.php

@@ -551,7 +551,7 @@ class BelongsToMany extends Association
     /**
      * {@inheritDoc}
      *
-     * @return callable
+     * @return \Closure
      */
     public function eagerLoader(array $options)
     {

+ 1 - 1
src/ORM/Association/HasMany.php

@@ -668,7 +668,7 @@ class HasMany extends Association
     /**
      * {@inheritDoc}
      *
-     * @return callable
+     * @return \Closure
      */
     public function eagerLoader(array $options)
     {

+ 1 - 1
src/ORM/Association/HasOne.php

@@ -125,7 +125,7 @@ class HasOne extends Association
     /**
      * {@inheritDoc}
      *
-     * @return callable
+     * @return \Closure
      */
     public function eagerLoader(array $options)
     {

+ 2 - 2
src/ORM/Rule/ExistsIn.php

@@ -35,7 +35,7 @@ class ExistsIn
     /**
      * The repository where the field will be looked for
      *
-     * @var \Cake\Datasource\RepositoryInterface|\Cake\ORM\Association
+     * @var \Cake\Datasource\RepositoryInterface|\Cake\ORM\Association|string
      */
     protected $_repository;
 
@@ -53,7 +53,7 @@ class ExistsIn
      * Set to true to accept composite foreign keys where one or more nullable columns are null.
      *
      * @param string|array $fields The field or fields to check existence as primary key.
-     * @param object|string $repository The repository where the field will be looked for,
+     * @param \Cake\Datasource\RepositoryInterface|\Cake\ORM\Association|string $repository The repository where the field will be looked for,
      * or the association name for the repository.
      * @param array $options The options that modify the rules behavior.
      *     Options 'allowNullableNulls' will make the rule pass if given foreign keys are set to `null`.

+ 8 - 4
src/ORM/Table.php

@@ -968,8 +968,9 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     {
         $options += ['sourceTable' => $this];
         $association = new BelongsTo($associated, $options);
+        $this->_associations->add($association->getName(), $association);
 
-        return $this->_associations->add($association->getName(), $association);
+        return $association;
     }
 
     /**
@@ -1012,8 +1013,9 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     {
         $options += ['sourceTable' => $this];
         $association = new HasOne($associated, $options);
+        $this->_associations->add($association->getName(), $association);
 
-        return $this->_associations->add($association->getName(), $association);
+        return $association;
     }
 
     /**
@@ -1062,8 +1064,9 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     {
         $options += ['sourceTable' => $this];
         $association = new HasMany($associated, $options);
+        $this->_associations->add($association->getName(), $association);
 
-        return $this->_associations->add($association->getName(), $association);
+        return $association;
     }
 
     /**
@@ -1114,8 +1117,9 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     {
         $options += ['sourceTable' => $this];
         $association = new BelongsToMany($associated, $options);
+        $this->_associations->add($association->getName(), $association);
 
-        return $this->_associations->add($association->getName(), $association);
+        return $association;
     }
 
     /**

+ 1 - 1
src/TestSuite/TestCase.php

@@ -661,7 +661,7 @@ abstract class TestCase extends BaseTestCase
         $options += ['alias' => $baseClass, 'connection' => $connection];
         $options += TableRegistry::config($alias);
 
-        /** @var \Cake\ORM\Table $mock */
+        /** @var \Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject $mock */
         $mock = $this->getMockBuilder($options['className'])
             ->setMethods($methods)
             ->setConstructorArgs([$options])