ソースを参照

Fix errors reported by phpstan.

ADmad 8 年 前
コミット
e475be71ee

+ 1 - 2
phpstan.neon

@@ -15,14 +15,13 @@ parameters:
         - '#Call to an undefined method Psr\\Http\\Message\\ResponseInterface::getCookies\(\)#'
         - '#Access to an undefined property Psr\\Http\\Message\\UriInterface::\$webroot#'
         - '#Access to an undefined property Psr\\Http\\Message\\UriInterface::\$base#'
-        - '#Call to an undefined method Cake\\Collection\\Iterator\\ZipIterator::getInnerIterator\(\)#'
-        - '#Call to an undefined method Cake\\ORM\\ResultSet::getInnerIterator\(\)#'
         - '#Result of method Cake\\Http\\Response::send\(\) \(void\) is used#'
         - '#Method Cake\\View\\Form\\ContextInterface::val\(\) invoked with 2 parameters, 1 required#'
         - '#Access to an undefined property Exception::\$queryString#'
         - '#Access to an undefined property PHPUnit\\Framework\\Test::\$fixtureManager#'
         - '#Method Redis::#'
         - '#Call to an undefined method Traversable::getArrayCopy().#'
+        - '#Variable $config in isset\(\) is never defined#'
     earlyTerminatingMethodCalls:
         Cake\Shell\Shell:
             - abort

+ 3 - 3
src/Cache/Engine/ApcEngine.php

@@ -14,7 +14,7 @@
  */
 namespace Cake\Cache\Engine;
 
-use APCUIterator;
+use APCuIterator;
 use Cake\Cache\CacheEngine;
 
 /**
@@ -144,8 +144,8 @@ class ApcEngine extends CacheEngine
         if ($check) {
             return true;
         }
-        if (class_exists('APCUIterator', false)) {
-            $iterator = new APCUIterator(
+        if (class_exists('APCuIterator', false)) {
+            $iterator = new APCuIterator(
                 '/^' . preg_quote($this->_config['prefix'], '/') . '/',
                 APC_ITER_NONE
             );

+ 4 - 4
src/Console/ConsoleInputArgument.php

@@ -15,7 +15,7 @@
 namespace Cake\Console;
 
 use Cake\Console\Exception\ConsoleException;
-use SimpleXmlElement;
+use SimpleXMLElement;
 
 /**
  * An object to represent a single argument used in the command line.
@@ -178,10 +178,10 @@ class ConsoleInputArgument
     /**
      * Append this arguments XML representation to the passed in SimpleXml object.
      *
-     * @param \SimpleXmlElement $parent The parent element.
-     * @return \SimpleXmlElement The parent with this argument appended.
+     * @param \SimpleXMLElement $parent The parent element.
+     * @return \SimpleXMLElement The parent with this argument appended.
      */
