Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove checks for Symfony's DI Container #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"phpunit/phpunit": "^8.5|^9.0",
"psr/container": "^1.0",
"symfony/cache" : "^3.1|^4.0|^5.0",
"symfony/dependency-injection" : "^3.1|^4.0|^5.0",
"mikey179/vfsstream": "^1.6.7"
},
"autoload": {
Expand Down
11 changes: 5 additions & 6 deletions src/Driver/LazyLoadingDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
namespace Metadata\Driver;

use Metadata\ClassMetadata;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Container\ContainerInterface;

class LazyLoadingDriver implements DriverInterface
{
/**
* @var ContainerInterface|PsrContainerInterface
* @var ContainerInterface
*/
private $container;

Expand All @@ -21,12 +20,12 @@ class LazyLoadingDriver implements DriverInterface
private $realDriverId;

/**
* @param ContainerInterface|PsrContainerInterface $container
* @param ContainerInterface $container
*/
public function __construct($container, string $realDriverId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just use a native php type hint here?

Suggested change
public function __construct($container, string $realDriverId)
public function __construct(ContainerInterface $container, string $realDriverId)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically adding a typehint is a B/C break, though the typehint would match up with the runtime check in the constructor (it just changes the error type). If it’s OK with the maintainers, we can add the typehint and remove the inline check.

{
if (!$container instanceof PsrContainerInterface && !$container instanceof ContainerInterface) {
throw new \InvalidArgumentException(sprintf('The container must be an instance of %s or %s (%s given).', PsrContainerInterface::class, ContainerInterface::class, \is_object($container) ? \get_class($container) : \gettype($container)));
if (!$container instanceof ContainerInterface) {
throw new \InvalidArgumentException(sprintf('The container must be an instance of %s (%s given).', ContainerInterface::class, \is_object($container) ? \get_class($container) : \gettype($container)));
}

$this->container = $container;
Expand Down
17 changes: 0 additions & 17 deletions tests/Driver/LazyLoadingDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;

class LazyLoadingDriverTest extends TestCase
{
Expand All @@ -37,22 +36,6 @@ protected function setUp(): void
$this->realDriver = $this->createMock(DriverInterface::class);
}

public function testSymfonyContainer()
{
$this->realDriver
->expects($this->once())
->method('loadMetadataForClass')
->with($this->ref)
->willReturn($this->metadata);

$container = new Container();
$container->set('foo', $this->realDriver);

$driver = new LazyLoadingDriver($container, 'foo');

self::assertSame($this->metadata, $driver->loadMetadataForClass($this->ref));
}

public function testPsrContainer()
{
$this->realDriver
Expand Down