Browse Source

Fixup in_array() and pure string usage, string[] docs and merging.

mscherer 6 years ago
parent
commit
ff4127a410

+ 1 - 0
.gitignore

@@ -12,6 +12,7 @@
 *.mo
 debug.log
 error.log
+.phpunit.result.cache
 
 # OS generated files #
 ######################

+ 4 - 4
src/Database/Schema/BaseSchema.php

@@ -215,10 +215,10 @@ abstract class BaseSchema
      * Generate the SQL to create a table.
      *
      * @param \Cake\Database\Schema\TableSchema $schema Table instance.
-     * @param array $columns The columns to go inside the table.
-     * @param array $constraints The constraints for the table.
-     * @param array $indexes The indexes for the table.
-     * @return array SQL statements to create a table.
+     * @param string[] $columns The columns to go inside the table.
+     * @param string[] $constraints The constraints for the table.
+     * @param string[] $indexes The indexes for the table.
+     * @return string[] SQL statements to create a table.
      */
     abstract public function createTableSql(TableSchema $schema, $columns, $constraints, $indexes);
 

+ 1 - 1
src/Database/Schema/Collection.php

@@ -54,7 +54,7 @@ class Collection
     /**
      * Get the list of tables available in the current connection.
      *
-     * @return array The list of tables in the connected database/schema.
+     * @return string[] The list of tables in the connected database/schema.
      */
     public function listTables()
     {

+ 12 - 12
src/Datasource/EntityTrait.php

@@ -44,7 +44,7 @@ trait EntityTrait
      * List of property names that should **not** be included in JSON or Array
      * representations of this Entity.
      *
-     * @var array
+     * @var string[]
      */
     protected $_hidden = [];
 
@@ -53,7 +53,7 @@ trait EntityTrait
      * representations of this Entity. If a field is present in both _hidden and _virtual
      * the field will **not** be in the array/json versions of the entity.
      *
-     * @var array
+     * @var string[]
      */
     protected $_virtual = [];
 
@@ -432,7 +432,7 @@ trait EntityTrait
      * $entity->unsetProperty(['name', 'last_name']);
      * ```
      *
-     * @param string|array $property The property to unset.
+     * @param string|string[] $property The property to unset.
      * @return $this
      */
     public function unsetProperty($property)
@@ -452,8 +452,8 @@ trait EntityTrait
      * will be returned. Otherwise the hidden properties will be set.
      *
      * @deprecated 3.4.0 Use EntityTrait::setHidden() and EntityTrait::getHidden()
-     * @param array|null $properties Either an array of properties to hide or null to get properties
-     * @return array|$this
+     * @param string[]|null $properties Either an array of properties to hide or null to get properties
+     * @return string[]|$this
      */
     public function hiddenProperties($properties = null)
     {
@@ -472,7 +472,7 @@ trait EntityTrait
     /**
      * Sets hidden properties.
      *
-     * @param array $properties An array of properties to hide from array exports.
+     * @param string[] $properties An array of properties to hide from array exports.
      * @param bool $merge Merge the new properties with the existing. By default false.
      * @return $this
      */
@@ -493,7 +493,7 @@ trait EntityTrait
     /**
      * Gets the hidden properties.
      *
-     * @return array
+     * @return string[]
      */
     public function getHidden()
     {
@@ -507,8 +507,8 @@ trait EntityTrait
      * will be returned. Otherwise the virtual properties will be set.
      *
      * @deprecated 3.4.0 Use EntityTrait::getVirtual() and EntityTrait::setVirtual()
-     * @param array|null $properties Either an array of properties to treat as virtual or null to get properties
-     * @return array|$this
+     * @param string[]|null $properties Either an array of properties to treat as virtual or null to get properties
+     * @return string[]|$this
      */
     public function virtualProperties($properties = null)
     {
@@ -547,7 +547,7 @@ trait EntityTrait
     /**
      * Gets the virtual properties on this entity.
      *
-     * @return array
+     * @return string[]
      */
     public function getVirtual()
     {
@@ -560,7 +560,7 @@ trait EntityTrait
      * The list of visible properties is all standard properties
      * plus virtual properties minus hidden properties.
      *
-     * @return array A list of properties that are 'visible' in all
+     * @return string[] A list of properties that are 'visible' in all
      *     representations.
      */
     public function getVisible()
@@ -577,7 +577,7 @@ trait EntityTrait
      * The list of visible properties is all standard properties
      * plus virtual properties minus hidden properties.
      *
-     * @return array A list of properties that are 'visible' in all
+     * @return string[] A list of properties that are 'visible' in all
      *     representations.
      * @deprecated 3.8.0 Use getVisible() instead.
      */

+ 1 - 1
src/Http/Client.php

@@ -536,7 +536,7 @@ class Client
      * or full mime-type.
      *
      * @param string $type short type alias or full mimetype.
-     * @return array Headers to set on the request.
+     * @return string[] Headers to set on the request.
      * @throws \Cake\Core\Exception\Exception When an unknown type alias is used.
      */
     protected function _typeHeaders($type)

+ 5 - 5
src/Http/ServerRequest.php

@@ -383,7 +383,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
         $method = $this->getEnv('REQUEST_METHOD');
         $override = false;
 
-        if (in_array($method, ['PUT', 'DELETE', 'PATCH']) &&
+        if (in_array($method, ['PUT', 'DELETE', 'PATCH'], true) &&
             strpos($this->contentType(), 'application/x-www-form-urlencoded') === 0
         ) {
             $data = $this->input();
@@ -400,7 +400,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
             $override = true;
         }
 
-        if ($override && !in_array($this->_environment['REQUEST_METHOD'], ['PUT', 'POST', 'DELETE', 'PATCH'])) {
+        if ($override && !in_array($this->_environment['REQUEST_METHOD'], ['PUT', 'POST', 'DELETE', 'PATCH'], true)) {
             $data = [];
         }
 
@@ -1119,7 +1119,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
     protected function normalizeHeaderName($name)
     {
         $name = str_replace('-', '_', strtoupper($name));
-        if (!in_array($name, ['CONTENT_LENGTH', 'CONTENT_TYPE'])) {
+        if (!in_array($name, ['CONTENT_LENGTH', 'CONTENT_TYPE'], true)) {
             $name = 'HTTP_' . $name;
         }
 
@@ -1496,7 +1496,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
             return $accept;
         }
 
-        return in_array($type, $accept);
+        return in_array($type, $accept, true);
     }
 
     /**
@@ -1544,7 +1544,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
             return $accept;
         }
 
-        return in_array(strtolower($language), $accept);
+        return in_array(strtolower($language), $accept, true);
     }
 
     /**

+ 1 - 1
src/Routing/Route/Route.php

@@ -219,7 +219,7 @@ class Route
         if (mb_strlen($patternValues) < strlen($patternValues)) {
             $this->options['multibytePattern'] = true;
         }
-        $this->options = array_merge($this->options, $patterns);
+        $this->options = $patterns + $this->options;
 
         return $this;
     }

+ 5 - 4
src/Routing/RouteBuilder.php

@@ -104,7 +104,7 @@ class RouteBuilder
      * The list of middleware that routes in this builder get
      * added during construction.
      *
-     * @var array
+     * @var string[]
      */
     protected $middleware = [];
 
@@ -191,8 +191,8 @@ class RouteBuilder
      * extensions applied. However, setting extensions does not modify existing routes.
      *
      * @deprecated 3.5.0 Use getExtensions/setExtensions instead.
-     * @param array|string|null $extensions Either the extensions to use or null.
-     * @return array|null
+     * @param string[]|string|null $extensions Either the extensions to use or null.
+     * @return string[]|null
      */
     public function extensions($extensions = null)
     {
@@ -235,7 +235,7 @@ class RouteBuilder
     /**
      * Add additional extensions to what is already in current scope
      *
-     * @param string|array $extensions One or more extensions to add
+     * @param string|string[] $extensions One or more extensions to add
      * @return void
      */
     public function addExtensions($extensions)
@@ -1049,6 +1049,7 @@ class RouteBuilder
      *
      * @param string ...$names The names of the middleware to apply to the current scope.
      * @return $this
+     * @throws \RuntimeException
      * @see \Cake\Routing\RouteCollection::addMiddlewareToScope()
      */
     public function applyMiddleware(...$names)

+ 1 - 0
src/Routing/RouteCollection.php

@@ -504,6 +504,7 @@ class RouteCollection
      * @param string $path The URL path to register middleware for.
      * @param string[] $middleware The middleware names to add for the path.
      * @return $this
+     * @throws \RuntimeException
      */
     public function applyMiddleware($path, array $middleware)
     {

+ 3 - 3
src/Routing/Router.php

@@ -160,7 +160,7 @@ class Router
     /**
      * Default extensions defined with Router::extensions()
      *
-     * @var array
+     * @var string[]
      */
     protected static $_defaultExtensions = [];
 
@@ -942,10 +942,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)
     {

+ 1 - 1
src/TestSuite/Fixture/TestFixture.php

@@ -249,7 +249,7 @@ class TestFixture implements FixtureInterface, TableSchemaInterface, TableSchema
         $schemaCollection = $db->getSchemaCollection();
         $tables = $schemaCollection->listTables();
 
-        if (!in_array($this->table, $tables)) {
+        if (!in_array($this->table, $tables, true)) {
             throw new CakeException(
                 sprintf(
                     'Cannot describe schema for table `%s` for fixture `%s` : the table does not exist.',

+ 3 - 3
src/Utility/CookieCryptTrait.php

@@ -28,7 +28,7 @@ trait CookieCryptTrait
     /**
      * Valid cipher names for encrypted cookies.
      *
-     * @var array
+     * @var string[]
      */
     protected $_validCiphers = ['aes', 'rijndael'];
 
@@ -93,10 +93,10 @@ trait CookieCryptTrait
     /**
      * Decrypts $value using public $type method in Security class
      *
-     * @param array $values Values to decrypt
+     * @param string[] $values Values to decrypt
      * @param string|bool $mode Encryption mode
      * @param string|null $key Used as the security salt if specified.
-     * @return string|array Decrypted values
+     * @return string|string[] Decrypted values
      */
     protected function _decrypt($values, $mode, $key = null)
     {

+ 1 - 1
src/Utility/Security.php

@@ -67,7 +67,7 @@ class Security
         $algorithm = strtolower($algorithm);
 
         $availableAlgorithms = hash_algos();
-        if (!in_array($algorithm, $availableAlgorithms)) {
+        if (!in_array($algorithm, $availableAlgorithms, true)) {
             throw new RuntimeException(sprintf(
                 'The hash type `%s` was not found. Available algorithms are: %s',
                 $algorithm,

+ 1 - 1
src/Validation/Validation.php

@@ -1246,7 +1246,7 @@ class Validation
             $mimeTypes[$key] = strtolower($val);
         }
 
-        return in_array(strtolower($mime), $mimeTypes);
+        return in_array(strtolower($mime), $mimeTypes, true);
     }
 
     /**

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

@@ -126,7 +126,7 @@ class ArrayContext implements ContextInterface
     {
         $primaryKey = $this->primaryKey();
 
-        return in_array($field, $primaryKey);
+        return in_array($field, $primaryKey, true);
     }
 
     /**

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

@@ -184,7 +184,7 @@ class EntityContext implements ContextInterface
         $table = $this->_getTable($parts);
         $primaryKey = (array)$table->getPrimaryKey();
 
-        return in_array(array_pop($parts), $primaryKey);
+        return in_array(array_pop($parts), $primaryKey, true);
     }
 
     /**

+ 1 - 1
src/View/Helper/FormHelper.php

@@ -190,7 +190,7 @@ class FormHelper extends Helper
     /**
      * List of fields created, used with secure forms.
      *
-     * @var array
+     * @var string[]
      */
     public $fields = [];
 

+ 1 - 1
src/View/StringTemplate.php

@@ -300,7 +300,7 @@ class StringTemplate
      * Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'
      *
      * @param string $key The name of the attribute to create
-     * @param string|array $value The value of the attribute to create.
+     * @param string|string[] $value The value of the attribute to create.
      * @param bool $escape Define if the value must be escaped
      * @return string The composed attribute.
      */

+ 5 - 5
src/View/View.php

@@ -197,7 +197,7 @@ class View implements EventDispatcherInterface
     /**
      * List of generated DOM UUIDs.
      *
-     * @var array
+     * @var string[]
      * @deprecated 3.7.0 The property is deprecated and will be removed in 4.0.0.
      */
     public $uuids = [];
@@ -241,21 +241,21 @@ class View implements EventDispatcherInterface
     /**
      * Holds an array of paths.
      *
-     * @var array
+     * @var string[]
      */
     protected $_paths = [];
 
     /**
      * Holds an array of plugin paths.
      *
-     * @var array
+     * @var string[][]
      */
     protected $_pathsForPlugin = [];
 
     /**
      * The names of views and their parents used with View::extend();
      *
-     * @var array
+     * @var string[]
      */
     protected $_parents = [];
 
@@ -1143,7 +1143,7 @@ class View implements EventDispatcherInterface
         if ($parent == $this->_current) {
             throw new LogicException('You cannot have views extend themselves.');
         }
-        if (isset($this->_parents[$parent]) && $this->_parents[$parent] == $this->_current) {
+        if (isset($this->_parents[$parent]) && $this->_parents[$parent] === $this->_current) {
             throw new LogicException('You cannot have views extend in a loop.');
         }
         $this->_parents[$this->_current] = $parent;

+ 3 - 3
src/View/Widget/SelectBoxWidget.php

@@ -226,7 +226,7 @@ class SelectBoxWidget extends BasicWidget
      * @param array|string|null $selected The options to select.
      * @param array $templateVars Additional template variables.
      * @param bool $escape Toggle HTML escaping.
-     * @return array Option elements.
+     * @return string[] Option elements.
      */
     protected function _renderOptions($options, $disabled, $selected, $templateVars, $escape)
     {
@@ -280,7 +280,7 @@ class SelectBoxWidget extends BasicWidget
      * Helper method for deciding what options are selected.
      *
      * @param string $key The key to test.
-     * @param array|string|null $selected The selected values.
+     * @param string[]|string|null $selected The selected values.
      * @return bool
      */
     protected function _isSelected($key, $selected)
@@ -303,7 +303,7 @@ class SelectBoxWidget extends BasicWidget
      * Helper method for deciding what options are disabled.
      *
      * @param string $key The key to test.
-     * @param array|null $disabled The disabled values.
+     * @param string[]|null $disabled The disabled values.
      * @return bool
      */
     protected function _isDisabled($key, $disabled)