Browse Source

Document the arrays more precisely.

mscherer 4 years ago
parent
commit
060ecc9e1b

+ 1 - 1
src/Command/PluginAssetsTrait.php

@@ -47,7 +47,7 @@ trait PluginAssetsTrait
      *
      * @param string|null $name Name of plugin for which to symlink assets.
      *   If null all plugins will be processed.
-     * @return array List of plugins with meta data.
+     * @return array<string, mixed> List of plugins with meta data.
      */
     protected function _list(?string $name = null): array
     {

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

@@ -81,7 +81,7 @@ class MysqlSchemaDialect extends SchemaDialect
      * The returned type will be a type that Cake\Database\TypeFactory can handle.
      *
      * @param string $column The column type + length
-     * @return array Array of column information.
+     * @return array<string, mixed> Array of column information.
      * @throws \Cake\Database\Exception\DatabaseException When column type cannot be parsed.
      */
     protected function _convertColumn(string $column): array

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

@@ -48,7 +48,7 @@ class SqliteSchemaDialect extends SchemaDialect
      *
      * @param string $column The column type + length
      * @throws \Cake\Database\Exception\DatabaseException when unable to parse column type
-     * @return array Array of column information.
+     * @return array<string, mixed> Array of column information.
      */
     protected function _convertColumn(string $column): array
     {

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

@@ -81,7 +81,7 @@ class SqlserverSchemaDialect extends SchemaDialect
      * @param int|null $length the column length
      * @param int|null $precision The column precision
      * @param int|null $scale The column scale
-     * @return array Array of column information.
+     * @return array<string, mixed> Array of column information.
      * @link https://technet.microsoft.com/en-us/library/ms187752.aspx
      */
     protected function _convertColumn(

+ 8 - 6
src/Database/SchemaCache.php

@@ -51,12 +51,13 @@ class SchemaCache
      * Build metadata.
      *
      * @param string|null $name The name of the table to build cache data for.
-     * @return array Returns a list build table caches
+     * @return array<string> Returns a list build table caches
      */
     public function build(?string $name = null): array
     {
-        $tables = [$name];
-        if (empty($name)) {
+        if ($name) {
+            $tables = [$name];
+        } else {
             $tables = $this->_schema->listTables();
         }
 
@@ -72,12 +73,13 @@ class SchemaCache
      * Clear metadata.
      *
      * @param string|null $name The name of the table to clear cache data for.
-     * @return array Returns a list of cleared table caches
+     * @return array<string> Returns a list of cleared table caches
      */
     public function clear(?string $name = null): array
     {
-        $tables = [$name];
-        if (empty($name)) {
+        if ($name) {
+            $tables = [$name];
+        } else {
             $tables = $this->_schema->listTables();
         }
 

+ 1 - 1
src/Datasource/ConnectionManager.php

@@ -110,7 +110,7 @@ class ConnectionManager
      * Note that query-string arguments are also parsed and set as values in the returned configuration.
      *
      * @param string $config The DSN string to convert to a configuration array
-     * @return array The configuration array to be stored after parsing the DSN
+     * @return array<string, mixed> The configuration array to be stored after parsing the DSN
      */
     public static function parseDsn(string $config): array
     {

+ 18 - 18
src/Datasource/Paginator.php

@@ -251,9 +251,9 @@ class Paginator implements PaginatorInterface
     /**
      * Build pagination params.
      *
-     * @param array $data Paginator data containing keys 'options',
+     * @param array<string, mixed> $data Paginator data containing keys 'options',
      *   'count', 'defaults', 'finder', 'numResults'.
-     * @return array Paging params.
+     * @return array<string, mixed> Paging params.
      */
     protected function buildParams(array $data): array
     {
@@ -284,9 +284,9 @@ class Paginator implements PaginatorInterface
     /**
      * Add "page" and "pageCount" params.
      *
-     * @param array $params Paging params.
+     * @param array<string, mixed> $params Paging params.
      * @param array $data Paginator data.
-     * @return array Updated params.
+     * @return array<string, mixed> Updated params.
      */
     protected function addPageCountParams(array $params, array $data): array
     {
@@ -309,9 +309,9 @@ class Paginator implements PaginatorInterface
     /**
      * Add "start" and "end" params.
      *
-     * @param array $params Paging params.
+     * @param array<string, mixed> $params Paging params.
      * @param array $data Paginator data.
-     * @return array Updated params.
+     * @return array<string, mixed> Updated params.
      */
     protected function addStartEndParams(array $params, array $data): array
     {
@@ -331,9 +331,9 @@ class Paginator implements PaginatorInterface
     /**
      * Add "prevPage" and "nextPage" params.
      *
-     * @param array $params Paginator params.
+     * @param array<string, mixed> $params Paginator params.
      * @param array $data Paging data.
-     * @return array Updated params.
+     * @return array<string, mixed> Updated params.
      */
     protected function addPrevNextParams(array $params, array $data): array
     {
@@ -350,9 +350,9 @@ class Paginator implements PaginatorInterface
     /**
      * Add sorting / ordering params.
      *
-     * @param array $params Paginator params.
+     * @param array<string, mixed> $params Paginator params.
      * @param array $data Paging data.
-     * @return array Updated params.
+     * @return array<string, mixed> Updated params.
      */
     protected function addSortingParams(array $params, array $data): array
     {
@@ -459,9 +459,9 @@ class Paginator implements PaginatorInterface
      * combined together. You can change config value `allowedParameters` to modify
      * which options/values can be set using request parameters.
      *
-     * @param array $params Request params.
+     * @param array<string, mixed> $params Request params.
      * @param array $settings The settings to merge with the request data.
-     * @return array Array of merged options.
+     * @return array<string, mixed> Array of merged options.
      */
     public function mergeOptions(array $params, array $settings): array
     {
@@ -481,8 +481,8 @@ class Paginator implements PaginatorInterface
      * repository, the general settings will be used.
      *
      * @param string $alias Model name to get settings for.
-     * @param array $settings The settings which is used for combining.
-     * @return array An array of pagination settings for a model,
+     * @param array<string, mixed> $settings The settings which is used for combining.
+     * @return array<string, mixed> An array of pagination settings for a model,
      *   or the general settings.
      */
     public function getDefaults(string $alias, array $settings): array
@@ -530,7 +530,7 @@ class Paginator implements PaginatorInterface
      *
      * @param \Cake\Datasource\RepositoryInterface $object Repository object.
      * @param array<string, mixed> $options The pagination options being used for this request.
-     * @return array An array of options with sort + direction removed and
+     * @return array<string, mixed> An array of options with sort + direction removed and
      *   replaced with order if possible.
      */
     public function validateSort(RepositoryInterface $object, array $options): array
@@ -593,9 +593,9 @@ class Paginator implements PaginatorInterface
     /**
      * Remove alias if needed.
      *
-     * @param array $fields Current fields
+     * @param array<string, mixed> $fields Current fields
      * @param string $model Current model alias
-     * @return array $fields Unaliased fields where applicable
+     * @return array<string, mixed> $fields Unaliased fields where applicable
      */
     protected function _removeAliases(array $fields, string $model): array
     {
@@ -664,7 +664,7 @@ class Paginator implements PaginatorInterface
      * Check the limit parameter and ensure it's within the maxLimit bounds.
      *
      * @param array<string, mixed> $options An array of options with a limit key to be checked.
-     * @return array An array of options for pagination.
+     * @return array<string, mixed> An array of options for pagination.
      */
     public function checkLimit(array $options): array
     {

+ 1 - 1
src/Error/Debugger.php

@@ -506,7 +506,7 @@ class Debugger
      * @param string $file Absolute path to a PHP file.
      * @param int $line Line number to highlight.
      * @param int $context Number of lines of context to extract above and below $line.
-     * @return array Set of lines highlighted
+     * @return array<string> Set of lines highlighted
      * @see https://secure.php.net/highlight_string
      * @link https://book.cakephp.org/4/en/development/debugging.html#getting-an-excerpt-from-a-file
      */

+ 2 - 2
src/Filesystem/File.php

@@ -45,7 +45,7 @@ class File
     /**
      * File info
      *
-     * @var array
+     * @var array<string, mixed>
      * https://book.cakephp.org/4/en/core-libraries/file-folder.html#Cake\Filesystem\File::$info
      */
     public $info = [];
@@ -297,7 +297,7 @@ class File
      * - filesize
      * - mime
      *
-     * @return array File information.
+     * @return array<string, mixed> File information.
      */
     public function info(): array
     {

+ 1 - 1
src/Filesystem/Folder.php

@@ -257,7 +257,7 @@ class Folder
      *
      * @param string $regexpPattern Preg_match pattern (Defaults to: .*)
      * @param string|bool $sort Whether results should be sorted.
-     * @return array Files that match given pattern
+     * @return array<string> Files that match given pattern
      */
     public function find(string $regexpPattern = '.*', $sort = false): array
     {

+ 1 - 1
src/Form/FormProtector.php

@@ -380,7 +380,7 @@ class FormProtector
      *
      * @param string $url Form URL.
      * @param string $sessionId Session Id.
-     * @return array The token data.
+     * @return array<string, mixed> The token data.
      * @psalm-return array{fields: string, unlocked: string, debug: string}
      */
     public function buildTokenData(string $url = '', string $sessionId = ''): array

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

@@ -265,7 +265,7 @@ class CookieCollection implements IteratorAggregate, Countable
      * @param string $scheme The http scheme to match
      * @param string $host The host to match.
      * @param string $path The path to match
-     * @return array An array of cookie name/value pairs
+     * @return array<string, mixed> An array of cookie name/value pairs
      */
     protected function findMatchingCookies(string $scheme, string $host, string $path): array
     {

+ 2 - 2
src/Http/Cookie/CookieInterface.php

@@ -241,14 +241,14 @@ interface CookieInterface
     /**
      * Get cookie options
      *
-     * @return array
+     * @return array<string, mixed>
      */
     public function getOptions(): array;
 
     /**
      * Get cookie data as array.
      *
-     * @return array With keys `name`, `value`, `expires` etc. options.
+     * @return array<string, mixed> With keys `name`, `value`, `expires` etc. options.
      */
     public function toArray(): array;
 

+ 1 - 1
src/Http/ServerRequest.php

@@ -304,7 +304,7 @@ class ServerRequest implements ServerRequestInterface
      * `query` option is also updated based on URL's querystring.
      *
      * @param array<string, mixed> $config Config array.
-     * @return array Update config.
+     * @return array<string, mixed> Update config.
      */
     protected function processUrlOption(array $config): array
     {

+ 1 - 1
src/I18n/RelativeTimeFormatter.php

@@ -395,7 +395,7 @@ class RelativeTimeFormatter implements DifferenceFormatterInterface
      *
      * @param array<string, mixed> $options The options provided by the user.
      * @param string $class The class name to use for defaults.
-     * @return array Options with defaults applied.
+     * @return array<string, mixed> Options with defaults applied.
      * @psalm-param class-string<\Cake\I18n\FrozenDate>|class-string<\Cake\I18n\FrozenTime> $class
      */
     protected function _options(array $options, string $class): array

+ 3 - 3
src/Mailer/Message.php

@@ -257,7 +257,7 @@ class Message implements JsonSerializable, Serializable
      *
      * Only absolute paths
      *
-     * @var array
+     * @var array<string, mixed>
      */
     protected $attachments = [];
 
@@ -1217,7 +1217,7 @@ class Message implements JsonSerializable, Serializable
     /**
      * Gets attachments to the email message.
      *
-     * @return array Array of attachments.
+     * @return array<string, mixed> Array of attachments.
      */
     public function getAttachments(): array
     {
@@ -1606,7 +1606,7 @@ class Message implements JsonSerializable, Serializable
      *
      * @param string|null $message Message to wrap
      * @param int $wrapLength The line length
-     * @return array Wrapped message
+     * @return array<string> Wrapped message
      */
     protected function wrap(?string $message = null, int $wrapLength = self::LINE_LENGTH_MUST): array
     {

+ 1 - 1
src/Mailer/Renderer.php

@@ -49,7 +49,7 @@ class Renderer
      *
      * @param string $content The content.
      * @param array<string> $types Content types to render. Valid array values are Message::MESSAGE_HTML, Message::MESSAGE_TEXT.
-     * @return array The rendered content with "html" and/or "text" keys.
+     * @return array<string, mixed> The rendered content with "html" and/or "text" keys.
      * @psalm-param array<\Cake\Mailer\Message::MESSAGE_HTML|\Cake\Mailer\Message::MESSAGE_TEXT> $types
      * @psalm-return array{html?: string, text?: string}
      */

+ 1 - 1
src/ORM/Association/Loader/SelectLoader.php

@@ -426,7 +426,7 @@ class SelectLoader
      * that need to be present to ensure the correct association data is loaded.
      *
      * @param \Cake\ORM\Query $query The query to get fields from.
-     * @return array The list of fields for the subquery.
+     * @return array<string, mixed> The list of fields for the subquery.
      */
     protected function _subqueryFields(Query $query): array
     {

+ 1 - 1
src/ORM/Rule/LinkConstraint.php

@@ -128,7 +128,7 @@ class LinkConstraint
      *
      * @param array<string> $fields The fields that should be aliased.
      * @param \Cake\ORM\Table $source The object to use for aliasing.
-     * @return array The aliased fields
+     * @return array<string> The aliased fields
      */
     protected function _aliasFields(array $fields, Table $source): array
     {

+ 2 - 2
src/Routing/Router.php

@@ -114,7 +114,7 @@ class Router
     /**
      * Named expressions
      *
-     * @var array
+     * @var array<string, string>
      */
     protected static $_namedExpressions = [
         'Action' => Router::ACTION,
@@ -182,7 +182,7 @@ class Router
     /**
      * Gets the named route patterns for use in config/routes.php
      *
-     * @return array Named route elements
+     * @return array<string, string> Named route elements
      * @see \Cake\Routing\Router::$_namedExpressions
      */
     public static function getNamedExpressions(): array

+ 3 - 3
src/Shell/Task/CommandTask.php

@@ -69,7 +69,7 @@ class CommandTask extends Shell
      * @param string $path The path to look in.
      * @param string $key The key to add shells to
      * @param array<string> $skip A list of commands to exclude.
-     * @return array The updated list of shells.
+     * @return array<string, mixed> The updated list of shells.
      */
     protected function _findShells(array $shellList, string $path, string $key, array $skip): array
     {
@@ -85,7 +85,7 @@ class CommandTask extends Shell
      * @param array<string> $shells The shell names.
      * @param array<string, mixed> $shellList List of shells.
      * @param array<string> $skip List of command names to skip.
-     * @return array The updated $shellList
+     * @return array<string, mixed> The updated $shellList
      */
     protected function _appendShells(string $type, array $shells, array $shellList, array $skip): array
     {
@@ -107,7 +107,7 @@ class CommandTask extends Shell
      * should be within them.
      *
      * @param string $dir The directory to read.
-     * @return array The list of shell classnames based on conventions.
+     * @return array<string> The list of shell classnames based on conventions.
      */
     protected function _scanDir(string $dir): array
     {

+ 1 - 1
src/View/Helper.php

@@ -146,7 +146,7 @@ class Helper implements EventListenerInterface
      * @param array<string, mixed> $options Array options/attributes to add a class to
      * @param string $class The class name being added.
      * @param string $key the key to use for class. Defaults to `'class'`.
-     * @return array Array of options with $key set.
+     * @return array<string, mixed> Array of options with $key set.
      */
     public function addClass(array $options, string $class, string $key = 'class'): array
     {

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

@@ -1224,7 +1224,7 @@ class FormHelper extends Helper
      *
      * @param string $fieldName The name of the field to parse options for.
      * @param array<string, mixed> $options Options list.
-     * @return array Options
+     * @return array<string, mixed> Options
      */
     protected function _parseOptions(string $fieldName, array $options): array
     {
@@ -1331,9 +1331,9 @@ class FormHelper extends Helper
      *
      * @param string $fieldName The name of the field to generate options for.
      * @param array<string, mixed> $options Options list.
-     * @param bool $allowOverride Whether or not it is allowed for this method to
+     * @param bool $allowOverride Whether it is allowed for this method to
      * overwrite the 'type' key in options.
-     * @return array
+     * @return array<string, mixed>
      */
     protected function _magicOptions(string $fieldName, array $options, bool $allowOverride): array
     {
@@ -1364,7 +1364,7 @@ class FormHelper extends Helper
      *
      * @param string $fieldName The name of the field to generate options for.
      * @param array<string, mixed> $options Options list.
-     * @return array Modified options list.
+     * @return array<string, mixed> Modified options list.
      */
     protected function setRequiredAndCustomValidity(string $fieldName, array $options)
     {
@@ -2273,7 +2273,7 @@ class FormHelper extends Helper
      *
      * @param string $field Name of the field to initialize options for.
      * @param array<string, mixed>|array<string> $options Array of options to append options into.
-     * @return array Array of options for the input.
+     * @return array<string, mixed> Array of options for the input.
      */
     protected function _initInputField(string $field, array $options = []): array
     {

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

@@ -814,7 +814,7 @@ class PaginatorHelper extends Helper
     /**
      * Calculates the start and end for the pagination numbers.
      *
-     * @param array $params Params from the numbers() method.
+     * @param array<string, mixed> $params Params from the numbers() method.
      * @param array<string, mixed> $options Options from the numbers() method.
      * @return array An array with the start and end numbers.
      * @psalm-return array{0: int, 1: int}

+ 4 - 4
src/View/Widget/BasicWidget.php

@@ -115,7 +115,7 @@ class BasicWidget implements WidgetInterface
      *
      * @param array<string, mixed> $data Data array
      * @param \Cake\View\Form\ContextInterface $context Context instance.
-     * @return array Updated data array.
+     * @return array<string, mixed> Updated data array.
      */
     protected function mergeDefaults(array $data, ContextInterface $context): array
     {
@@ -134,7 +134,7 @@ class BasicWidget implements WidgetInterface
      * @param array<string, mixed> $data Data array
      * @param \Cake\View\Form\ContextInterface $context Context instance.
      * @param string $fieldName Field name.
-     * @return array Updated data array.
+     * @return array<string, mixed> Updated data array.
      */
     protected function setRequired(array $data, ContextInterface $context, string $fieldName): array
     {
@@ -160,7 +160,7 @@ class BasicWidget implements WidgetInterface
      * @param array<string, mixed> $data Data array
      * @param \Cake\View\Form\ContextInterface $context Context instance.
      * @param string $fieldName Field name.
-     * @return array Updated data array.
+     * @return array<string, mixed> Updated data array.
      */
     protected function setMaxLength(array $data, ContextInterface $context, string $fieldName): array
     {
@@ -178,7 +178,7 @@ class BasicWidget implements WidgetInterface
      * @param array<string, mixed> $data Data array
      * @param \Cake\View\Form\ContextInterface $context Context instance.
      * @param string $fieldName Field name.
-     * @return array Updated data array.
+     * @return array<string, mixed> Updated data array.
      */
     protected function setStep(array $data, ContextInterface $context, string $fieldName): array
     {

+ 1 - 1
src/View/Widget/DateTimeWidget.php

@@ -138,7 +138,7 @@ class DateTimeWidget extends BasicWidget
      * @param array<string, mixed> $data Data array
      * @param \Cake\View\Form\ContextInterface $context Context instance.
      * @param string $fieldName Field name.
-     * @return array Updated data array.
+     * @return array<string, mixed> Updated data array.
      */
     protected function setStep(array $data, ContextInterface $context, string $fieldName): array
     {