Skip to content

Commit

Permalink
Solve deprecation about SourceIteratorInterface (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Feb 12, 2022
1 parent 82909ff commit 6e96dae
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/reference/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions docs/reference/sources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
3 changes: 1 addition & 2 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Sonata\Exporter;

use Sonata\Exporter\Source\SourceIteratorInterface;
use Sonata\Exporter\Writer\TypedWriterInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;

Expand Down Expand Up @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Source/ChainSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
final class ChainSourceIterator implements SourceIteratorInterface
{
/**
* @var \ArrayIterator<array-key, SourceIteratorInterface>
* @var \ArrayIterator<array-key, \Iterator>
*/
private $sources;

/**
* @param array<SourceIteratorInterface> $sources
* @param array<\Iterator> $sources
*/
public function __construct(array $sources = [])
{
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Source/SymfonySitemapSourceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class SymfonySitemapSourceIterator implements SourceIteratorInterface
private $router;

/**
* @var SourceIteratorInterface
* @var \Iterator
*/
private $source;

Expand All @@ -39,7 +39,7 @@ final class SymfonySitemapSourceIterator implements SourceIteratorInterface
private $parameters;

public function __construct(
SourceIteratorInterface $source,
\Iterator $source,
RouterInterface $router,
string $routeName,
array $parameters = []
Expand Down
3 changes: 1 addition & 2 deletions tests/ExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);
Expand Down
5 changes: 2 additions & 3 deletions tests/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 1 addition & 2 deletions tests/Source/ChainSourceIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use PHPUnit\Framework\TestCase;
use Sonata\Exporter\Source\ChainSourceIterator;
use Sonata\Exporter\Source\SourceIteratorInterface;

final class ChainSourceIteratorTest extends TestCase
{
Expand All @@ -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]);

Expand Down

0 comments on commit 6e96dae

Please sign in to comment.