Browse Source

Merge pull request #13223 from cakephp/4.x-cleanup

Cleanup up static returns, fix array doc blocks.
ADmad 7 years ago
parent
commit
c697e31e00

+ 3 - 4
.scrutinizer.yml

@@ -19,12 +19,11 @@ build:
         php:
           ini:
             'memory_limit': -1
-          pecl_extensions:
-            - redis
-            - memcached
-            - apcu
       dependencies:
         override:
+          - pecl install apcu
+          - pecl install redis
+          - pecl install memcached
           - composer stan-setup
       tests:
         override:

+ 0 - 6
psalm-baseline.xml

@@ -1432,12 +1432,6 @@
     </PropertyNotSetInConstructor>
   </file>
   <file src="src/Http/Client/Response.php">
-    <PossiblyNullArgument occurrences="1">
-      <code>$cookie</code>
-    </PossiblyNullArgument>
-    <PossiblyNullReference occurrences="1">
-      <code>getValue</code>
-    </PossiblyNullReference>
     <PropertyNotSetInConstructor occurrences="5">
       <code>$code</code>
       <code>$cookies</code>

+ 2 - 1
src/Core/Configure.php

@@ -272,12 +272,13 @@ class Configure
     /**
      * Gets the names of the configured Engine objects.
      *
-     * @return array
+     * @return string[]
      */
     public static function configured(): array
     {
         return array_keys(static::$_engines);
     }
+
     /**
      * Remove a configured engine. This will unset the engine
      * and make any future attempts to use it cause an Exception.

+ 2 - 2
src/Core/StaticConfigTrait.php

@@ -277,7 +277,7 @@ REGEXP;
     /**
      * Updates the DSN class map for this class.
      *
-     * @param array $map Additions/edits to the class map to apply.
+     * @param string[] $map Additions/edits to the class map to apply.
      * @return void
      */
     public static function setDsnClassMap(array $map): void
