Browse Source

Merge pull request #9428 from cakephp/bugfix/typehints

Bugfix/typehints
José Lorenzo Rodríguez 9 years ago
parent
commit
47c7355f44

+ 1 - 1
src/Datasource/RepositoryInterface.php

@@ -88,7 +88,7 @@ interface RepositoryInterface
      * This method will *not* trigger beforeSave/afterSave events. If you need those
      * first load a collection of records and update them.
      *
-     * @param array $fields A hash of field => new value.
+     * @param string|array|callable|\Cake\Database\Expression\QueryExpression $fields A hash of field => new value.
      * @param mixed $conditions Conditions to be used, accepts anything Query::where()
      * can take.
      * @return int Count Returns the affected rows.

+ 1 - 1
src/Http/Client.php

@@ -124,7 +124,7 @@ class Client
 
     /**
      * Adapter for sending requests. Defaults to
-     * Cake\Http\Adapter\Stream
+     * Cake\Http\Client\Adapter\Stream
      *
      * @var \Cake\Http\Client\Adapter\Stream
      */

+ 4 - 3
src/Mailer/Email.php

@@ -1383,7 +1383,7 @@ class Email implements JsonSerializable, Serializable
      * @param string|array|null $message String with message or array with variables to be used in render
      * @param string|array $transportConfig String to use config from EmailConfig or array with configs
      * @param bool $send Send the email or just return the instance pre-configured
-     * @return \Cake\Mailer\Email Instance of Cake\Mailer\Email
+     * @return static Instance of Cake\Mailer\Email
      * @throws \InvalidArgumentException
      */
     public static function deliver($to = null, $subject = null, $message = null, $transportConfig = 'default', $send = true)
@@ -1393,6 +1393,7 @@ class Email implements JsonSerializable, Serializable
         if (is_array($transportConfig) && !isset($transportConfig['transport'])) {
             $transportConfig['transport'] = 'default';
         }
