From 6cf9f114c743303b14f2a827545a05138e312c7e Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 7 Sep 2016 15:30:33 +0200 Subject: [PATCH] Fix up yellow warnings in IDE by proper doc block typehinting. --- src/Datasource/RepositoryInterface.php | 2 +- src/Mailer/Email.php | 7 +++-- src/ORM/Association.php | 4 +-- src/ORM/AssociationCollection.php | 22 ++++++++++--- src/ORM/Behavior.php | 4 ++- src/ORM/Behavior/TreeBehavior.php | 19 +++++------ src/ORM/EagerLoadable.php | 2 +- src/ORM/Locator/TableLocator.php | 4 ++- src/ORM/Query.php | 5 ++- src/Routing/RouteBuilder.php | 3 +- src/Routing/RouteCollection.php | 14 +++++---- src/TestSuite/Fixture/FixtureManager.php | 40 ++++++++++++------------ src/TestSuite/TestCase.php | 2 +- 13 files changed, 75 insertions(+), 53 deletions(-) diff --git a/src/Datasource/RepositoryInterface.php b/src/Datasource/RepositoryInterface.php index 0da99c9c76c..fdbb12133cc 100644 --- a/src/Datasource/RepositoryInterface.php +++ b/src/Datasource/RepositoryInterface.php @@ -88,7 +88,7 @@ public function query(); * 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. diff --git a/src/Mailer/Email.php b/src/Mailer/Email.php index 02dfec1519c..dd0dc28566d 100644 --- a/src/Mailer/Email.php +++ b/src/Mailer/Email.php @@ -1383,7 +1383,7 @@ protected function _logDelivery($contents) * @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 @@ public static function deliver($to = null, $subject = null, $message = null, $tr 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 @@ protected function _checkViewVars(&$item, $key) * 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 @@ public function serialize() * 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) { diff --git a/src/ORM/Association.php b/src/ORM/Association.php index f6c1b9cf812..e24210e37e0 100644 --- a/src/ORM/Association.php +++ b/src/ORM/Association.php @@ -607,7 +607,7 @@ public function attachTo(Query $query, array $options = []) * 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 @@ public function find($type = null, array $options = []) * 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 diff --git a/src/ORM/AssociationCollection.php b/src/ORM/AssociationCollection.php index 3a6d521fc59..cae9a360bb1 100644 --- a/src/ORM/AssociationCollection.php +++ b/src/ORM/AssociationCollection.php @@ -33,7 +33,7 @@ class AssociationCollection implements IteratorAggregate /** * Stored associations * - * @var array + * @var \Cake\ORM\Association[] */ protected $_items = []; @@ -269,6 +269,21 @@ protected function _save($association, $entity, $nested, $options) * @return void */ 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) { @@ -278,9 +293,8 @@ public function cascadeDelete(EntityInterface $entity, array $options) } $assoc->cascadeDelete($entity, $options); } - foreach ($noCascade as $assoc) { - $assoc->cascadeDelete($entity, $options); - } + + return $noCascade; } /** diff --git a/src/ORM/Behavior.php b/src/ORM/Behavior.php index 5a835da58b3..3aebe1bfe4d 100644 --- a/src/ORM/Behavior.php +++ b/src/ORM/Behavior.php @@ -366,7 +366,9 @@ protected function _reflectionCache() $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; } diff --git a/src/ORM/Behavior/TreeBehavior.php b/src/ORM/Behavior/TreeBehavior.php index 4726a55838c..ec15d9fe2fa 100644 --- a/src/ORM/Behavior/TreeBehavior.php +++ b/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 @@ protected function _setChildrenLevel($entity) $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 @@ function ($field) { 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 @@ function ($field) { return $this->_scope($query) ->where([ "{$right} <" => $node->get($config['right']), - "{$left} >" => $node->get($config['left']) + "{$left} >" => $node->get($config['left']), ]); } @@ -485,7 +486,7 @@ public function findTreeList(Query $query, array $options) $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 @@ public function formatTreeList(Query $query, array $options = []) $options += [ 'keyPath' => $this->_getPrimaryKey(), 'valuePath' => $this->_table->displayField(), - 'spacer' => '_' + 'spacer' => '_', ]; return $results @@ -993,7 +994,7 @@ public function getLevel($entity) $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(); diff --git a/src/ORM/EagerLoadable.php b/src/ORM/EagerLoadable.php index 2e62f3a2741..c009d7ef797 100644 --- a/src/ORM/EagerLoadable.php +++ b/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 = []; diff --git a/src/ORM/Locator/TableLocator.php b/src/ORM/Locator/TableLocator.php index 08c90a56193..8d511f299bb 100644 --- a/src/ORM/Locator/TableLocator.php +++ b/src/ORM/Locator/TableLocator.php @@ -168,7 +168,9 @@ public function get($alias, array $options = []) 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); } diff --git a/src/ORM/Query.php b/src/ORM/Query.php index 17f0f9db4dc..2ce69ce5c79 100644 --- a/src/ORM/Query.php +++ b/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) @@ -203,7 +202,7 @@ public function select($fields = [], $overwrite = false) * * This method returns the same query object for chaining. * - * @param \Cake\ORM\Table $table The table to pull types from + * @param \Cake\Datasource\RepositoryInterface $table The table to pull types from * @return $this */ public function addDefaultTypes(Table $table) diff --git a/src/Routing/RouteBuilder.php b/src/Routing/RouteBuilder.php index 8d72f986928..f512ec89da3 100644 --- a/src/Routing/RouteBuilder.php +++ b/src/Routing/RouteBuilder.php @@ -335,7 +335,8 @@ public function resources($name, $options = [], $callback = null) } $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']; diff --git a/src/Routing/RouteCollection.php b/src/Routing/RouteCollection.php index ae81efc53f2..96e48122a89 100644 --- a/src/Routing/RouteCollection.php +++ b/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 @@ public function parse($url, $method = '') 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 @@ protected function _getNames($url) "${controller}:${action}", "${controller}:_action", "_controller:${action}", - "_controller:_action" + "_controller:_action", ]; // No prefix, no plugin @@ -202,7 +203,7 @@ protected function _getNames($url) "_prefix:${controller}:${action}", "_prefix:${controller}:_action", "_prefix:_controller:${action}", - "_prefix:_controller:_action" + "_prefix:_controller:_action", ]; } @@ -264,6 +265,7 @@ public function match($url, $context) 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 @@ public function match($url, $context) /** * Get all the connected routes as a flat list. * - * @return array + * @return \Cake\Routing\Route\Route[] */ public function routes() { @@ -287,7 +289,7 @@ public function routes() /** * Get the connected named routes. * - * @return array + * @return \Cake\Routing\Route\Route[] */ public function named() { diff --git a/src/TestSuite/Fixture/FixtureManager.php b/src/TestSuite/Fixture/FixtureManager.php index cc4b54702b9..3cffac7048c 100644 --- a/src/TestSuite/Fixture/FixtureManager.php +++ b/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 @@ protected function _loadFixtures($test) /** * 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 @@ public function unload($test) */ 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); } /** diff --git a/src/TestSuite/TestCase.php b/src/TestSuite/TestCase.php index d47e4834488..0ea06fdbc4b 100644 --- a/src/TestSuite/TestCase.php +++ b/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;