From dbff203d1e27a3b1ab66107d14b683775743d6e3 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Aug 2024 08:25:00 +0900 Subject: [PATCH 1/6] test: add test for numeric field name --- tests/system/Validation/ValidationTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index b5493a682c8e..00360f368e66 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -270,6 +270,16 @@ public function testRunDoesTheBasics(): void $this->assertSame([], $this->validation->getValidated()); } + public function testRunWithNumericFieldName(): void + { + // The array key will be int. + $data = ['123' => 'notanumber']; + $this->validation->setRules(['123' => 'is_numeric']); + + $this->assertFalse($this->validation->run($data)); + $this->assertSame([], $this->validation->getValidated()); + } + public function testClosureRule(): void { $this->validation->setRules( From 99f41ee353215dfc32d3126e10508b3fc0d08e57 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Aug 2024 08:26:35 +0900 Subject: [PATCH 2/6] fix: TypeError when there is numeric field name TypeError: str_contains(): Argument #1 ($haystack) must be of type string, int given --- system/Validation/Validation.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index bfc661c2b3d4..c183a5bb739b 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -163,6 +163,9 @@ public function run(?array $data = null, ?string $group = null, $dbGroup = null) // Run through each rule. If we have any field set for // this rule, then we need to run them through! foreach ($this->rules as $field => $setup) { + // An array key might be int. + $field = (string) $field; + $rules = $setup['rules']; if (is_string($rules)) { From 2979ece9a39977b2429b01e0ca724e46be2a994c Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Aug 2024 08:30:22 +0900 Subject: [PATCH 3/6] docs: make @var more precise --- phpstan-baseline.php | 6 ------ system/Validation/Validation.php | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index f0a882e68b01..c48093046742 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -10459,12 +10459,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Validation/Validation.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Property CodeIgniter\\\\Validation\\\\Validation\\:\\:\\$rules type has no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Validation/Validation.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Property CodeIgniter\\\\Validation\\\\Validation\\:\\:\\$validated type has no value type specified in iterable type array\\.$#', diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index c183a5bb739b..a4d817d2a9b4 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -51,7 +51,7 @@ class Validation implements ValidationInterface /** * Stores the actual rules that should be run against $data. * - * @var array + * @var array}> * * [ * field1 => [ From 90513e38ecfe750aba382f06c9c2d680e2935598 Mon Sep 17 00:00:00 2001 From: Osman Bozdag Date: Tue, 27 Aug 2024 04:49:40 +0200 Subject: [PATCH 4/6] docs: Change tags to elements and fix some typos helpers/html_helper.rst Change tags to elements and fix some typos helpers/html_helper.rst --- user_guide_src/source/helpers/html_helper.rst | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/user_guide_src/source/helpers/html_helper.rst b/user_guide_src/source/helpers/html_helper.rst index 95760b4af4da..83ce88ac5705 100644 --- a/user_guide_src/source/helpers/html_helper.rst +++ b/user_guide_src/source/helpers/html_helper.rst @@ -2,8 +2,7 @@ HTML Helper ########### -The HTML Helper file contains functions that assist in working with -HTML. +The HTML Helper file contains functions that assist in working with HTML. .. contents:: :local: @@ -31,10 +30,10 @@ The following functions are available: :param string|array $src: Image source URI, or array of attributes and values :param bool $indexPage: Whether to treat ``$src`` as a routed URI string :param mixed $attributes: Additional HTML attributes - :returns: HTML image tag + :returns: HTML image element :rtype: string - Lets you create HTML ```` tags. The first parameter contains the + Lets you create HTML ```` elements. The first parameter contains the image source. Example: .. literalinclude:: html_helper/002.php @@ -84,10 +83,10 @@ The following functions are available: :param string $media: Media type :param bool $indexPage: Whether to treat ``$src`` as a routed URI string :param string $hreflang: Hreflang type - :returns: HTML link tag + :returns: An HTML link element :rtype: string - Lets you create HTML ```` tags. This is useful for stylesheet links, + Lets you create HTML ```` elements. This is useful for stylesheet links, as well as other links. The parameters are *href*, with optional *rel*, *type*, *title*, *media* and *indexPage*. @@ -111,10 +110,10 @@ The following functions are available: :param array|string $src: The source name or URL of a JavaScript file, or an associative array specifying the attributes :param bool $indexPage: Whether to treat ``$src`` as a routed URI string - :returns: HTML script tag + :returns: An HTML script element :rtype: string - Lets you create HTML ```` tags. The parameters is *src*, with optional *indexPage*. + Lets you create HTML ```` elements. The parameters are *src* and optional *indexPage*. *indexPage* is a boolean value that specifies if the *src* should have the page specified by ``$config['indexPage']`` added to the address it creates. @@ -132,11 +131,11 @@ The following functions are available: :param array $list: List entries :param array $attributes: HTML attributes - :returns: HTML-formatted unordered list + :returns: An HTML unordered list element :rtype: string - Permits you to generate unordered HTML lists from simple or - multi-dimensional arrays. Example: + Permits you to generate an unordered HTML list from a simple or + multi-dimensional array. Example: .. literalinclude:: html_helper/012.php @@ -205,20 +204,20 @@ The following functions are available: :param array $list: List entries :param array $attributes: HTML attributes - :returns: HTML-formatted ordered list + :returns: An HTML ordered list element :rtype: string - Identical to :php:func:`ul()`, only it produces the ``
    `` tag for + Identical to :php:func:`ul()`, only it produces ``
      `` element for ordered lists instead of ``
        ``. .. php:function:: video($src[, $unsupportedMessage = ''[, $attributes = ''[, $tracks = [][, $indexPage = false]]]]) :param mixed $src: Either a source string or an array of sources. See :php:func:`source()` function - :param string $unsupportedMessage: The message to display if the media tag is not supported by the browser + :param string $unsupportedMessage: The message to display if the video element is not supported by the browser :param string $attributes: HTML attributes :param array $tracks: Use the track function inside an array. See :php:func:`track()` function :param bool $indexPage: - :returns: HTML-formatted video element + :returns: An HTML video element :rtype: string Permits you to generate HTML video element from simple or @@ -253,24 +252,24 @@ The following functions are available: .. php:function:: audio($src[, $unsupportedMessage = ''[, $attributes = ''[, $tracks = [][, $indexPage = false]]]]) :param mixed $src: Either a source string or an array of sources. See :php:func:`source()` function - :param string $unsupportedMessage: The message to display if the media tag is not supported by the browser + :param string $unsupportedMessage: The message to display if the audio element is not supported by the browser :param string $attributes: :param array $tracks: Use the track function inside an array. See :php:func:`track()` function :param bool $indexPage: - :returns: HTML-formatted audio element + :returns: An HTML audio element :rtype: string - Identical to :php:func:`video()`, only it produces the ``