+        /* @var \Cake\Mailer\Email $instance */
         $instance = new $class($transportConfig);
         if ($to !== null) {
             $instance->to($to);
@@ -2032,7 +2033,7 @@ class Email implements JsonSerializable, Serializable
      * Configures an email instance object from serialized config.
      *
      * @param array $config Email configuration array.
-     * @return \Cake\Mailer\Email Configured email instance.
+     * @return $this Configured email instance.
      */
     public function createFromArray($config)
     {
@@ -2069,7 +2070,7 @@ class Email implements JsonSerializable, Serializable
      * Unserializes the Email object.
      *
      * @param string $data Serialized string.
-     * @return \Cake\Mailer\Email Configured email instance.
+     * @return static Configured email instance.
      */
     public function unserialize($data)
     {

+ 2 - 2
src/ORM/Association.php

@@ -607,7 +607,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\Database\Query $query The query to modify
+     * @param \Cake\Datasource\QueryInterface $query The query to modify
      * @param array $options Options array containing the `negateMatch` key.
      * @return void
      */
@@ -695,7 +695,7 @@ abstract class Association
      * Proxies the operation to the target table's exists method after
      * appending the default conditions for this association
      *
-     * @param array|callable|ExpressionInterface $conditions The conditions to use
+     * @param array|callable|\Cake\Database\ExpressionInterface $conditions The conditions to use
      * for checking if any record matches.
      * @see \Cake\ORM\Table::exists()
      * @return bool

+ 18 - 4
src/ORM/AssociationCollection.php

@@ -33,7 +33,7 @@ class AssociationCollection implements IteratorAggregate
     /**
      * Stored associations
      *
-     * @var array
+     * @var \Cake\ORM\Association[]
      */
     protected $_items = [];
 
@@ -270,6 +270,21 @@ class AssociationCollection implements IteratorAggregate
      */
     public function cascadeDelete(EntityInterface $entity, array $options)
     {
+        $noCascade = $this->_getNoCascadeItems($entity, $options);
+        foreach ($noCascade as $assoc) {
+            $assoc->cascadeDelete($entity, $options);
+        }
+    }
+
+    /**
+     * Returns items that have no cascade callback.
+     *
+     * @param \Cake\Datasource\EntityInterface $entity The entity to delete associations for.
+     * @param array $options The options used in the delete operation.
+     * @return \Cake\ORM\Association[]
+     */
+    protected function _getNoCascadeItems($entity, $options)
+    {
         $noCascade = [];
         foreach ($this->_items as $assoc) {
             if (!$assoc->cascadeCallbacks()) {
@@ -278,9 +293,8 @@ class AssociationCollection implements IteratorAggregate
             }
             $assoc->cascadeDelete($entity, $options);
         }
-        foreach ($noCascade as $assoc) {
-            $assoc->cascadeDelete($entity, $options);
-        }
+
+        return $noCascade;
     }
 
     /**

+ 3 - 1
src/ORM/Behavior.php

@@ -366,7 +366,9 @@ class Behavior implements EventListenerInterface
         $eventMethods = [];
         foreach ($events as $e => $binding) {
             if (is_array($binding) && isset($binding['callable'])) {
-                $binding = $binding['callable'];
+                /* @var string $callable */
+                $callable = $binding['callable'];
+                $binding = $callable;
             }
             $eventMethods[$binding] = true;
         }

+ 10 - 9
src/ORM/Behavior/TreeBehavior.php

@@ -56,7 +56,7 @@ class TreeBehavior extends Behavior
         'implementedFinders' => [
             'path' => 'findPath',
             'children' => 'findChildren',
-            'treeList' => 'findTreeList'
+            'treeList' => 'findTreeList',
         ],
         'implementedMethods' => [
             'childCount' => 'childCount',
@@ -65,14 +65,14 @@ class TreeBehavior extends Behavior
             'recover' => 'recover',
             'removeFromTree' => 'removeFromTree',
             'getLevel' => 'getLevel',
-            'formatTreeList' => 'formatTreeList'
+            'formatTreeList' => 'formatTreeList',
         ],
         'parent' => 'parent_id',
         'left' => 'lft',
         'right' => 'rght',
         'scope' => null,
         'level' => null,
-        'recoverOrder' => null
+        'recoverOrder' => null,
     ];
 
     /**
@@ -192,9 +192,10 @@ class TreeBehavior extends Behavior
         $children = $this->_table->find('children', [
             'for' => $primaryKeyValue,
             'fields' => [$this->_getPrimaryKey(), $config['parent'], $config['level']],
-            'order' => $config['left']
+            'order' => $config['left'],
         ]);
 
+        /* @var \Cake\ORM\Entity $node */
         foreach ($children as $node) {
             $parentIdValue = $node->get($config['parent']);
             $depth = $depths[$parentIdValue] + 1;
@@ -384,7 +385,7 @@ class TreeBehavior extends Behavior
         return $this->_scope($query)
             ->where([
                 "$left <=" => $node->get($config['left']),
-                "$right >=" => $node->get($config['right'])
+                "$right >=" => $node->get($config['right']),
             ])
             ->order([$left => 'ASC']);
     }
@@ -459,7 +460,7 @@ class TreeBehavior extends Behavior
         return $this->_scope($query)
             ->where([
                 "{$right} <" => $node->get($config['right']),
-                "{$left} >" => $node->get($config['left'])
+                "{$left} >" => $node->get($config['left']),
             ]);
     }
 
@@ -485,7 +486,7 @@ class TreeBehavior extends Behavior
         $results = $this->_scope($query)
             ->find('threaded', [
                 'parentField' => $this->config('parent'),
-                'order' => [$this->config('left') => 'ASC']
+                'order' => [$this->config('left') => 'ASC'],
             ]);
 
         return $this->formatTreeList($results, $options);
