Skip to content

Commit

Permalink
Merge pull request #13851 from cakephp/master-in-array
Browse files Browse the repository at this point in the history
Fixup in_array() and pure string usage, string[] docs and merging.
  • Loading branch information
markstory committed Nov 7, 2019
2 parents 34833a0 + ff4127a commit 9e14905
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@
*.mo
debug.log
error.log
.phpunit.result.cache

# OS generated files #
######################
Expand Down
8 changes: 4 additions & 4 deletions src/Database/Schema/BaseSchema.php
Expand Up @@ -215,10 +215,10 @@ public function convertOptionsDescription(TableSchema $schema, $row)
* 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);

Expand Down
2 changes: 1 addition & 1 deletion src/Database/Schema/Collection.php
Expand Up @@ -54,7 +54,7 @@ public function __construct(Connection $connection)
/**
* 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()
{
Expand Down
24 changes: 12 additions & 12 deletions src/Datasource/EntityTrait.php
Expand Up @@ -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 = [];

Expand All @@ -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 = [];

Expand Down Expand Up @@ -432,7 +432,7 @@ public function hasValue($property)
* $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)
Expand All @@ -452,8 +452,8 @@ public function unsetProperty($property)
* 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)
{
Expand All @@ -472,7 +472,7 @@ public function hiddenProperties($properties = null)
/**
* 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
*/
Expand All @@ -493,7 +493,7 @@ public function setHidden(array $properties, $merge = false)
/**
* Gets the hidden properties.
*
* @return array
* @return string[]
*/
public function getHidden()
{
Expand All @@ -507,8 +507,8 @@ public function getHidden()
* 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)
{
Expand Down Expand Up @@ -547,7 +547,7 @@ public function setVirtual(array $properties, $merge = false)
/**
* Gets the virtual properties on this entity.
*
* @return array
* @return string[]
*/
public function getVirtual()
{
Expand All @@ -560,7 +560,7 @@ public function getVirtual()
* 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()
Expand All @@ -577,7 +577,7 @@ public function getVisible()
* 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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Client.php
Expand Up @@ -536,7 +536,7 @@ protected function _createRequest($method, $url, $data, $options)
* 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)
Expand Down
10 changes: 5 additions & 5 deletions src/Http/ServerRequest.php
Expand Up @@ -383,7 +383,7 @@ protected function _processPost($data)
$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();
Expand All @@ -400,7 +400,7 @@ protected function _processPost($data)
$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 = [];
}

Expand Down Expand Up @@ -1119,7 +1119,7 @@ public function here($base = true)
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;
}

Expand Down Expand Up @@ -1496,7 +1496,7 @@ public function accepts($type = null)
return $accept;
}

return in_array($type, $accept);
return in_array($type, $accept, true);
}

/**
Expand Down Expand Up @@ -1544,7 +1544,7 @@ public function acceptLanguage($language = null)
return $accept;
}

return in_array(strtolower($language), $accept);
return in_array(strtolower($language), $accept, true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Routing/Route/Route.php
Expand Up @@ -219,7 +219,7 @@ public function setPatterns(array $patterns)
if (mb_strlen($patternValues) < strlen($patternValues)) {
$this->options['multibytePattern'] = true;
}
$this->options = array_merge($this->options, $patterns);
$this->options = $patterns + $this->options;

return $this;
}
Expand Down
9 changes: 5 additions & 4 deletions src/Routing/RouteBuilder.php
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -191,8 +191,8 @@ public function getRouteClass()
* 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)
{
Expand Down Expand Up @@ -235,7 +235,7 @@ public function getExtensions()
/**
* 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)
Expand Down Expand Up @@ -1049,6 +1049,7 @@ public function registerMiddleware($name, $middleware)
*
* @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)
Expand Down
1 change: 1 addition & 0 deletions src/Routing/RouteCollection.php
Expand Up @@ -504,6 +504,7 @@ public function middlewareExists($name)
* @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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Routing/Router.php
Expand Up @@ -160,7 +160,7 @@ class Router
/**
* Default extensions defined with Router::extensions()
*
* @var array
* @var string[]
*/
protected static $_defaultExtensions = [];

Expand Down Expand Up @@ -942,10 +942,10 @@ public static function normalize($url = '/')
* 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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/TestSuite/Fixture/TestFixture.php
Expand Up @@ -249,7 +249,7 @@ protected function _schemaFromReflection()
$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.',
Expand Down
6 changes: 3 additions & 3 deletions src/Utility/CookieCryptTrait.php
Expand Up @@ -28,7 +28,7 @@ trait CookieCryptTrait
/**
* Valid cipher names for encrypted cookies.
*
* @var array
* @var string[]
*/
protected $_validCiphers = ['aes', 'rijndael'];

Expand Down Expand Up @@ -93,10 +93,10 @@ protected function _checkCipher($encrypt)
/**
* 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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Security.php
Expand Up @@ -67,7 +67,7 @@ public static function hash($string, $algorithm = null, $salt = false)
$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,
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validation.php
Expand Up @@ -1246,7 +1246,7 @@ public static function mimeType($check, $mimeTypes = [])
$mimeTypes[$key] = strtolower($val);
}

return in_array(strtolower($mime), $mimeTypes);
return in_array(strtolower($mime), $mimeTypes, true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/View/Form/ArrayContext.php
Expand Up @@ -126,7 +126,7 @@ public function isPrimaryKey($field)
{
$primaryKey = $this->primaryKey();

return in_array($field, $primaryKey);
return in_array($field, $primaryKey, true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/View/Form/EntityContext.php
Expand Up @@ -184,7 +184,7 @@ public function isPrimaryKey($field)
$table = $this->_getTable($parts);
$primaryKey = (array)$table->getPrimaryKey();

return in_array(array_pop($parts), $primaryKey);
return in_array(array_pop($parts), $primaryKey, true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -190,7 +190,7 @@ class FormHelper extends Helper
/**
* List of fields created, used with secure forms.
*
* @var array
* @var string[]
*/
public $fields = [];

Expand Down
2 changes: 1 addition & 1 deletion src/View/StringTemplate.php
Expand Up @@ -300,7 +300,7 @@ public function formatAttributes($options, $exclude = null)
* 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.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/View/View.php
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];

Expand Down Expand Up @@ -1143,7 +1143,7 @@ public function extend($name)
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;
Expand Down

0 comments on commit 9e14905

Please sign in to comment.