Browse Source

Fix some errors reported by phpstan level 2.

ADmad 9 years ago
parent
commit
68d2fcb83f

+ 19 - 19
phpstan.neon

@@ -1,23 +1,23 @@
 parameters:
-	autoload_files:
-		- %rootDir%/../../../src/basics.php
-	ignoreErrors:
-		- '#Function wincache_ucache_[a-zA-Z0-9_]+ not found#'
-		- '#Function xcache_[a-zA-Z0-9_]+ not found#'
-		- '#Function fastcgi_[a-zA-Z0-9_]+ not found#'
-		- '#Cake\\Database\\Type\\[a-zA-Z0-9_]+Type::__construct\(\) does not call parent constructor from Cake\\Database\\Type#'
-		- '#Constructor of class Cake\\[a-zA-Z0-9_\\]+ has an unused parameter#'
-		- '#Call to an undefined method Cake\\Console\\Shell::main\(\)#'
-		- '#Access to undefined constant Memcached::OPT_CLIENT_MODE#'
-		- '#Access to undefined constant Memcached::DYNAMIC_CLIENT_MODE#'
-		- '#Access to undefined constant PDO::SQLSRV_ATTR_ENCODING#'
-		- '#Access to undefined constant PDO::SQLSRV_ENCODING_BINARY#'
-		- '#Access to an undefined property Cake\\Http\\Client\\Message::\$headers#'
-		- '#Access to an undefined property Cake\\[a-zA-Z0-9_\\]+::\$_validViewOptions#'
-		- '#Access to an undefined property Cake\\Database\\Driver::\$_connection#'
-	earlyTerminatingMethodCalls:
-		Cake\Shell\Shell:
-			- abort
+    autoload_files:
+        - %rootDir%/../../../src/basics.php
+    ignoreErrors:
+        - '#Function wincache_ucache_[a-zA-Z0-9_]+ not found#'
+        - '#Function xcache_[a-zA-Z0-9_]+ not found#'
+        - '#Function fastcgi_[a-zA-Z0-9_]+ not found#'
+        - '#Cake\\Database\\Type\\[a-zA-Z0-9_]+Type::__construct\(\) does not call parent constructor from Cake\\Database\\Type#'
+        - '#Constructor of class Cake\\[a-zA-Z0-9_\\]+ has an unused parameter#'
+        - '#Call to an undefined method Cake\\Console\\Shell::main\(\)#'
+        - '#Access to undefined constant Memcached::OPT_CLIENT_MODE#'
+        - '#Access to undefined constant Memcached::DYNAMIC_CLIENT_MODE#'
+        - '#Access to undefined constant PDO::SQLSRV_ATTR_ENCODING#'
+        - '#Access to undefined constant PDO::SQLSRV_ENCODING_BINARY#'
+        - '#Access to an undefined property Cake\\Http\\Client\\Message::\$headers#'
+        - '#Access to an undefined property Cake\\[a-zA-Z0-9_\\]+::\$_validViewOptions#'
+        - '#Access to an undefined property Cake\\Database\\Driver::\$_connection#'
+    earlyTerminatingMethodCalls:
+        Cake\Shell\Shell:
+            - abort
 
 services:
     -

+ 1 - 1
src/Console/ConsoleOptionParser.php