@@ -514,7 +515,7 @@ class TreeBehavior extends Behavior
             $options += [
                 'keyPath' => $this->_getPrimaryKey(),
                 'valuePath' => $this->_table->displayField(),
-                'spacer' => '_'
+                'spacer' => '_',
             ];
 
             return $results
@@ -993,7 +994,7 @@ class TreeBehavior extends Behavior
 
         $query = $this->_table->find('all')->where([
             $config['left'] . ' <' => $entity[$config['left']],
-            $config['right'] . ' >' => $entity[$config['right']]
+            $config['right'] . ' >' => $entity[$config['right']],
         ]);
 
         return $this->_scope($query)->count();

+ 1 - 1
src/ORM/EagerLoadable.php

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

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

@@ -168,7 +168,9 @@ class TableLocator implements LocatorInterface
             if (!empty($options['connectionName'])) {
                 $connectionName = $options['connectionName'];
             } else {
-                $connectionName = $options['className']::defaultConnectionName();
+                /* @var \Cake\ORM\Table $className */
+                $className = $options['className'];
+                $connectionName = $className::defaultConnectionName();
             }
             $options['connection'] = ConnectionManager::get($connectionName);
         }

+ 1 - 2
src/ORM/Query.php

@@ -15,7 +15,6 @@
 namespace Cake\ORM;
 
 use ArrayObject;
-use Cake\Collection\CollectionInterface;
 use Cake\Database\ExpressionInterface;
 use Cake\Database\Query as DatabaseQuery;
 use Cake\Database\TypedResultInterface;
@@ -157,7 +156,7 @@ class Query extends DatabaseQuery implements JsonSerializable, QueryInterface
     /**
      * Constructor
      *
-     * @param \Cake\Database\Connection $connection The connection object
+     * @param \Cake\Datasource\ConnectionInterface $connection The connection object
      * @param \Cake\ORM\Table $table The table this query is starting on
      */
     public function __construct($connection, $table)

+ 2 - 1
src/Routing/RouteBuilder.php

@@ -335,7 +335,8 @@ class RouteBuilder
         }
 
         $connectOptions = $options['connectOptions'];
-        $urlName = Inflector::{$options['inflect']}($name);
+        $method = $options['inflect'];
+        $urlName = Inflector::$method($name);
         $resourceMap = array_merge(static::$_resourceMap, $options['map']);
 
         $only = (array)$options['only'];

+ 8 - 6
src/Routing/RouteCollection.php

@@ -39,14 +39,14 @@ class RouteCollection
     /**
      * The routes connected to this collection.
      *
-     * @var array
+     * @var \Cake\Routing\Route\Route[]
      */
     protected $_routes = [];
 
     /**
      * The hash map of named routes that are in this collection.
      *
-     * @var array
+     * @var \Cake\Routing\Route\Route[]
      */
     protected $_named = [];
 
@@ -131,6 +131,7 @@ class RouteCollection
                 list($url, $queryParameters) = explode('?', $url, 2);
                 parse_str($queryParameters, $queryParameters);
             }
+            /* @var \Cake\Routing\Route\Route $route */
             foreach ($this->_paths[$path] as $route) {
                 $r = $route->parse($url, $method);
                 if ($r === false) {
@@ -170,7 +171,7 @@ class RouteCollection
             "${controller}:${action}",
             "${controller}:_action",
             "_controller:${action}",
-            "_controller:_action"
+            "_controller:_action",
         ];
 
         // No prefix, no plugin
@@ -202,7 +203,7 @@ class RouteCollection
                 "_prefix:${controller}:${action}",
                 "_prefix:${controller}:_action",
                 "_prefix:_controller:${action}",
-                "_prefix:_controller:_action"
+                "_prefix:_controller:_action",
             ];
         }
 
@@ -264,6 +265,7 @@ class RouteCollection
             if (empty($this->_routeTable[$name])) {
                 continue;
             }