-    public function xml(SimpleXmlElement $parent)
+    public function xml(SimpleXMLElement $parent)
     {
         $option = $parent->addChild('argument');
         $option->addAttribute('name', $this->_name);

+ 4 - 4
src/Console/ConsoleInputOption.php

@@ -15,7 +15,7 @@
 namespace Cake\Console;
 
 use Cake\Console\Exception\ConsoleException;
-use SimpleXmlElement;
+use SimpleXMLElement;
 
 /**
  * An object to represent a single option used in the command line.
@@ -240,10 +240,10 @@ class ConsoleInputOption
     /**
      * Append the option's xml into the parent.
      *
-     * @param \SimpleXmlElement $parent The parent element.
-     * @return \SimpleXmlElement The parent with this option appended.
+     * @param \SimpleXMLElement $parent The parent element.
+     * @return \SimpleXMLElement The parent with this option appended.
      */
-    public function xml(SimpleXmlElement $parent)
+    public function xml(SimpleXMLElement $parent)
     {
         $option = $parent->addChild('option');
         $option->addAttribute('name', '--' . $this->_name);

+ 4 - 4
src/Console/ConsoleInputSubcommand.php

@@ -16,7 +16,7 @@
  */
 namespace Cake\Console;
 
-use SimpleXmlElement;
+use SimpleXMLElement;
 
 /**
  * An object to represent a single subcommand used in the command line.
@@ -126,10 +126,10 @@ class ConsoleInputSubcommand
     /**
      * Append this subcommand to the Parent element
      *
-     * @param \SimpleXmlElement $parent The parent element.
-     * @return \SimpleXmlElement The parent with this subcommand appended.
+     * @param \SimpleXMLElement $parent The parent element.
+     * @return \SimpleXMLElement The parent with this subcommand appended.
      */
-    public function xml(SimpleXmlElement $parent)
+    public function xml(SimpleXMLElement $parent)
     {
         $command = $parent->addChild('command');
         $command->addAttribute('name', $this->_name);

+ 3 - 3
src/Console/HelpFormatter.php

@@ -16,7 +16,7 @@ namespace Cake\Console;
 
 use Cake\Console\Exception\ConsoleException;
 use Cake\Utility\Text;
-use SimpleXmlElement;
+use SimpleXMLElement;
 
 /**
  * HelpFormatter formats help for console shells. Can format to either
@@ -211,12 +211,12 @@ class HelpFormatter
      * Get the help as an xml string.
      *
      * @param bool $string Return the SimpleXml object or a string. Defaults to true.
-     * @return string|\SimpleXmlElement See $string
+     * @return string|\SimpleXMLElement See $string
      */
     public function xml($string = true)
     {
         $parser = $this->_parser;
-        $xml = new SimpleXmlElement('<shell></shell>');
+        $xml = new SimpleXMLElement('<shell></shell>');
         $xml->addChild('command', $parser->getCommand());
         $xml->addChild('description', $parser->getDescription());
 

+ 2 - 2
src/Controller/Controller.php

@@ -123,7 +123,7 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
      * This object contains all the information about a request and several methods for reading
      * additional information about the request.
      *
-     * @var \Cake\Http\ServerRequest
+     * @var \Cake\Http\ServerRequest|null
      * @link https://book.cakephp.org/3.0/en/controllers/request-response.html#request
      */
     public $request;
@@ -131,7 +131,7 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
     /**
      * An instance of a Response object that contains information about the impending response
      *
-     * @var \Cake\Http\Response
+     * @var \Cake\Http\Response|null
      * @link https://book.cakephp.org/3.0/en/controllers/request-response.html#response
      */
     public $response;

+ 1 - 0
src/Core/ObjectRegistry.php

@@ -126,6 +126,7 @@ abstract class ObjectRegistry implements Countable, IteratorAggregate
         if (empty($config)) {
             return;
         }
+        /* @var \Cake\Core\InstanceConfigTrait $existing */
         $existingConfig = $existing->getConfig();
         unset($config['enabled'], $existingConfig['enabled']);
 

+ 2 - 2
src/Database/Connection.php

@@ -827,7 +827,7 @@ class Connection implements ConnectionInterface
     /**
      * Sets a logger
      *
-     * @param object $logger Logger object
+     * @param \Cake\Database\Log\QueryLogger $logger Logger object
      * @return $this
      */
     public function setLogger($logger)
@@ -840,7 +840,7 @@ class Connection implements ConnectionInterface
     /**
      * Gets the logger object
      *
-     * @return object logger instance
+     * @return \Cake\Database\Log\QueryLogger logger instance
      */
     public function getLogger()
     {

+ 4 - 4
src/Database/Log/LoggingStatement.php

@@ -110,8 +110,8 @@ class LoggingStatement extends StatementDecorator
      * it returns the currently setup logger instance
      *
      * @deprecated 3.5.0 Use getLogger() and setLogger() instead.
-     * @param object|null $instance Logger object instance.
-     * @return object|null Logger instance
+     * @param \Cake\Database\Log\QueryLogger|null $instance Logger object instance.
+     * @return \Cake\Database\Log\QueryLogger|null Logger instance
      */
     public function logger($instance = null)
     {
@@ -125,7 +125,7 @@ class LoggingStatement extends StatementDecorator
     /**
      * Sets a logger
      *
-     * @param object $logger Logger object
+     * @param \Cake\Database\Log\QueryLogger $logger Logger object
      * @return void
      */
     public function setLogger($logger)
@@ -136,7 +136,7 @@ class LoggingStatement extends StatementDecorator
     /**
      * Gets the logger object
      *
-     * @return object logger instance
+     * @return \Cake\Database\Log\QueryLogger logger instance
      */
     public function getLogger()
     {

+ 1 - 1
src/Event/EventManager.php

@@ -63,7 +63,7 @@ class EventManager
     /**
      * Enables automatic adding of events to the event list object if it is present.
      *
-     * @param bool
+     * @var bool
      */
     protected $_trackEvents = false;
 

+ 4 - 4
src/Http/Cookie/Cookie.php

@@ -16,7 +16,7 @@ namespace Cake\Http\Cookie;
 use Cake\Chronos\Chronos;
 use Cake\Utility\Hash;
 use DateTimeImmutable;
-use DateTimezone;
+use DateTimeZone;
 use InvalidArgumentException;
 
 /**
@@ -146,7 +146,7 @@ class Cookie implements CookieInterface
         $this->validateBool($secure);
         $this->secure = $secure;
         if ($expiresAt) {
-            $expiresAt = $expiresAt->setTimezone(new DateTimezone('GMT'));
+            $expiresAt = $expiresAt->setTimezone(new DateTimeZone('GMT'));
         }
         $this->expiresAt = $expiresAt;
     }
@@ -397,7 +397,7 @@ class Cookie implements CookieInterface
     public function withExpiry($dateTime)
     {
         $new = clone $this;
-        $new->expiresAt = $dateTime->setTimezone(new DateTimezone('GMT'));
+        $new->expiresAt = $dateTime->setTimezone(new DateTimeZone('GMT'));
 
         return $new;
     }
@@ -439,7 +439,7 @@ class Cookie implements CookieInterface
      */
     public function isExpired($time = null)
     {
-        $time = $time ?: new DateTimeImmutable('now', new DateTimezone('UTC'));
+        $time = $time ?: new DateTimeImmutable('now', new DateTimeZone('UTC'));
         if (!$this->expiresAt) {
             return false;
         }

+ 1 - 1
src/Http/Middleware/CsrfProtectionMiddleware.php

@@ -157,7 +157,7 @@ class CsrfProtectionMiddleware
      * @param string $token The token to add.
      * @param \Cake\Http\ServerRequest $request The request to validate against.
      * @param \Cake\Http\Response $response The response.
-     * @return @param \Cake\Http\Response $response Modified response.
+     * @return \Cake\Http\Response $response Modified response.
      */
     protected function _addTokenCookie($token, ServerRequest $request, Response $response)
     {

+ 1 - 1
src/Http/Server.php

@@ -109,7 +109,7 @@ class Server
     /**
      * Set the application.
      *
-     * @param Cake\Core\HttpApplicationInterface $app The application to set.
+     * @param \Cake\Core\HttpApplicationInterface $app The application to set.
      * @return $this
      */
     public function setApp(HttpApplicationInterface $app)

+ 1 - 1
src/I18n/I18n.php

@@ -168,7 +168,7 @@ class I18n
      * ```
      *
      * @param string $name The domain of the translation messages.
-     * @param callable|null $loader A callback function or callable class responsible for
+     * @param callable $loader A callback function or callable class responsible for
      *   constructing a translations package instance.
      * @param string|null $locale The locale for the translator.
      * @return void

+ 4 - 4
src/I18n/RelativeTimeFormatter.php

@@ -15,7 +15,7 @@
 namespace Cake\I18n;
 
 use Cake\Chronos\ChronosInterface;
-use DatetimeInterface;
+use DateTimeInterface;
 
 /**
  * Helper class for formatting relative dates & times.
@@ -91,7 +91,7 @@ class RelativeTimeFormatter
      * @return string Relative time string.
      * @see \Cake\I18n\Time::timeAgoInWords()
      */
-    public function timeAgoInWords(DatetimeInterface $time, array $options = [])
+    public function timeAgoInWords(DateTimeInterface $time, array $options = [])
     {
         $options = $this->_options($options, FrozenTime::class);
         if ($options['timezone'] && $time instanceof ChronosInterface) {
@@ -276,12 +276,12 @@ class RelativeTimeFormatter
     /**
      * Format a into a relative date string.
      *
-     * @param \DatetimeInterface $date The date to format.
+     * @param \DateTimeInterface $date The date to format.
      * @param array $options Array of options.
      * @return string Relative date string.
      * @see \Cake\I18n\Date::timeAgoInWords()
      */
-    public function dateAgoInWords(DatetimeInterface $date, array $options = [])
+    public function dateAgoInWords(DateTimeInterface $date, array $options = [])
     {
         $options = $this->_options($options, FrozenDate::class);
         if ($options['timezone'] && $date instanceof ChronosInterface) {

+ 3 - 3
src/Mailer/Email.php

@@ -33,7 +33,7 @@ use LogicException;
 use PDO;
 use RuntimeException;
 use Serializable;
-use SimpleXmlElement;
+use SimpleXMLElement;
 
 /**
  * CakePHP Email class.
@@ -2694,7 +2694,7 @@ class Email implements JsonSerializable, Serializable
      * It has certain limitations for viewVars that are good to know:
      *
      *    - ORM\Query executed and stored as resultset
-     *    - SimpleXmlElements stored as associative array
+     *    - SimpleXMLElements stored as associative array
      *    - Exceptions stored as strings
      *    - Resources, \Closure and \PDO are not supported.
      *
@@ -2784,7 +2784,7 @@ class Email implements JsonSerializable, Serializable
     {
         $array = $this->jsonSerialize();
         array_walk_recursive($array, function (&$item, $key) {
-            if ($item instanceof SimpleXmlElement) {
+            if ($item instanceof SimpleXMLElement) {
                 $item = json_decode(json_encode((array)$item), true);
             }
         });

+ 1 - 1
src/ORM/Association.php

@@ -1431,7 +1431,7 @@ abstract class Association
      * the saving operation to the target table.
      *
      * @param \Cake\Datasource\EntityInterface $entity the data to be saved
-     * @param array|\ArrayObject $options The options for saving associated data.
+     * @param array $options The options for saving associated data.
      * @return bool|\Cake\Datasource\EntityInterface false if $entity could not be saved, otherwise it returns
      * the saved entity
      * @see \Cake\ORM\Table::save()

+ 1 - 1
src/ORM/EagerLoadable.php

@@ -35,7 +35,7 @@ class EagerLoadable
     /**
      * A list of other associations to load from this level.
      *
-     * @var \Cake\Orm\EagerLoadable[]
+     * @var \Cake\ORM\EagerLoadable[]
      */
     protected $_associations = [];
 

+ 1 - 1
src/ORM/Query.php

@@ -424,7 +424,7 @@ class Query extends DatabaseQuery implements JsonSerializable, QueryInterface
      * Used to recursively add contained association column types to
      * the query.
      *
-     * @param \Cake\ORM\Table|\Cake\Datasource\RepositoryInterface $table The table instance to pluck associations from.
+     * @param \Cake\ORM\Table $table The table instance to pluck associations from.
      * @param \Cake\Database\TypeMap $typeMap The typemap to check for columns in.
      *   This typemap is indirectly mutated via Cake\ORM\Query::addDefaultTypes()
      * @param array $associations The nested tree of associations to walk.

+ 1 - 1
src/ORM/TableRegistry.php

@@ -97,7 +97,7 @@ class TableRegistry
     /**
      * Sets singleton instance of LocatorInterface implementation.
      *
-     * @param \Cake\ORM\Locator\LocatorInterface|null $tableLocator Instance of a locator to use.
+     * @param \Cake\ORM\Locator\LocatorInterface $tableLocator Instance of a locator to use.
      * @return void
      */
     public static function setTableLocator(LocatorInterface $tableLocator)

+ 1 - 1
src/Routing/RouteCollection.php

@@ -181,7 +181,7 @@ class RouteCollection
     /**
      * Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.
      *
-     * @param \Psr\Http\Messages\ServerRequestInterface $request The request to parse route data from.
+     * @param \Psr\Http\Message\ServerRequestInterface $request The request to parse route data from.
      * @return array An array of request parameters parsed from the URL.
      * @throws \Cake\Routing\Exception\MissingRouteException When a URL has no matching route.
      */

+ 2 - 2
src/Shell/CommandListShell.php

@@ -19,7 +19,7 @@ use Cake\Console\Shell;
 use Cake\Core\Configure;
 use Cake\Core\Plugin;
 use Cake\Utility\Inflector;
-use SimpleXmlElement;
+use SimpleXMLElement;
 
 /**
  * Shows a list of commands available from the console.
@@ -128,7 +128,7 @@ class CommandListShell extends Shell
     protected function _asXml($shellList)
     {
         $plugins = Plugin::loaded();
-        $shells = new SimpleXmlElement('<shells></shells>');
+        $shells = new SimpleXMLElement('<shells></shells>');
         foreach ($shellList as $plugin => $commands) {
             foreach ($commands as $command) {
                 $callable = $command;

+ 2 - 2
src/Shell/HelpShell.php

@@ -21,7 +21,7 @@ use Cake\Console\ConsoleOutput;
 use Cake\Console\Shell;
 use Cake\Shell\Task\CommandTask;
 use Cake\Utility\Inflector;
-use SimpleXmlElement;
+use SimpleXMLElement;
 
 /**
  * Print out command list
@@ -139,7 +139,7 @@ class HelpShell extends Shell implements CommandCollectionAwareInterface
      */
     protected function asXml($commands)
     {
-        $shells = new SimpleXmlElement('<shells></shells>');
+        $shells = new SimpleXMLElement('<shells></shells>');
         foreach ($commands as $name => $class) {
             $shell = $shells->addChild('shell');
             $shell->addAttribute('name', $name);

+ 1 - 1
src/Shell/OrmCacheShell.php

@@ -90,7 +90,7 @@ class OrmCacheShell extends Shell
     /**
      * Helper method to get the schema collection.
      *
-     * @return false|\Cake\Database\Schema\Collection|\Cake\Database\Schema\CachedCollection
+     * @return false|\Cake\Database\Schema\CachedCollection
      */
     protected function _getSchema()
     {

+ 2 - 2
src/TestSuite/Fixture/TestFixture.php

@@ -264,8 +264,8 @@ class TestFixture implements FixtureInterface, TableSchemaInterface, TableSchema
     /**
      * Gets/Sets the TableSchema instance used by this fixture.
      *
-     * @param \Cake\Database\Schema\TableSchema|\Cake\Database\Schema\TableSchemaInterface|null $schema The table to set.
-     * @return \Cake\Database\Schema\TableSchema|\Cake\Database\Schema\TableSchemaInterface|null
+     * @param \Cake\Database\Schema\TableSchema|null $schema The table to set.
+     * @return \Cake\Database\Schema\TableSchema|null
      * @deprecated 3.5.0 Use getTableSchema/setTableSchema instead.
      */
     public function schema(TableSchema $schema = null)

+ 2 - 1
src/TestSuite/TestCase.php

@@ -638,7 +638,7 @@ abstract class TestCase extends BaseTestCase
      * Mock a model, maintain fixtures and table association
      *
      * @param string $alias The model to get a mock for.
-     * @param mixed $methods The list of methods to mock
+     * @param array $methods The list of methods to mock
      * @param array $options The config data for the mock's constructor.
      * @throws \Cake\ORM\Exception\MissingTableClassException
      * @return \Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject
@@ -661,6 +661,7 @@ abstract class TestCase extends BaseTestCase
         $options += ['alias' => $baseClass, 'connection' => $connection];
         $options += TableRegistry::config($alias);
 
+        /* @var \Cake\ORM\Table $mock */
         $mock = $this->getMockBuilder($options['className'])
             ->setMethods($methods)
             ->setConstructorArgs([$options])

+ 1 - 0
src/Utility/Hash.php

@@ -160,6 +160,7 @@ class Hash
 
             foreach ($context[$_key] as $item) {
                 if (is_object($item) && method_exists($item, 'toArray')) {
+                    /* @var \Cake\Datasource\EntityInterface $item */
                     $item = $item->toArray();
                 }
                 foreach ((array)$item as $k => $v) {

+ 2 - 2
src/Utility/Security.php

@@ -152,8 +152,8 @@ class Security
      *
      * You can use this method to forcibly decide between mcrypt/openssl/custom implementations.
      *
-     * @param object|null $instance The crypto instance to use.
-     * @return object Crypto instance.
+     * @param \Cake\Utility\Crypto\OpenSsl|\Cake\Utility\Crypto\Mcrypt|null $instance The crypto instance to use.
+     * @return \Cake\Utility\Crypto\OpenSsl|\Cake\Utility\Crypto\Mcrypt Crypto instance.
      * @throws \InvalidArgumentException When no compatible crypto extension is available.
      */
     public static function engine($instance = null)

+ 2 - 2
src/Utility/Xml.php

@@ -97,7 +97,7 @@ class Xml
      * If using array as input, you can pass `options` from Xml::fromArray.
      *
      * @param string|array $input XML string, a path to a file, a URL or an array
-     * @param string|array $options The options to use
+     * @param array $options The options to use
      * @return \SimpleXMLElement|\DOMDocument SimpleXMLElement or DOMDocument
      * @throws \Cake\Utility\Exception\XmlException
      */
@@ -135,7 +135,7 @@ class Xml
      *
      * @param string $input The input to load.
      * @param array $options The options to use. See Xml::build()
-     * @return \SimpleXmlElement|\DOMDocument
+     * @return \SimpleXMLElement|\DOMDocument
      * @throws \Cake\Utility\Exception\XmlException
      */
     protected static function _loadXml($input, $options)

+ 1 - 1
src/Validation/Validation.php

@@ -527,7 +527,7 @@ class Validation
      * The list of what is considered to be boolean values, may be set via $booleanValues.
      *
      * @param bool|int|string $check Value to check.
-     * @param string $booleanValues List of valid boolean values, defaults to `[true, false, 0, 1, '0', '1']`.
+     * @param array $booleanValues List of valid boolean values, defaults to `[true, false, 0, 1, '0', '1']`.
      * @return bool Success.
      */
     public static function boolean($check, array $booleanValues = [])

+ 2 - 0
src/View/Form/EntityContext.php

@@ -156,6 +156,8 @@ class EntityContext implements ContextInterface
             is_array($entity) ||
             $entity instanceof Traversable
         );
+
+        /* @var \Cake\Datasource\RepositoryInterface $table */
         $alias = $this->_rootName = $table->getAlias();
         $this->_tables[$alias] = $table;
     }

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

@@ -150,7 +150,7 @@ class HtmlHelper extends Helper
      *
      * @param string $name Text for link
      * @param string|array|null $link URL for link (if empty it won't be a link)
-     * @param string|array $options Link attributes e.g. ['id' => 'selected']
+     * @param array $options Link attributes e.g. ['id' => 'selected']
      * @return $this
      * @see \Cake\View\Helper\HtmlHelper::link() for details on $options that can be used.
      * @link https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper