浏览代码

Merge pull request #15910 from cakephp/5.0-types

Add param types.
othercorey 4 年之前
父节点
当前提交
a700c702ff

+ 1 - 1
src/Command/Helper/ProgressHelper.php

@@ -116,7 +116,7 @@ class ProgressHelper extends Helper
      * @param float|int $num The amount of progress to advance by.
      * @return $this
      */
-    public function increment($num = 1)
+    public function increment(float|int $num = 1)
     {
         $this->_progress = min(max(0, $this->_progress + $num), $this->_total);
 

+ 2 - 2
src/Console/ConsoleInputOption.php

@@ -90,7 +90,7 @@ class ConsoleInputOption
      * @param string $short The short alias for this option
      * @param string $help The help text for this option
      * @param bool $isBoolean Whether this option is a boolean option. Boolean options don't consume extra tokens
-     * @param mixed $default The default value for this option.
+     * @param string|bool|null $default The default value for this option.
      * @param array<string> $choices Valid choices for this option.
      * @param bool $multiple Whether this option can accept multiple value definition.
      * @param bool $required Whether this option is required or not.
@@ -101,7 +101,7 @@ class ConsoleInputOption
         string $short = '',
         string $help = '',
         bool $isBoolean = false,
-        $default = null,
+        string|bool|null $default = null,
         array $choices = [],
         bool $multiple = false,
         bool $required = false

+ 7 - 6
src/Utility/Filesystem.php

@@ -18,6 +18,7 @@ namespace Cake\Utility;
 
 use Cake\Core\Exception\CakeException;
 use CallbackFilterIterator;
+use Closure;
 use FilesystemIterator;
 use Iterator;
 use RecursiveCallbackFilterIterator;
@@ -47,12 +48,12 @@ class Filesystem
      * Find files / directories (non-recursively) in given directory path.
      *
      * @param string $path Directory path.
-     * @param mixed $filter If string will be used as regex for filtering using
+     * @param \Closure|string|null $filter If string will be used as regex for filtering using
      *   `RegexIterator`, if callable will be as callback for `CallbackFilterIterator`.
      * @param int|null $flags Flags for FilesystemIterator::__construct();
      * @return \Iterator
      */
-    public function find(string $path, $filter = null, ?int $flags = null): Iterator
+    public function find(string $path, Closure|string|null $filter = null, ?int $flags = null): Iterator
     {
         $flags = $flags ?? FilesystemIterator::KEY_AS_PATHNAME
             | FilesystemIterator::CURRENT_AS_FILEINFO
@@ -70,13 +71,13 @@ class Filesystem
      * Find files/ directories recursively in given directory path.
      *
      * @param string $path Directory path.
-     * @param mixed $filter If string will be used as regex for filtering using
+     * @param \Closure|string|null $filter If string will be used as regex for filtering using
      *   `RegexIterator`, if callable will be as callback for `CallbackFilterIterator`.
      *   Hidden directories (starting with dot e.g. .git) are always skipped.
      * @param int|null $flags Flags for FilesystemIterator::__construct();
      * @return \Iterator
      */
-    public function findRecursive(string $path, $filter = null, ?int $flags = null): Iterator
+    public function findRecursive(string $path, Closure|string|null $filter = null, ?int $flags = null): Iterator
     {
         $flags = $flags ?? FilesystemIterator::KEY_AS_PATHNAME
             | FilesystemIterator::CURRENT_AS_FILEINFO
@@ -110,10 +111,10 @@ class Filesystem
      * Wrap iterator in additional filtering iterator.
      *
      * @param \Iterator $iterator Iterator
-     * @param mixed $filter Regex string or callback.
+     * @param \Closure|string|null $filter Regex string or callback.
      * @return \Iterator
      */
-    protected function filterIterator(Iterator $iterator, $filter): Iterator
+    protected function filterIterator(Iterator $iterator, Closure|string|null $filter): Iterator
     {
         if (is_string($filter)) {
             return new RegexIterator($iterator, $filter);

+ 7 - 3
src/Utility/Xml.php

@@ -298,13 +298,17 @@ class Xml
      *
      * @param \DOMDocument $dom Handler to DOMDocument
      * @param \DOMDocument|\DOMElement $node Handler to DOMElement (child)
-     * @param array $data Array of data to append to the $node.
+     * @param mixed $data Array of data to append to the $node.
      * @param string $format Either 'attributes' or 'tags'. This determines where nested keys go.
      * @return void
      * @throws \Cake\Utility\Exception\XmlException
      */
-    protected static function _fromArray(DOMDocument $dom, DOMDocument|DOMElement $node, $data, string $format): void
-    {
+    protected static function _fromArray(
+        DOMDocument $dom,
+        DOMDocument|DOMElement $node,
+        mixed $data,
+        string $format
+    ): void {
         if (empty($data) || !is_array($data)) {
             return;
         }

+ 1 - 1
tests/TestCase/Console/HelpFormatterTest.php

@@ -183,7 +183,7 @@ txt;
         $parser->addOption('test', ['help' => 'A test option.'])
                ->addOption('number', [
                    'help' => 'The number',
-                   'default' => 2,
+                   'default' => '2',
                ])
                 ->addOption('connection', [
                     'short' => 'c',