@@ -818,7 +818,7 @@ class ConsoleOptionParser
             $value = $option->defaultValue();
         }
         if ($option->validChoice($value)) {
-            if ($option->acceptsMultiple($value)) {
+            if ($option->acceptsMultiple()) {
                 $params[$name][] = $value;
             } else {
                 $params[$name] = $value;

+ 1 - 1
src/ORM/Association.php

@@ -945,7 +945,7 @@ abstract class Association
      * Conditionally adds a condition to the passed Query that will make it find
      * records where there is no match with this association.
      *
-     * @param \Cake\Datasource\QueryInterface $query The query to modify
+     * @param \Cake\ORM\Query $query The query to modify
      * @param array $options Options array containing the `negateMatch` key.
      * @return void
      */

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

@@ -599,7 +599,7 @@ class BelongsToMany extends Association
         $table = $this->junction();
         $hasMany = $this->getSource()->association($table->getAlias());
         if ($this->_cascadeCallbacks) {
-            foreach ($hasMany->find('all')->where($conditions)->toList() as $related) {
+            foreach ($hasMany->find('all')->where($conditions)->all()->toList() as $related) {
                 $table->delete($related, $options);
             }
 

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

@@ -46,7 +46,7 @@ class DependentDeleteHelper
         $conditions = array_combine($foreignKey, $entity->extract($bindingKey));
 
         if ($association->getCascadeCallbacks()) {
-            foreach ($association->find()->where($conditions)->toList() as $related) {
+            foreach ($association->find()->where($conditions)->all()->toList() as $related) {
                 $table->delete($related, $options);
             }
 

+ 3 - 2
src/ORM/Behavior/CounterCacheBehavior.php

@@ -18,6 +18,7 @@ use Cake\Datasource\EntityInterface;
 use Cake\Event\Event;
 use Cake\ORM\Association;
 use Cake\ORM\Behavior;
+use Cake\ORM\Entity;
 
 /**
  * CounterCache behavior
@@ -198,12 +199,12 @@ class CounterCacheBehavior extends Behavior
      * Updates counter cache for a single association
      *
      * @param \Cake\Event\Event $event Event instance.
-     * @param \Cake\Datasource\EntityInterface $entity Entity
+     * @param \Cake\ORM\Entity $entity Entity
      * @param \Cake\ORM\Association $assoc The association object
      * @param array $settings The settings for for counter cache for this association
      * @return void
      */
-    protected function _processAssociation(Event $event, EntityInterface $entity, Association $assoc, array $settings)
+    protected function _processAssociation(Event $event, Entity $entity, Association $assoc, array $settings)
     {
         $foreignKeys = (array)$assoc->getForeignKey();
         $primaryKeys = (array)$assoc->getBindingKey();

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

@@ -328,6 +328,7 @@ class TranslateBehavior extends Behavior implements PropertyMarshalInterface
                 'model' => $model
             ])
             ->enableBufferedResults(false)
+            ->all()
             ->indexBy('field');
 
         $modified = [];
@@ -704,6 +705,6 @@ class TranslateBehavior extends Behavior implements PropertyMarshalInterface
             $query->unionAll($q);
         }
 
-        return $query->combine('num', 'id')->toArray();
+        return $query->all()->combine('num', 'id')->toArray();
     }
 }

+ 7 - 6
src/ORM/Marshaller.php

@@ -20,6 +20,7 @@ use Cake\Database\Expression\TupleComparison;
 use Cake\Database\Type;
 use Cake\Datasource\EntityInterface;
 use Cake\Datasource\InvalidPropertyInterface;
+use Cake\ORM\Association\BelongsToMany;
 use RuntimeException;
 
 /**
@@ -158,7 +159,7 @@ class Marshaller
      *
      * @param array $data The data to hydrate.
      * @param array $options List of options
-     * @return \Cake\Datasource\EntityInterface
+     * @return \Cake\ORM\Entity
      * @see \Cake\ORM\Table::newEntity()
      * @see \Cake\ORM\Entity::$_accessible
      */
@@ -168,7 +169,7 @@ class Marshaller
 
         $primaryKey = (array)$this->_table->getPrimaryKey();
         $entityClass = $this->_table->getEntityClass();
-        /* @var \Cake\Datasource\EntityInterface $entity */
+        /* @var \Cake\ORM\Entity $entity */
         $entity = new $entityClass();
         $entity->setSource($this->_table->getRegistryAlias());
 
@@ -352,12 +353,12 @@ class Marshaller
      * Builds the related entities and handles the special casing
      * for junction table entities.
      *
-     * @param \Cake\ORM\Association $assoc The association to marshal.
+     * @param \Cake\ORM\BelongsToMany $assoc The association to marshal.
      * @param array $data The data to convert into entities.
      * @param array $options List of options.
      * @return array An array of built entities.
      */
-    protected function _belongsToMany(Association $assoc, array $data, $options = [])
+    protected function _belongsToMany(BelongsToMany $assoc, array $data, $options = [])
     {
         $associated = isset($options['associated']) ? $options['associated'] : [];
         $forceNew = isset($options['forceNew']) ? $options['forceNew'] : false;
@@ -379,7 +380,7 @@ class Marshaller
                 if (count($keys) === $primaryCount) {
                     $rowConditions = [];
                     foreach ($keys as $key => $value) {
-                        $rowConditions[][$target->aliasfield($key)] = $value;
+                        $rowConditions[][$target->aliasField($key)] = $value;
                     }
 
                     if ($forceNew && !$target->exists($rowConditions)) {
@@ -761,7 +762,7 @@ class Marshaller
      * Merge the special _joinData property into the entity set.
      *
      * @param \Cake\Datasource\EntityInterface $original The original entity
-     * @param \Cake\ORM\Association $assoc The association to marshall
+     * @param \Cake\ORM\Association\BelongsToMany $assoc The association to marshall
      * @param array $value The data to hydrate
      * @param array $options List of options.
      * @return array An array of entities

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

@@ -35,7 +35,7 @@ class ExistsIn
     /**
      * The repository where the field will be looked for
      *
-     * @var array
+     * @var \Cake\Datasource\RepositoryInterface
      */
     protected $_repository;