From 5f3a304ab31e940c7667f84e61a88492f96c1196 Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 19 Mar 2018 02:50:14 +0530 Subject: [PATCH] Fix errors reported by phpstan. --- src/Console/CommandRunner.php | 4 ++- src/Core/Plugin.php | 2 +- src/Core/PluginCollection.php | 4 ++- src/Database/Statement/StatementDecorator.php | 2 +- src/Filesystem/Folder.php | 2 +- src/Http/Client.php | 2 +- src/Http/Client/Response.php | 2 +- src/Http/Server.php | 4 ++- src/Http/ServerRequest.php | 3 +-- src/ORM/Association.php | 2 +- src/ORM/Table.php | 25 +++++++++++++++---- src/Validation/ValidationSet.php | 2 +- src/View/Helper.php | 1 + src/View/Helper/UrlHelper.php | 6 ++++- src/View/ViewBuilder.php | 8 +++--- 15 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/Console/CommandRunner.php b/src/Console/CommandRunner.php index de66afbd3f5..2b33bf49143 100644 --- a/src/Console/CommandRunner.php +++ b/src/Console/CommandRunner.php @@ -257,7 +257,9 @@ public function eventManager(EventManager $events = null) public function setEventManager(EventManager $events) { if ($this->app instanceof PluginApplicationInterface) { - return $this->app->setEventManager($events); + $this->app->setEventManager($events); + + return $this; } throw new InvalidArgumentException('Cannot set the event manager, the application does not support events.'); diff --git a/src/Core/Plugin.php b/src/Core/Plugin.php index d25b98c897a..e76fc40cc70 100644 --- a/src/Core/Plugin.php +++ b/src/Core/Plugin.php @@ -30,7 +30,7 @@ class Plugin /** * Holds a list of all loaded plugins and their configuration * - * @var \Cake\Core\PluginCollection + * @var \Cake\Core\PluginCollection|null */ protected static $plugins; diff --git a/src/Core/PluginCollection.php b/src/Core/PluginCollection.php index 1fcb53e5066..f7690101642 100644 --- a/src/Core/PluginCollection.php +++ b/src/Core/PluginCollection.php @@ -48,7 +48,9 @@ class PluginCollection implements Iterator, Countable protected $names = []; /** - * @var null|string + * Iterator position. + * + * @var int */ protected $position = 0; diff --git a/src/Database/Statement/StatementDecorator.php b/src/Database/Statement/StatementDecorator.php index 2d9d6508ce9..c1a75efc1c1 100644 --- a/src/Database/Statement/StatementDecorator.php +++ b/src/Database/Statement/StatementDecorator.php @@ -300,7 +300,7 @@ public function bind($params, $types) * * @param string|null $table table name or sequence to get last insert value from * @param string|null $column the name of the column representing the primary key - * @return string + * @return string|int */ public function lastInsertId($table = null, $column = null) { diff --git a/src/Filesystem/Folder.php b/src/Filesystem/Folder.php index 89363b1755e..9b59a1e8f0e 100644 --- a/src/Filesystem/Folder.php +++ b/src/Filesystem/Folder.php @@ -923,7 +923,7 @@ public function errors($reset = true) * Get the real path (taking ".." and such into account) * * @param string $path Path to resolve - * @return string|bool The resolved path + * @return string|false The resolved path */ public function realpath($path) { diff --git a/src/Http/Client.php b/src/Http/Client.php index c4fef5c734c..16dc8a23ff4 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -122,7 +122,7 @@ class Client * Cookies are indexed by the cookie's domain or * request host name. * - * @var \Cake\Http\Client\CookieCollection + * @var \Cake\Http\Cookie\CookieCollection */ protected $_cookies; diff --git a/src/Http/Client/Response.php b/src/Http/Client/Response.php index 975f855194f..9e896c39be2 100644 --- a/src/Http/Client/Response.php +++ b/src/Http/Client/Response.php @@ -440,7 +440,7 @@ public function getCookieCollection() * Get the value of a single cookie. * * @param string $name The name of the cookie value. - * @return string|null Either the cookie's value or null when the cookie is undefined. + * @return string|array|null Either the cookie's value or null when the cookie is undefined. */ public function getCookie($name) { diff --git a/src/Http/Server.php b/src/Http/Server.php index 1ed17f12a7f..5e2691b03fb 100644 --- a/src/Http/Server.php +++ b/src/Http/Server.php @@ -210,7 +210,9 @@ public function eventManager(EventManager $events = null) public function setEventManager(EventManager $events) { if ($this->app instanceof PluginApplicationInterface) { - return $this->app->setEventManager($events); + $this->app->setEventManager($events); + + return $this; } throw new InvalidArgumentException('Cannot set the event manager, the application does not support events.'); diff --git a/src/Http/ServerRequest.php b/src/Http/ServerRequest.php index fed4264e3b2..6bd643e996a 100644 --- a/src/Http/ServerRequest.php +++ b/src/Http/ServerRequest.php @@ -777,8 +777,7 @@ public function clearDetectorCache() /** * Worker for the public is() function * - * @param string|array $type The type of request you want to check. If an array - * this method will return true if the request matches any type. + * @param string $type The type of request you want to check. * @param array $args Array of custom detector arguments. * @return bool Whether or not the request is the type you are checking. */ diff --git a/src/ORM/Association.php b/src/ORM/Association.php index dd94f287568..eda333f5460 100644 --- a/src/ORM/Association.php +++ b/src/ORM/Association.php @@ -502,7 +502,7 @@ public function getConditions() * @deprecated 3.4.0 Use setConditions()/getConditions() instead. * @param array|null $conditions list of conditions to be used * @see \Cake\Database\Query::where() for examples on the format of the array - * @return array + * @return array|callable */ public function conditions($conditions = null) { diff --git a/src/ORM/Table.php b/src/ORM/Table.php index ce75881f662..98771ccc3b0 100644 --- a/src/ORM/Table.php +++ b/src/ORM/Table.php @@ -749,7 +749,9 @@ public function displayField($key = null) 'Use setDisplayField()/getDisplayField() instead.' ); if ($key !== null) { - return $this->setDisplayField($key); + $this->setDisplayField($key); + + return $key; } return $this->getDisplayField(); @@ -931,6 +933,7 @@ public function behaviors() */ public function getBehavior($name) { + /** @var \Cake\ORM\Behavior $behavior */ $behavior = $this->_behaviors->get($name); if ($behavior === null) { throw new InvalidArgumentException(sprintf( @@ -1126,7 +1129,10 @@ public function belongsTo($associated, array $options = []) { $options += ['sourceTable' => $this]; - return $this->_associations->load(BelongsTo::class, $associated, $options); + /** @var \Cake\ORM\Association\BelongsTo $association */ + $association = $this->_associations->load(BelongsTo::class, $associated, $options); + + return $association; } /** @@ -1169,7 +1175,10 @@ public function hasOne($associated, array $options = []) { $options += ['sourceTable' => $this]; - return $this->_associations->load(HasOne::class, $associated, $options); + /** @var \Cake\ORM\Association\HasOne $association */ + $association = $this->_associations->load(HasOne::class, $associated, $options); + + return $association; } /** @@ -1218,7 +1227,10 @@ public function hasMany($associated, array $options = []) { $options += ['sourceTable' => $this]; - return $this->_associations->load(HasMany::class, $associated, $options); + /** @var \Cake\ORM\Association\HasMany $association */ + $association = $this->_associations->load(HasMany::class, $associated, $options); + + return $association; } /** @@ -1269,7 +1281,10 @@ public function belongsToMany($associated, array $options = []) { $options += ['sourceTable' => $this]; - return $this->_associations->load(BelongsToMany::class, $associated, $options); + /** @var \Cake\ORM\Association\BelongsToMany $association */ + $association = $this->_associations->load(BelongsToMany::class, $associated, $options); + + return $association; } /** diff --git a/src/Validation/ValidationSet.php b/src/Validation/ValidationSet.php index c0adbfbde2d..de4aa444653 100644 --- a/src/Validation/ValidationSet.php +++ b/src/Validation/ValidationSet.php @@ -54,7 +54,7 @@ class ValidationSet implements ArrayAccess, IteratorAggregate, Countable * * @param bool|string|callable|null $validatePresent Deprecated since 3.6.0 ValidationSet::isPresenceRequired() is deprecated as a setter * Use ValidationSet::requirePresence() instead. - * @return bool|string + * @return bool|string|callable */ public function isPresenceRequired($validatePresent = null) { diff --git a/src/View/Helper.php b/src/View/Helper.php index 5dc6d7b1284..9f0e9b3ffef 100644 --- a/src/View/Helper.php +++ b/src/View/Helper.php @@ -181,6 +181,7 @@ protected function _confirm($message, $okCode, $cancelCode = '', $options = []) // We cannot change the key here in 3.x, but the behavior is inverted in this case $escape = isset($options['escape']) && $options['escape'] === false; if ($escape) { + /** @var string $confirm */ $confirm = h($confirm); } diff --git a/src/View/Helper/UrlHelper.php b/src/View/Helper/UrlHelper.php index ecf0fa5553a..81c3a62c2b2 100644 --- a/src/View/Helper/UrlHelper.php +++ b/src/View/Helper/UrlHelper.php @@ -55,6 +55,7 @@ public function build($url = null, $options = false) /** @var string $url */ $url = Router::url($url, $options['fullBase']); if ($options['escape']) { + /** @var string $url */ $url = h($url); } @@ -210,7 +211,10 @@ protected function _encodeUrl($url) $parts = array_map('rawurlencode', $parts); $encoded = implode('/', $parts); - return h(str_replace($path, $encoded, $url)); + /** @var string $url */ + $url = h(str_replace($path, $encoded, $url)); + + return $url; } /** diff --git a/src/View/ViewBuilder.php b/src/View/ViewBuilder.php index d89d7f2a62a..192af1fcb00 100644 --- a/src/View/ViewBuilder.php +++ b/src/View/ViewBuilder.php @@ -254,7 +254,7 @@ public function setPlugin($name) /** * Gets the plugin name to use. * - * @return string + * @return string|null|false */ public function getPlugin() { @@ -267,7 +267,7 @@ public function getPlugin() * @deprecated 3.4.0 Use setPlugin()/getPlugin() instead. * @param string|null|false $name Plugin name. If null returns current plugin. * Use false to remove the current plugin name. - * @return string|$this + * @return string|false|null|$this */ public function plugin($name = null) { @@ -341,7 +341,7 @@ public function setTheme($theme) /** * Gets the view theme to use. * - * @return string + * @return string|null|false */ public function getTheme() { @@ -354,7 +354,7 @@ public function getTheme() * @deprecated 3.4.0 Use setTheme()/getTheme() instead. * @param string|null|false $theme Theme name. If null returns current theme. * Use false to remove the current theme. - * @return string|$this + * @return string|false|null|$this */ public function theme($theme = null) {