From a043f9ad145a0e9cef6cf627624c2ce91758380f Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 4 Apr 2021 22:00:44 +0100 Subject: [PATCH 1/2] #663 - Add test case --- stub/issue663.zep | 35 ++++++++++++++++++++++++++++ tests/Extension/Issue663Test.php | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 stub/issue663.zep create mode 100644 tests/Extension/Issue663Test.php diff --git a/stub/issue663.zep b/stub/issue663.zep new file mode 100644 index 000000000..f594607b0 --- /dev/null +++ b/stub/issue663.zep @@ -0,0 +1,35 @@ +namespace Stub; + +class Issue663 +{ + public static function is_array_assoc(arr) -> bool + { + if (!is_array(arr) || empty(arr)) { + return false; + } + + return static::is_array_assoc_internal(arr); + } + + private static function is_array_assoc_internal(array arr) -> bool + { + int count, i; + let count = count(arr); + for i in range(0, count - 1) { + if (!isset(arr[i])) { + return true; + } + } + + return false; + } + + public static function is_array_indexed(arr) -> bool + { + if (!is_array(arr) || empty(arr)) { + return false; + } + + return !static::is_array_assoc_internal(arr); + } +} \ No newline at end of file diff --git a/tests/Extension/Issue663Test.php b/tests/Extension/Issue663Test.php new file mode 100644 index 000000000..3113d6a53 --- /dev/null +++ b/tests/Extension/Issue663Test.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Extension; + +use PHPUnit\Framework\TestCase; +use Stub\Issue663; + +final class Issue663Test extends TestCase +{ + public function testIssue663(): void + { + $test = new Issue663(); + + $this->assertFalse($test->is_array_assoc(false)); + $this->assertFalse($test->is_array_assoc(1)); + $this->assertFalse($test->is_array_assoc([])); + $this->assertTrue($test->is_array_assoc(['test' => 'test'])); + $this->assertFalse($test->is_array_assoc(['test'])); + $this->assertFalse($test->is_array_assoc([0 => 'test'])); + + $this->assertFalse($test->is_array_indexed(false)); + $this->assertFalse($test->is_array_indexed(1)); + $this->assertFalse($test->is_array_indexed([])); + $this->assertFalse($test->is_array_indexed(['test' => 'test'])); + $this->assertTrue($test->is_array_indexed(['test'])); + $this->assertTrue($test->is_array_indexed([0 => 'test'])); + } +} From 8dc6424e47e13917b6a7fd8f3debaa3ca500e85c Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 4 Apr 2021 22:02:18 +0100 Subject: [PATCH 2/2] #1187 - Add new line --- stub/issue663.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stub/issue663.zep b/stub/issue663.zep index f594607b0..2d8272ddd 100644 --- a/stub/issue663.zep +++ b/stub/issue663.zep @@ -32,4 +32,4 @@ class Issue663 return !static::is_array_assoc_internal(arr); } -} \ No newline at end of file +}