ソースを参照

More phpstan related fixes.

ADmad 8 年 前
コミット
bca167d7c7

+ 1 - 0
phpstan.neon

@@ -22,6 +22,7 @@ parameters:
         - '#Call to an undefined method Traversable::getArrayCopy().#'
         - '#Variable \$config in isset\(\) is never defined#'
         - '#Call to static method id\(\) on an unknown class PHPUnit_Runner_Version#'
+        - '#Call to an undefined method DateTimeInterface::i18nFormat\(\)#'
     earlyTerminatingMethodCalls:
         Cake\Shell\Shell:
             - abort

+ 1 - 1
src/Core/ObjectRegistry.php

@@ -117,6 +117,7 @@ abstract class ObjectRegistry implements Countable, IteratorAggregate
      */
     protected function _checkDuplicate($name, $config)
     {
+        /** @var \Cake\Core\InstanceConfigTrait $existing */
         $existing = $this->_loaded[$name];
         $msg = sprintf('The "%s" alias has already been loaded', $name);
         $hasConfig = method_exists($existing, 'config');
@@ -126,7 +127,6 @@ abstract class ObjectRegistry implements Countable, IteratorAggregate
         if (empty($config)) {
             return;
         }
-        /** @var \Cake\Core\InstanceConfigTrait $existing */
         $existingConfig = $existing->getConfig();
         unset($config['enabled'], $existingConfig['enabled']);
 

+ 0 - 2
src/I18n/RelativeTimeFormatter.php

@@ -115,7 +115,6 @@ class RelativeTimeFormatter
         }
 
         if ($diff > abs($now - (new FrozenTime($options['end']))->format('U'))) {
-            /** @var \Cake\I18n\DateFormatTrait $time */
             return sprintf($options['absoluteString'], $time->i18nFormat($options['format']));
         }
 
@@ -306,7 +305,6 @@ class RelativeTimeFormatter
         }
 
         if ($diff > abs($now - (new FrozenDate($options['end']))->format('U'))) {
-            /** @var \Cake\I18n\DateFormatTrait $time */
             return sprintf($options['absoluteString'], $date->i18nFormat($options['format']));
         }
 

+ 6 - 3
src/ORM/Marshaller.php

@@ -240,19 +240,22 @@ class Marshaller
         if (!$options['validate']) {
             return [];
         }
+
+        $validator = null;
         if ($options['validate'] === true) {
-            $options['validate'] = $this->_table->getValidator();
+            $validator = $this->_table->getValidator();
         }
         if (is_string($options['validate'])) {
-            $options['validate'] = $this->_table->getValidator($options['validate']);
+            $validator = $this->_table->getValidator($options['validate']);
         }
+        $options['validate'] = $validator;
         if (!is_object($options['validate'])) {
             throw new RuntimeException(
                 sprintf('validate must be a boolean, a string or an object. Got %s.', gettype($options['validate']))
             );
         }
 
-        return $options['validate']->errors($data, $isNew);
+        return $validator->errors($data, $isNew);
     }
 
     /**

+ 2 - 2
src/ORM/Table.php

@@ -170,7 +170,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     /**
      * Connection instance
      *
-     * @var \Cake\Database\Connection|\Cake\Datasource\ConnectionInterface
+     * @var \Cake\Database\Connection
      */
     protected $_connection;
 
@@ -495,7 +495,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     /**
      * Returns the connection instance.
      *
-     * @return \Cake\Database\Connection|\Cake\Datasource\ConnectionInterface
+     * @return \Cake\Database\Connection
      */
     public function getConnection()
     {

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

@@ -79,7 +79,7 @@ class TestFixture implements FixtureInterface, TableSchemaInterface, TableSchema
     /**
      * The schema for this fixture.
      *
-     * @var \Cake\Database\Schema\TableSchema|\Cake\Database\Schema\TableSchemaInterface
+     * @var \Cake\Database\Schema\TableSchema
      */
     protected $_schema;
 

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

@@ -17,6 +17,7 @@ namespace Cake\View\Form;
 use ArrayAccess;
 use Cake\Collection\Collection;
 use Cake\Datasource\EntityInterface;
+use Cake\Datasource\RepositoryInterface;
 use Cake\Http\ServerRequest;
 use Cake\ORM\TableRegistry;
 use Cake\Utility\Inflector;
@@ -147,7 +148,7 @@ class EntityContext implements ContextInterface
             $table = TableRegistry::get($table);
         }
 
-        if (!is_object($table)) {
+        if (!($table instanceof RepositoryInterface)) {
             throw new RuntimeException(
                 'Unable to find table class for current entity'
             );
@@ -157,7 +158,6 @@ class EntityContext implements ContextInterface
             $entity instanceof Traversable
         );
 
-        /** @var \Cake\Datasource\RepositoryInterface $table */
         $alias = $this->_rootName = $table->getAlias();
         $this->_tables[$alias] = $table;
     }