diff --git a/composer.json b/composer.json index fdc822b3..b512481d 100644 --- a/composer.json +++ b/composer.json @@ -35,11 +35,11 @@ "doctrine/collections": "^2.1.2", "friendsofphp/php-cs-fixer": "^v3.14.3", "phpbench/phpbench": "^1.2.8", - "phpstan/phpstan": "^1.9.17", - "phpstan/phpstan-deprecation-rules": "^1.1.1", - "phpstan/phpstan-phpunit": "^1.3.4", - "phpstan/phpstan-strict-rules": "^1.4.5", - "phpunit/phpunit": "^10.0.7", + "phpstan/phpstan": "^1.10.0", + "phpstan/phpstan-deprecation-rules": "^1.1.2", + "phpstan/phpstan-phpunit": "^1.3.7", + "phpstan/phpstan-strict-rules": "^1.5.0", + "phpunit/phpunit": "^10.0.11", "ext-xdebug": "*" }, "autoload": { diff --git a/src/AbstractCsvTest.php b/src/AbstractCsvTest.php index f5e058cf..836dcb5a 100644 --- a/src/AbstractCsvTest.php +++ b/src/AbstractCsvTest.php @@ -21,7 +21,6 @@ use SplTempFileObject; use function chr; use function function_exists; -use function iterator_to_array; use function ob_get_clean; use function ob_start; use function strtolower; @@ -149,7 +148,6 @@ public function testChunkDoesNotTimeoutAfterReading(): void { $raw_csv = "john,doe,john.doe@example.com\njane,doe,jane.doe@example.com\n"; $csv = Reader::createFromString($raw_csv); - iterator_to_array($csv->getRecords()); self::assertSame($raw_csv, $csv->toString()); } @@ -173,8 +171,7 @@ public function testChunkTriggersException(): void { $this->expectException(InvalidArgument::class); - $chunk = $this->csv->chunk(0); - iterator_to_array($chunk); + [...$this->csv->chunk(0)]; } public function testChunk(): void diff --git a/src/CharsetConverterTest.php b/src/CharsetConverterTest.php index 2882e9ef..61278821 100644 --- a/src/CharsetConverterTest.php +++ b/src/CharsetConverterTest.php @@ -166,7 +166,7 @@ public function testItDoesNotChangeTheCSVContentIfNoBOMSequenceIsFound(): void self::assertSame( [['start end']], - iterator_to_array($reader) + [...$reader] ); } @@ -184,7 +184,7 @@ public static function testItSkipBOMSequenceBeforeConsumingTheCSVStream(string $ self::assertSame( [['start end']], - iterator_to_array($reader) + [...$reader] ); } @@ -202,7 +202,7 @@ public function testItOnlySkipOnceTheBOMSequenceBeforeConsumingTheCSVStreamOnMul self::assertSame( [[$sequence.'start end']], - iterator_to_array($reader) + [...$reader] ); } @@ -213,10 +213,7 @@ public function testItOnlySkipOnceTheBOMSequenceBeforeConsumingTheCSVStreamOnSin CharsetConverter::addBOMSkippingTo($reader); $reader->includeInputBOM(); - self::assertSame( - [[$sequence.'start', $sequence.'end']], - iterator_to_array($reader) - ); + self::assertSame([[$sequence.'start', $sequence.'end']], [...$reader]); } public static function providesBOMSequences(): iterable diff --git a/src/MapIteratorTest.php b/src/MapIteratorTest.php index dc844b12..54425fc0 100644 --- a/src/MapIteratorTest.php +++ b/src/MapIteratorTest.php @@ -30,7 +30,7 @@ public function testMapIteratorCanActLikeArrayMapWithOneArray(): void self::assertSame( array_map($mapper, $array), - iterator_to_array(new MapIterator($iterator, $mapper), true) + [...new MapIterator($iterator, $mapper)] ); } diff --git a/src/Reader.php b/src/Reader.php index 4f8d3bda..b6076fb6 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -25,7 +25,6 @@ use function count; use function is_array; use function iterator_count; -use function iterator_to_array; use function mb_strlen; use function mb_substr; use function strlen; @@ -235,7 +234,7 @@ public function getIterator(): Iterator */ public function jsonSerialize(): array { - return iterator_to_array($this->getRecords(), false); + return array_values([...$this->getRecords()]); } /** diff --git a/src/ReaderTest.php b/src/ReaderTest.php index 237d98f9..989b48a4 100644 --- a/src/ReaderTest.php +++ b/src/ReaderTest.php @@ -187,7 +187,7 @@ public function testHeaderThrowsIfItContainsNonStringNames(): void { $this->expectException(SyntaxError::class); - iterator_to_array($this->csv->getRecords(['field1', 2, 'field3'])); + [...$this->csv->getRecords(['field1', 2, 'field3'])]; } #[DataProvider('validBOMSequences')] diff --git a/src/ResultSet.php b/src/ResultSet.php index 45d9a36c..dd819e06 100644 --- a/src/ResultSet.php +++ b/src/ResultSet.php @@ -23,7 +23,6 @@ use function array_search; use function is_string; use function iterator_count; -use function iterator_to_array; /** * Represents the result set of a {@link Reader} processed by a {@link Statement}. @@ -138,7 +137,7 @@ public function count(): int public function jsonSerialize(): array { - return iterator_to_array($this->records, false); + return array_values([...$this->records]); } /** diff --git a/src/ResultSetTest.php b/src/ResultSetTest.php index 2658176d..f90affea 100644 --- a/src/ResultSetTest.php +++ b/src/ResultSetTest.php @@ -20,7 +20,6 @@ use SplTempFileObject; use function current; use function in_array; -use function iterator_to_array; use function json_encode; use function next; @@ -67,10 +66,7 @@ public function testFilter(): void $result2 = $stmt->where($func2)->process($result1, ['foo', 'bar']); $result3 = $stmt->where($func2)->process($result2, ['foo', 'bar']); - self::assertNotContains( - ['jane', 'doe', 'jane.doe@example.com'], - iterator_to_array($result1, false) - ); + self::assertNotContains(['jane', 'doe', 'jane.doe@example.com'], [...$result1]); self::assertCount(0, $result2); self::assertEquals($result3, $result2); @@ -82,13 +78,14 @@ public function testFetchColumnTriggersException(int|string $field): void $this->expectException(InvalidArgument::class); $this->csv->setHeaderOffset(0); + $resultSet = $this->stmt->process($this->csv); if (is_int($field)) { - iterator_to_array($this->stmt->process($this->csv)->fetchColumnByOffset($field), false); + [...$resultSet->fetchColumnByOffset($field)]; return; } - iterator_to_array($this->stmt->process($this->csv)->fetchColumnByName($field), false); + [...$resultSet->fetchColumnByName($field)]; } public static function invalidFieldNameProvider(): array @@ -104,8 +101,7 @@ public function testFetchColumnTriggersOutOfRangeException(): void $this->expectException(InvalidArgument::class); $this->csv->setHeaderOffset(0); - $res = $this->stmt->process($this->csv)->fetchColumnByOffset(-1); - iterator_to_array($res, false); + [...$this->stmt->process($this->csv)->fetchColumnByOffset(-1)]; } public function testFetchColumn(): void @@ -119,10 +115,7 @@ public function testFetchColumnByNameTriggersException(): void $this->expectException(InvalidArgument::class); $this->csv->setHeaderOffset(0); - iterator_to_array( - $this->stmt->process($this->csv)->fetchColumnByName('foobar'), - false - ); + [...$this->stmt->process($this->csv)->fetchColumnByName('foobar')]; } public function testFetchColumnByOffsetTriggersException(): void @@ -130,10 +123,7 @@ public function testFetchColumnByOffsetTriggersException(): void $this->expectException(InvalidArgument::class); $this->csv->setHeaderOffset(0); - iterator_to_array( - $this->stmt->process($this->csv)->fetchColumnByOffset(24), - false - ); + [...$this->stmt->process($this->csv)->fetchColumnByOffset(24)]; } public function testFetchColumnByOffsetTriggersOutOfRangeException(): void @@ -142,10 +132,7 @@ public function testFetchColumnByOffsetTriggersOutOfRangeException(): void $this->csv->setHeaderOffset(0); - iterator_to_array( - $this->stmt->process($this->csv)->fetchColumnByOffset(-1), - false - ); + [...$this->stmt->process($this->csv)->fetchColumnByOffset(-1)]; } public function testFetchAssocWithRowIndex(): void @@ -166,7 +153,7 @@ public function testFetchAssocWithRowIndex(): void $csv->setHeaderOffset(2); self::assertContains( ['D' => '6', 'E' => '7', 'F' => '8'], - iterator_to_array($this->stmt->process($csv), false) + [...$this->stmt->process($csv)] ); } @@ -194,7 +181,7 @@ public function testFetchColumnInconsistentColumnCSV(): void $csv = Reader::createFromFileObject($file); $res = $this->stmt->process($csv)->fetchColumnByOffset(2); - self::assertCount(1, iterator_to_array($res)); + self::assertCount(1, [...$res]); } public function testFetchColumnEmptyCol(): void @@ -210,7 +197,7 @@ public function testFetchColumnEmptyCol(): void } $csv = Reader::createFromFileObject($file); $res = $this->stmt->process($csv)->fetchColumnByOffset(2); - self::assertCount(0, iterator_to_array($res)); + self::assertCount(0, [...$res]); } public function testfetchOne(): void @@ -261,7 +248,7 @@ public static function fetchPairsDataProvider(): array public function testFetchPairsWithInvalidOffset(): void { - self::assertCount(0, iterator_to_array($this->stmt->process($this->csv)->fetchPairs(10, 1), true)); + self::assertCount(0, [...$this->stmt->process($this->csv)->fetchPairs(10, 1)]); } public function testFetchPairsWithInvalidValue(): void diff --git a/src/Statement.php b/src/Statement.php index a42be412..9587cb49 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -160,7 +160,7 @@ protected function buildOrderBy(Iterator $iterator): Iterator }; /** @var ArrayIterator> $it */ - $it = new ArrayIterator(iterator_to_array($iterator)); + $it = new ArrayIterator([...$iterator]); $it->uasort($compare); return $it; diff --git a/src/StatementTest.php b/src/StatementTest.php index e777147e..cad084f3 100644 --- a/src/StatementTest.php +++ b/src/StatementTest.php @@ -20,7 +20,6 @@ use SplTempFileObject; use function array_reverse; use function in_array; -use function iterator_to_array; use function strcmp; use function strlen; @@ -108,10 +107,7 @@ public function testIntervalThrowException(): void { $this->expectException(OutOfBoundsException::class); - iterator_to_array($this->stmt - ->offset(1) - ->limit(0) - ->process($this->csv)); + [...$this->stmt->offset(1)->limit(0)->process($this->csv)]; } public function testFilter(): void @@ -124,10 +120,7 @@ public function testFilter(): void $result2 = $stmt->where($func2)->process($result1, ['foo', 'bar']); $result3 = $stmt->where($func2)->process($result2, ['foo', 'bar']); - self::assertNotContains( - ['jane', 'doe', 'jane.doe@example.com'], - iterator_to_array($result1, false) - ); + self::assertNotContains(['jane', 'doe', 'jane.doe@example.com'], [...$result1]); self::assertCount(0, $result2); self::assertEquals($result3, $result2); @@ -139,7 +132,7 @@ public function testOrderBy(): void ->orderBy(fn (array $rowA, array $rowB): int => strcmp($rowA[0], $rowB[0])) ->process($this->csv); - self::assertSame(array_reverse($this->expected), iterator_to_array($calculated, false)); + self::assertSame(array_reverse($this->expected), array_values([...$calculated])); } public function testOrderByWithEquity(): void @@ -148,6 +141,6 @@ public function testOrderByWithEquity(): void ->orderBy(fn (array $rowA, array $rowB): int => strlen($rowA[0]) <=> strlen($rowB[0])) ->process($this->csv); - self::assertSame($this->expected, iterator_to_array($calculated, false)); + self::assertSame($this->expected, array_values([...$calculated])); } }