From 6e96dae678890d34552ec9398ecbf9521eef62f3 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 12 Feb 2022 15:30:09 +0100 Subject: [PATCH] Solve deprecation about SourceIteratorInterface (#573) --- docs/reference/introduction.rst | 2 +- docs/reference/sources.rst | 3 +-- src/Exporter.php | 3 +-- src/Handler.php | 7 +++---- src/Source/ChainSourceIterator.php | 6 +++--- src/Source/SymfonySitemapSourceIterator.php | 4 ++-- tests/ExporterTest.php | 3 +-- tests/HandlerTest.php | 5 ++--- tests/Source/ChainSourceIteratorTest.php | 3 +-- 9 files changed, 15 insertions(+), 21 deletions(-) diff --git a/docs/reference/introduction.rst b/docs/reference/introduction.rst index fc0f13f6..aff2981d 100644 --- a/docs/reference/introduction.rst +++ b/docs/reference/introduction.rst @@ -10,7 +10,7 @@ Usage .. code-block:: php - // This can be any instance of SourceIteratorInterface + // This can be any instance of \Iterator $source = new ArraySourceIterator([/* your data */]); // This could be any format supported diff --git a/docs/reference/sources.rst b/docs/reference/sources.rst index 5b21b5aa..f031a0a2 100644 --- a/docs/reference/sources.rst +++ b/docs/reference/sources.rst @@ -17,5 +17,4 @@ You may export data from various sources: * Sitemap (Takes another iterator) * Chain (can aggregate data from several different iterators) -You may also create your own. To do so, create a class that implements ``Exporter\Source\SourceIteratorInterface``. - +You may also create your own. To do so, create a class that implements ``\Iterator``. diff --git a/src/Exporter.php b/src/Exporter.php index 8c951fc7..8549e6a0 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -13,7 +13,6 @@ namespace Sonata\Exporter; -use Sonata\Exporter\Source\SourceIteratorInterface; use Sonata\Exporter\Writer\TypedWriterInterface; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -42,7 +41,7 @@ public function __construct(array $writers = []) /** * @throws \RuntimeException */ - public function getResponse(string $format, string $filename, SourceIteratorInterface $source): StreamedResponse + public function getResponse(string $format, string $filename, \Iterator $source): StreamedResponse { if (!\array_key_exists($format, $this->writers)) { throw new \RuntimeException(sprintf( diff --git a/src/Handler.php b/src/Handler.php index 2848c41e..681482bc 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -13,13 +13,12 @@ namespace Sonata\Exporter; -use Sonata\Exporter\Source\SourceIteratorInterface; use Sonata\Exporter\Writer\WriterInterface; final class Handler { /** - * @var SourceIteratorInterface + * @var \Iterator */ private $source; @@ -28,7 +27,7 @@ final class Handler */ private $writer; - public function __construct(SourceIteratorInterface $source, WriterInterface $writer) + public function __construct(\Iterator $source, WriterInterface $writer) { $this->source = $source; $this->writer = $writer; @@ -45,7 +44,7 @@ public function export(): void $this->writer->close(); } - public static function create(SourceIteratorInterface $source, WriterInterface $writer): self + public static function create(\Iterator $source, WriterInterface $writer): self { return new self($source, $writer); } diff --git a/src/Source/ChainSourceIterator.php b/src/Source/ChainSourceIterator.php index b9e5ac91..17d0af08 100644 --- a/src/Source/ChainSourceIterator.php +++ b/src/Source/ChainSourceIterator.php @@ -16,12 +16,12 @@ final class ChainSourceIterator implements SourceIteratorInterface { /** - * @var \ArrayIterator + * @var \ArrayIterator */ private $sources; /** - * @param array $sources + * @param array<\Iterator> $sources */ public function __construct(array $sources = []) { @@ -32,7 +32,7 @@ public function __construct(array $sources = []) } } - public function addSource(SourceIteratorInterface $source): void + public function addSource(\Iterator $source): void { $this->sources->append($source); } diff --git a/src/Source/SymfonySitemapSourceIterator.php b/src/Source/SymfonySitemapSourceIterator.php index eadc1244..a2d11be8 100644 --- a/src/Source/SymfonySitemapSourceIterator.php +++ b/src/Source/SymfonySitemapSourceIterator.php @@ -24,7 +24,7 @@ final class SymfonySitemapSourceIterator implements SourceIteratorInterface private $router; /** - * @var SourceIteratorInterface + * @var \Iterator */ private $source; @@ -39,7 +39,7 @@ final class SymfonySitemapSourceIterator implements SourceIteratorInterface private $parameters; public function __construct( - SourceIteratorInterface $source, + \Iterator $source, RouterInterface $router, string $routeName, array $parameters = [] diff --git a/tests/ExporterTest.php b/tests/ExporterTest.php index 18b5bbf5..bbd5bdcc 100644 --- a/tests/ExporterTest.php +++ b/tests/ExporterTest.php @@ -16,7 +16,6 @@ use PHPUnit\Framework\TestCase; use Sonata\Exporter\Exporter; use Sonata\Exporter\Source\ArraySourceIterator; -use Sonata\Exporter\Source\SourceIteratorInterface; use Sonata\Exporter\Writer\CsvWriter; use Sonata\Exporter\Writer\JsonWriter; use Sonata\Exporter\Writer\TypedWriterInterface; @@ -30,7 +29,7 @@ public function testFilter(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Invalid "foo" format'); - $source = $this->createMock(SourceIteratorInterface::class); + $source = $this->createMock(\Iterator::class); $writer = $this->createMock(TypedWriterInterface::class); $exporter = new Exporter([$writer]); diff --git a/tests/HandlerTest.php b/tests/HandlerTest.php index 72b5cb77..6e8eb6c0 100644 --- a/tests/HandlerTest.php +++ b/tests/HandlerTest.php @@ -11,18 +11,17 @@ * file that was distributed with this source code. */ -namespace Sonata\Exporter\Test; +namespace Sonata\Exporter\Tests; use PHPUnit\Framework\TestCase; use Sonata\Exporter\Handler; -use Sonata\Exporter\Source\SourceIteratorInterface; use Sonata\Exporter\Writer\WriterInterface; final class HandlerTest extends TestCase { public function testHandler(): void { - $source = $this->createMock(SourceIteratorInterface::class); + $source = $this->createMock(\Iterator::class); $writer = $this->createMock(WriterInterface::class); $writer->expects(static::once())->method('open'); $writer->expects(static::once())->method('close'); diff --git a/tests/Source/ChainSourceIteratorTest.php b/tests/Source/ChainSourceIteratorTest.php index 93053a6c..74b2e630 100644 --- a/tests/Source/ChainSourceIteratorTest.php +++ b/tests/Source/ChainSourceIteratorTest.php @@ -15,7 +15,6 @@ use PHPUnit\Framework\TestCase; use Sonata\Exporter\Source\ChainSourceIterator; -use Sonata\Exporter\Source\SourceIteratorInterface; final class ChainSourceIteratorTest extends TestCase { @@ -24,7 +23,7 @@ final class ChainSourceIteratorTest extends TestCase */ public function testIterator(): void { - $source = $this->createMock(SourceIteratorInterface::class); + $source = $this->createMock(\Iterator::class); $iterator = new ChainSourceIterator([$source]);