@@ -288,7 +288,7 @@ REGEXP;
     /**
      * Returns the DSN class map for this class.
      *
-     * @return array
+     * @return string[]
      */
     public static function getDsnClassMap(): array
     {

+ 8 - 7
src/Http/Client/Response.php

@@ -256,9 +256,9 @@ class Response extends Message implements ResponseInterface
      *
      * @param int $code The status code to set.
      * @param string $reasonPhrase The status reason phrase.
-     * @return $this A copy of the current object with an updated status code.
+     * @return static A copy of the current object with an updated status code.
      */
-    public function withStatus($code, $reasonPhrase = ''): self
+    public function withStatus($code, $reasonPhrase = '')
     {
         $new = clone $this;
         $new->code = $code;
@@ -330,11 +330,13 @@ class Response extends Message implements ResponseInterface
     public function getCookie(string $name)
     {
         $this->buildCookieCollection();
-        if (!$this->cookies->has($name)) {
+
+        $cookie = $this->cookies->get($name);
+        if ($cookie === null) {
             return null;
         }
 
-        return $this->cookies->get($name)->getValue();
+        return $cookie->getValue();
     }
 
     /**
@@ -347,12 +349,11 @@ class Response extends Message implements ResponseInterface
     {
         $this->buildCookieCollection();
 
-        if (!$this->cookies->has($name)) {
+        $cookie = $this->cookies->get($name);
+        if ($cookie === null) {
             return null;
         }
 
-        $cookie = $this->cookies->get($name);
-
         return $this->convertCookieToArray($cookie);
     }
 

+ 1 - 1
src/Http/Cookie/CookieCollection.php

@@ -335,7 +335,7 @@ class CookieCollection implements IteratorAggregate, Countable
      * Parse Set-Cookie headers into array
      *
      * @param array $values List of Set-Cookie Header values.
-     * @return \Cake\Http\Cookie\Cookie[] An array of cookie objects
+     * @return \Cake\Http\Cookie\CookieInterface[] An array of cookie objects
      */
     protected static function parseSetCookieHeader(array $values): array
     {

+ 21 - 21
src/Http/Response.php

@@ -518,7 +518,7 @@ class Response implements ResponseInterface
      * @param string $url The location to redirect to.
      * @return static A new response with the Location header set.
      */
-    public function withLocation(string $url): self
+    public function withLocation(string $url)
     {
         $new = $this->withHeader('Location', $url);
         if ($new->_status === 200) {
@@ -680,7 +680,7 @@ class Response implements ResponseInterface
      * @param string $contentType Either a file extension which will be mapped to a mime-type or a concrete mime-type.
      * @return static
      */
-    public function withType(string $contentType): self
+    public function withType(string $contentType)
     {
         $mappedType = $this->resolveType($contentType);
         $new = clone $this;
@@ -766,7 +766,7 @@ class Response implements ResponseInterface
      * @param string $charset Character set string.
      * @return static
      */
-    public function withCharset(string $charset): self
+    public function withCharset(string $charset)
     {
         $new = clone $this;
         $new->_charset = $charset;
@@ -780,7 +780,7 @@ class Response implements ResponseInterface
      *
      * @return static
      */
-    public function withDisabledCache(): self
+    public function withDisabledCache()
     {
         return $this->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT')
             ->withHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT')
@@ -794,7 +794,7 @@ class Response implements ResponseInterface
      * @param int|string $time a valid time for cache expiry
      * @return static
      */
-    public function withCache($since, $time = '+1 day'): self
+    public function withCache($since, $time = '+1 day')
     {
         if (!is_int($time)) {
             $time = strtotime($time);
@@ -815,7 +815,7 @@ class Response implements ResponseInterface
      * @param int|null $time time in seconds after which the response should no longer be considered fresh.
      * @return static
      */
-    public function withSharable(bool $public, ?int $time = null): self
+    public function withSharable(bool $public, ?int $time = null)
     {
         $new = clone $this;
         unset($new->_cacheDirectives['private'], $new->_cacheDirectives['public']);
@@ -840,7 +840,7 @@ class Response implements ResponseInterface
      * @param int $seconds The number of seconds for shared max-age
      * @return static
      */
-    public function withSharedMaxAge(int $seconds): self
+    public function withSharedMaxAge(int $seconds)
     {
         $new = clone $this;
         $new->_cacheDirectives['s-maxage'] = $seconds;
@@ -858,7 +858,7 @@ class Response implements ResponseInterface
      * @param int $seconds The seconds a cached response can be considered valid
      * @return static
      */
-    public function withMaxAge(int $seconds): self
+    public function withMaxAge(int $seconds)
     {
         $new = clone $this;
         $new->_cacheDirectives['max-age'] = $seconds;
@@ -878,7 +878,7 @@ class Response implements ResponseInterface
      * @param bool $enable If boolean sets or unsets the directive.
      * @return static
      */
-    public function withMustRevalidate(bool $enable): self
+    public function withMustRevalidate(bool $enable)
     {
         $new = clone $this;
         if ($enable) {
@@ -924,7 +924,7 @@ class Response implements ResponseInterface
      * @param string|\DateTimeInterface $time Valid time string or \DateTime instance.
      * @return static
      */
-    public function withExpires($time): self
+    public function withExpires($time)
     {
         $date = $this->_getUTCDate($time);
 
@@ -947,7 +947,7 @@ class Response implements ResponseInterface
      * @param int|string|\DateTimeInterface $time Valid time string or \DateTime instance.
      * @return static
      */
-    public function withModified($time): self
+    public function withModified($time)
     {
         $date = $this->_getUTCDate($time);
 
@@ -991,7 +991,7 @@ class Response implements ResponseInterface
      *
      * @return static
      */
-    public function withNotModified(): self
+    public function withNotModified()
     {
         $new = $this->withStatus(304);
         $new->_createStream();
@@ -1022,7 +1022,7 @@ class Response implements ResponseInterface
      *   containing the list for variances.
      * @return static
      */
-    public function withVary($cacheVariances): self
+    public function withVary($cacheVariances)
     {
         return $this->withHeader('Vary', (array)$cacheVariances);
     }
@@ -1048,7 +1048,7 @@ class Response implements ResponseInterface
      *   other with the same hash or not. Defaults to false
      * @return static
      */
-    public function withEtag(string $hash, bool $weak = false): self
+    public function withEtag(string $hash, bool $weak = false)
     {
         $hash = sprintf('%s"%s"', $weak ? 'W/' : null, $hash);
 
@@ -1108,7 +1108,7 @@ class Response implements ResponseInterface
      * @param string $filename The name of the file as the browser will download the response
      * @return static
      */
-    public function withDownload(string $filename): self
+    public function withDownload(string $filename)
     {
         return $this->withHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
     }
@@ -1119,7 +1119,7 @@ class Response implements ResponseInterface
      * @param int|string $bytes Number of bytes
      * @return static
      */
-    public function withLength($bytes): self
+    public function withLength($bytes)
     {
         return $this->withHeader('Content-Length', (string)$bytes);
     }
@@ -1146,7 +1146,7 @@ class Response implements ResponseInterface
      * @return static
      * @since 3.6.0
      */
-    public function withAddedLink(string $url, array $options = []): self
+    public function withAddedLink(string $url, array $options = [])
     {
         $params = [];
         foreach ($options as $key => $option) {
@@ -1228,7 +1228,7 @@ class Response implements ResponseInterface
      * @param \Cake\Http\Cookie\CookieInterface $cookie cookie object
      * @return static
      */
-    public function withCookie(CookieInterface $cookie): self
+    public function withCookie(CookieInterface $cookie)
     {
         $new = clone $this;
         $new->_cookies = $new->_cookies->add($cookie);
@@ -1249,7 +1249,7 @@ class Response implements ResponseInterface
      * @param \Cake\Http\Cookie\CookieInterface $cookie cookie object
      * @return static
      */
-    public function withExpiredCookie(CookieInterface $cookie): self
+    public function withExpiredCookie(CookieInterface $cookie)
     {
         $cookie = $cookie->withExpired();
 
@@ -1406,7 +1406,7 @@ class Response implements ResponseInterface
      * @return static
      * @throws \Cake\Http\Exception\NotFoundException
      */
-    public function withFile(string $path, array $options = []): self
+    public function withFile(string $path, array $options = [])
     {
         $file = $this->validateFile($path);
         $options += [
@@ -1462,7 +1462,7 @@ class Response implements ResponseInterface
      * @param string $string The string to be sent
      * @return static
      */
-    public function withStringBody(?string $string): self
+    public function withStringBody(?string $string)
     {
         $new = clone $this;
         $new->_createStream();

+ 6 - 6
src/Http/ServerRequest.php

@@ -1437,7 +1437,7 @@ class ServerRequest implements ServerRequestInterface
      * @param \Cake\Http\Cookie\CookieCollection $cookies The cookie collection
      * @return static
      */
-    public function withCookieCollection(CookieCollection $cookies): self
+    public function withCookieCollection(CookieCollection $cookies)
     {
         $new = clone $this;
         $values = [];
@@ -1465,7 +1465,7 @@ class ServerRequest implements ServerRequestInterface
      * @param array $cookies The new cookie data to use.
      * @return static
      */
-    public function withCookieParams(array $cookies): self
+    public function withCookieParams(array $cookies)
     {
         $new = clone $this;
         $new->cookies = $cookies;
@@ -1575,7 +1575,7 @@ class ServerRequest implements ServerRequestInterface
      * @param string $value Value to set
      * @return static
      */
-    public function withEnv(string $key, string $value): self
+    public function withEnv(string $key, string $value)
     {
         $new = clone $this;
         $new->_environment[$key] = $value;
@@ -1644,7 +1644,7 @@ class ServerRequest implements ServerRequestInterface
      * @param mixed $value The value to insert into the request data.
      * @return static
      */
-    public function withData(string $name, $value): self
+    public function withData(string $name, $value)
     {
         $copy = clone $this;
         $copy->data = Hash::insert($copy->data, $name, $value);
@@ -1661,7 +1661,7 @@ class ServerRequest implements ServerRequestInterface
      * @param string $name The dot separated path to remove.
      * @return static
      */
-    public function withoutData(string $name): self
+    public function withoutData(string $name)
     {
         $copy = clone $this;
         $copy->data = Hash::remove($copy->data, $name);
@@ -1679,7 +1679,7 @@ class ServerRequest implements ServerRequestInterface
      * @param mixed $value The value to insert into the the request parameters.
      * @return static
      */
-    public function withParam(string $name, $value): self
+    public function withParam(string $name, $value)
     {
         $copy = clone $this;
         $copy->params = Hash::insert($copy->params, $name, $value);

+ 4 - 4
src/Log/Log.php

@@ -113,7 +113,7 @@ class Log
     /**
      * An array mapping url schemes to fully qualified Log engine class names
      *
-     * @var array
+     * @var string[]
      */
     protected static $_dsnClassMap = [
         'console' => Engine\ConsoleLog::class,
@@ -138,7 +138,7 @@ class Log
     /**
      * Handled log levels
      *
-     * @var array
+     * @var string[]
      */
     protected static $_levels = [
         'emergency',
@@ -225,7 +225,7 @@ class Log
      * Call this method to obtain current
      * level configuration.
      *
-     * @return array active log levels
+     * @return string[] Active log levels
      */
     public static function levels(): array
     {
@@ -355,7 +355,7 @@ class Log
             $level = array_search($level, static::$_levelMap, true);
         }
 
-        if (!in_array($level, static::$_levels)) {
+        if (!in_array($level, static::$_levels, true)) {
             throw new InvalidArgumentException(sprintf('Invalid log level "%s"', $level));
         }
 

+ 3 - 3
src/Routing/Router.php

@@ -154,7 +154,7 @@ class Router
     /**
      * Default extensions defined with Router::extensions()
      *
-     * @var array
+     * @var string[]
      */
     protected static $_defaultExtensions = [];
 
@@ -726,10 +726,10 @@ class Router
      * A string or an array of valid extensions can be passed to this method.
      * If called without any parameters it will return current list of set extensions.
      *
-     * @param array|string|null $extensions List of extensions to be added.
+     * @param string[]|string|null $extensions List of extensions to be added.
      * @param bool $merge Whether to merge with or override existing extensions.
      *   Defaults to `true`.
-     * @return array Array of extensions Router is configured to parse.
+     * @return string[] Array of extensions Router is configured to parse.
      */
     public static function extensions($extensions = null, $merge = true): array
     {

+ 1 - 1
src/View/Form/ContextInterface.php

@@ -89,7 +89,7 @@ interface ContextInterface
     public function getMaxLength(string $field): ?int;
 
     /**
-     * Get the fieldnames of the top level object in this context.
+     * Get the field names of the top level object in this context.
      *
      * @return string[] A list of the field names in the context.
      */

+ 1 - 1
src/View/View.php

@@ -811,7 +811,7 @@ class View implements EventDispatcherInterface
     /**
      * Get the names of all the existing blocks.
      *
-     * @return array An array containing the blocks.
+     * @return string[] An array containing the blocks.
      * @see \Cake\View\ViewBlock::keys()
      */
     public function blocks(): array

+ 3 - 3
src/View/ViewBlock.php

@@ -57,7 +57,7 @@ class ViewBlock
     /**
      * The active blocks being captured.
      *
-     * @var array
+     * @var string[]
      */
     protected $_active = [];
 
@@ -218,9 +218,9 @@ class ViewBlock
     }
 
     /**
-     * Get the names of the unclosed/active blocks.
+     * Get the unclosed/active blocks. Key is name, value is mode.
      *
-     * @return array An array of unclosed blocks.
+     * @return string[] An array of unclosed blocks.
      */
     public function unclosed(): array
     {

+ 1 - 1
src/View/ViewBuilder.php

@@ -595,7 +595,7 @@ class ViewBuilder implements JsonSerializable, Serializable
      * @param array $config View builder configuration array.
      * @return $this Configured view builder instance.
      */
-    public function createFromArray(array $config): self
+    public function createFromArray(array $config)
     {
         foreach ($config as $property => $value) {
             $this->{$property} = $value;