+            /* @var \Cake\Routing\Route\Route $route */
             foreach ($this->_routeTable[$name] as $route) {
                 $match = $route->match($url, $context);
                 if ($match) {
@@ -277,7 +279,7 @@ class RouteCollection
     /**
      * Get all the connected routes as a flat list.
      *
-     * @return array
+     * @return \Cake\Routing\Route\Route[]
      */
     public function routes()
     {
@@ -287,7 +289,7 @@ class RouteCollection
     /**
      * Get the connected named routes.
      *
-     * @return array
+     * @return \Cake\Routing\Route\Route[]
      */
     public function named()
     {

+ 20 - 20
src/TestSuite/Fixture/FixtureManager.php

@@ -39,14 +39,14 @@ class FixtureManager
     /**
      * Holds the fixture classes that where instantiated
      *
-     * @var array
+     * @var \Cake\Datasource\FixtureInterface[]
      */
     protected $_loaded = [];
 
     /**
      * Holds the fixture classes that where instantiated indexed by class name
      *
-     * @var array
+     * @var \Cake\Datasource\FixtureInterface[]
      */
     protected $_fixtureMap = [];
 
@@ -219,7 +219,7 @@ class FixtureManager
     /**
      * Runs the drop and create commands on the fixtures if necessary.
      *
-     * @param \Cake\TestSuite\Fixture\TestFixture $fixture the fixture object to create
+     * @param \Cake\Datasource\FixtureInterface $fixture the fixture object to create
      * @param \Cake\Database\Connection $db The Connection object instance to use
      * @param array $sources The existing tables in the datasource.
      * @param bool $drop whether drop the fixture if it is already created or not
@@ -429,27 +429,27 @@ class FixtureManager
      */
     public function loadSingle($name, $db = null, $dropTables = true)
     {
-        if (isset($this->_fixtureMap[$name])) {
-            $fixture = $this->_fixtureMap[$name];
-            if (!$db) {
-                $db = ConnectionManager::get($fixture->connection());
-            }
+        if (!isset($this->_fixtureMap[$name])) {
+            throw new UnexpectedValueException(sprintf('Referenced fixture class %s not found', $name));
+        }
 
-            if (!$this->isFixtureSetup($db->configName(), $fixture)) {
-                $sources = $db->schemaCollection()->listTables();
-                $this->_setupTable($fixture, $db, $sources, $dropTables);
-            }
+        $fixture = $this->_fixtureMap[$name];
+        if (!$db) {
+            $db = ConnectionManager::get($fixture->connection());
+        }
 
-            if (!$dropTables) {
-                $fixture->dropConstraints($db);
-                $fixture->truncate($db);
-            }
+        if (!$this->isFixtureSetup($db->configName(), $fixture)) {
+            $sources = $db->schemaCollection()->listTables();
+            $this->_setupTable($fixture, $db, $sources, $dropTables);
+        }
 
-            $fixture->createConstraints($db);
-            $fixture->insert($db);
-        } else {
-            throw new UnexpectedValueException(sprintf('Referenced fixture class %s not found', $name));
+        if (!$dropTables) {
+            $fixture->dropConstraints($db);
+            $fixture->truncate($db);
         }
+
+        $fixture->createConstraints($db);
+        $fixture->insert($db);
     }
 
     /**

+ 1 - 1
src/TestSuite/TestCase.php

@@ -43,7 +43,7 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
      * By default, all fixtures attached to this class will be truncated and reloaded after each test.
      * Set this to false to handle manually
      *
-     * @var array
+     * @var bool
      */
     public $autoFixtures = true;
 

+ 1 - 0
src/View/Widget/DateTimeWidget.php

@@ -259,6 +259,7 @@ class DateTimeWidget implements WidgetInterface
 
                 $date = new DateTime();
             } else {
+                /* @var \DateTime $value */
                 $date = clone $value;
             }
         } catch (Exception $e) {