Skip to content

Commit

Permalink
Fix up yellow warnings in IDE by proper doc block typehinting.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark authored and Mark S committed Sep 7, 2016
1 parent 369c721 commit 6cf9f11
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/Datasource/RepositoryInterface.php
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions src/Mailer/Email.php
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Association.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions src/ORM/AssociationCollection.php
Expand Up @@ -33,7 +33,7 @@ class AssociationCollection implements IteratorAggregate
/**
* Stored associations
*
* @var array
* @var \Cake\ORM\Association[]
*/
protected $_items = [];

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/ORM/Behavior.php
Expand Up @@ -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;
}
Expand Down
19 changes: 10 additions & 9 deletions src/ORM/Behavior/TreeBehavior.php
Expand Up @@ -56,7 +56,7 @@ class TreeBehavior extends Behavior
'implementedFinders' => [
'path' => 'findPath',
'children' => 'findChildren',
'treeList' => 'findTreeList'
'treeList' => 'findTreeList',
],
'implementedMethods' => [
'childCount' => 'childCount',
Expand All @@ -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,
];

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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']),
]);
}

Expand All @@ -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);
Expand Down Expand Up @@ -514,7 +515,7 @@ public function formatTreeList(Query $query, array $options = [])
$options += [
'keyPath' => $this->_getPrimaryKey(),
'valuePath' => $this->_table->displayField(),
'spacer' => '_'
'spacer' => '_',
];

return $results
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/EagerLoadable.php
Expand Up @@ -35,7 +35,7 @@ class EagerLoadable
/**
* A list of other associations to load from this level.
*
* @var array
* @var \Cake\Orm\EagerLoadable[]
*/
protected $_associations = [];

Expand Down
4 changes: 3 additions & 1 deletion src/ORM/Locator/TableLocator.php
Expand Up @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions src/ORM/Query.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Routing/RouteBuilder.php
Expand Up @@ -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'];
Expand Down
14 changes: 8 additions & 6 deletions src/Routing/RouteCollection.php
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -170,7 +171,7 @@ protected function _getNames($url)
"${controller}:${action}",
"${controller}:_action",
"_controller:${action}",
"_controller:_action"
"_controller:_action",
];

// No prefix, no plugin
Expand Down Expand Up @@ -202,7 +203,7 @@ protected function _getNames($url)
"_prefix:${controller}:${action}",
"_prefix:${controller}:_action",
"_prefix:_controller:${action}",
"_prefix:_controller:_action"
"_prefix:_controller:_action",
];
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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()
{
Expand All @@ -287,7 +289,7 @@ public function routes()
/**
* Get the connected named routes.
*
* @return array
* @return \Cake\Routing\Route\Route[]
*/
public function named()
{
Expand Down
40 changes: 20 additions & 20 deletions src/TestSuite/Fixture/FixtureManager.php
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 6cf9f11

Please sign in to comment.