diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 18be910..f827328 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -16,8 +16,10 @@ jobs: strategy: matrix: php-version: - - "7.3" - "7.4" + - "8.0" + - "8.1" + - "8.2" deps: - "normal" symfony-require: @@ -25,28 +27,118 @@ jobs: symfony-deprecations-helper: - "" include: - # Test against latest Symfony 4.3 stable - - symfony-require: "4.3.*" - php-version: "7.3" + # Test against latest Symfony 5.4 stable on 7.4 + - symfony-require: "5.4.*" + php-version: "7.4" + deps: "dev" + + # Test against latest Symfony 5.4 stable on 7.4 deps normal + - symfony-require: "5.4.*" + php-version: "7.4" + deps: "normal" + + # Test against latest Symfony 5.4 stable on 8.0 + - symfony-require: "5.4.*" + php-version: "8.0" + deps: "dev" + + # Test against latest Symfony 5.4 stable on 8.0 deps normal + - symfony-require: "5.4.*" + php-version: "8.0" + deps: "normal" + + # Test against latest Symfony 5.4 stable on 8.1 + - symfony-require: "5.4.*" + php-version: "8.1" + deps: "dev" + + # Test against latest Symfony 5.4 stable on 8.1 deps normal + - symfony-require: "5.4.*" + php-version: "8.1" + deps: "normal" + + # Test against latest Symfony 5.4 stable on 8.2 + - symfony-require: "5.4.*" + php-version: "8.2" + deps: "dev" + + # Test against latest Symfony 5.4 stable on 8.2 deps normal + - symfony-require: "5.4.*" + php-version: "8.2" + deps: "normal" + + # Test against latest Symfony 6.0 stable on 8.0 + - symfony-require: "6.0.*" + php-version: "8.0" + deps: "dev" + + # Test against latest Symfony 6.0 stable on 8.0 deps normal + - symfony-require: "6.0.*" + php-version: "8.0" deps: "normal" - # Test against latest Symfony 4.4 dev - - symfony-require: "4.4.*" - php-version: "7.3" + # Test against latest Symfony 6.0 stable on 8.1 + - symfony-require: "6.0.*" + php-version: "8.1" deps: "dev" - # Test against latest Symfony 5.2 dev - - symfony-require: "5.2.*" - php-version: "7.3" + # Test against latest Symfony 6.0 stable on 8.1 deps normal + - symfony-require: "6.0.*" + php-version: "8.1" + deps: "normal" + + # Test against latest Symfony 6.0 stable on 8.2 + - symfony-require: "6.0.*" + php-version: "8.2" + deps: "dev" + + # Test against latest Symfony 6.0 stable on 8.2 deps normal + - symfony-require: "6.0.*" + php-version: "8.2" + deps: "normal" + + # Test against latest Symfony 6.1 stable on 8.1 + - symfony-require: "6.1.*" + php-version: "8.1" + deps: "dev" + + # Test against latest Symfony 6.1 stable on 8.1 deps normal + - symfony-require: "6.1.*" + php-version: "8.1" + deps: "normal" + + # Test against latest Symfony 6.1 stable on 8.2 + - symfony-require: "6.1.*" + php-version: "8.2" deps: "dev" - - php-version: "8.0" + # Test against latest Symfony 6.1 stable on 8.2 deps normal + - symfony-require: "6.1.*" + php-version: "8.2" + deps: "normal" + + # Test against latest Symfony 6.2 stable on 8.1 + - symfony-require: "6.2.*" + php-version: "8.1" deps: "dev" - symfony-deprecations-helper: "weak" + # Test against latest Symfony 6.2 stable on 8.1 deps normal + - symfony-require: "6.2.*" + php-version: "8.1" + deps: "normal" + + # Test against latest Symfony 6.2 stable on 8.2 + - symfony-require: "6.2.*" + php-version: "8.2" + deps: "dev" + + # Test against latest Symfony 6.2 stable on 8.2 deps normal + - symfony-require: "6.2.*" + php-version: "8.2" + deps: "normal" steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v3" with: fetch-depth: 2 @@ -57,7 +149,7 @@ jobs: coverage: "pcov" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v2" + uses: "actions/cache@v3" with: path: "~/.composer/cache" key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" @@ -83,7 +175,7 @@ jobs: with: name: "phpunit-${{ matrix.php-version }}-${{ matrix.deps }}-${{ hashFiles('composer.lock') }}.coverage" path: "coverage.xml" - + - uses: codecov/codecov-action@v1 with: verbose: true diff --git a/ClientConfiguration.php b/ClientConfiguration.php index 6ddf0ba..19e0e9e 100644 --- a/ClientConfiguration.php +++ b/ClientConfiguration.php @@ -20,14 +20,8 @@ class ClientConfiguration extends ParameterBag implements ConfigurationInterface { /** * ClientConfiguration constructor. - * @param ApiToken $apiToken - * @param EventDispatcherInterface $eventDispatcher - * @param ClientInterface $client - * @param RequestFactoryInterface $requestFactory - * @param ResponseFactoryInterface $responseFactory - * @param StreamFactoryInterface $streamFactory - * @param UriFactoryInterface $uriFactory - * @param array $options + * + * @param array $options */ public function __construct( ApiToken $apiToken, diff --git a/DependencyInjection/CompilerPass/ConfigurationPass.php b/DependencyInjection/CompilerPass/ConfigurationPass.php index 842bdde..d9dc55b 100644 --- a/DependencyInjection/CompilerPass/ConfigurationPass.php +++ b/DependencyInjection/CompilerPass/ConfigurationPass.php @@ -14,17 +14,13 @@ class ConfigurationPass implements CompilerPassInterface { - /** - * @param ContainerBuilder $container - * - * @return void - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { + /** @var array $parameters */ $parameters = $container->getParameter('tmdb.options'); $configDefinition = $container->getDefinition(ClientConfiguration::class); - // By default the first argument is always referenced to the ApiToken. + // By default, the first argument is always referenced to the ApiToken. if (null !== $bearerToken = $parameters['options']['bearer_token']) { $configDefinition->replaceArgument(0, new Reference(BearerToken::class)); } @@ -34,11 +30,7 @@ public function process(ContainerBuilder $container) } /** - * @param ContainerBuilder $container - * @param Definition $configDefinition - * @param array $parameters - * - * @return void + * @param array $parameters */ private function setupEventDispatcher( ContainerBuilder $container, @@ -58,11 +50,7 @@ private function setupEventDispatcher( } /** - * @param ContainerBuilder $container - * @param Definition $configDefinition - * @param array $parameters - * - * @return void + * @param array $parameters */ private function setupHttpClient( ContainerBuilder $container, @@ -122,11 +110,6 @@ private function setupHttpClient( } /** - * @param ContainerBuilder $container - * @param string $alias - * @param string $tag - * @param string $configurationPath - * @return void * @throws \RuntimeException */ protected function tryToAliasAutowiredInterfacesIfPossible( diff --git a/DependencyInjection/CompilerPass/EventDispatchingPass.php b/DependencyInjection/CompilerPass/EventDispatchingPass.php index 9a3c1e6..b4c7a3a 100644 --- a/DependencyInjection/CompilerPass/EventDispatchingPass.php +++ b/DependencyInjection/CompilerPass/EventDispatchingPass.php @@ -30,13 +30,9 @@ */ class EventDispatchingPass implements CompilerPassInterface { - /** - * @param ContainerBuilder $container - * - * @return void - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { + /** @var array $parameters */ $parameters = $container->getParameter('tmdb.options'); $clientOptions = $parameters['options']; @@ -54,11 +50,7 @@ public function process(ContainerBuilder $container) } /** - * @param ContainerBuilder $container - * @param Definition $eventDispatcher - * @param array $parameters - * - * @return void + * @param array $parameters */ private function handleSymfonyEventDispatcherRegistration( ContainerBuilder $container, @@ -123,9 +115,7 @@ private function handleSymfonyEventDispatcherRegistration( } /** - * @param ContainerBuilder $container - * @param array $parameters - * @return Definition + * @param array $parameters */ private function getRequestListener( ContainerBuilder $container, @@ -139,9 +129,7 @@ private function getRequestListener( } /** - * @param ContainerBuilder $container - * @param array $parameters - * @return Definition + * @param array $parameters */ private function getPsr6CacheRequestListener( ContainerBuilder $container, @@ -154,13 +142,7 @@ private function getPsr6CacheRequestListener( } /** - * @param string $event - * @param string $listener - * @param Definition $eventDispatcher - * @param ContainerBuilder $container - * @param array $parameters - * - * @return void + * @param array $parameters */ private function handleLogging( string $event, @@ -168,7 +150,7 @@ private function handleLogging( Definition $eventDispatcher, ContainerBuilder $container, array $parameters - ) { + ): void { $options = $parameters[$listener]; $configEntry = sprintf('tmdb_symfony.log.%s', $listener); @@ -231,11 +213,7 @@ private function handleLogging( /** * Register listeners for logging. * - * @param ContainerBuilder $container - * @param Definition $eventDispatcher - * @param array $parameters - * - * @return void + * @param array $parameters */ private function handleLoggerListeners(ContainerBuilder $container, Definition $eventDispatcher, array $parameters): void { @@ -258,11 +236,6 @@ private function handleLoggerListeners(ContainerBuilder $container, Definition $ } } - /** - * @param Definition $eventDispatcher - * @param string $event - * @param string $reference - */ private function registerEventListener( Definition $eventDispatcher, string $event, diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 4397a8f..a865751 100755 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -2,6 +2,13 @@ namespace Tmdb\SymfonyBundle\DependencyInjection; +use Psr\EventDispatcher\EventDispatcherInterface; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\ResponseFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\UriFactoryInterface; +use Psr\Log\LoggerInterface; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -13,14 +20,16 @@ use Tmdb\Formatter\Hydration\SimpleHydrationFormatter; use Tmdb\Formatter\TmdbApiException\SimpleTmdbApiExceptionFormatter; + class Configuration implements ConfigurationInterface { /** * {@inheritDoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('tmdb_symfony'); + /** @var ArrayNodeDefinition $rootNode */ $rootNode = $treeBuilder->getRootNode(); $this->addRootChildren($rootNode); @@ -31,11 +40,6 @@ public function getConfigTreeBuilder() return $treeBuilder; } - /** - * @param ArrayNodeDefinition $rootNode - * - * @return void - */ private function addRootChildren(ArrayNodeDefinition $rootNode): void { $rootNode @@ -60,11 +64,6 @@ private function addRootChildren(ArrayNodeDefinition $rootNode): void ; } - /** - * @param ArrayNodeDefinition $rootNode - * - * @return void - */ private function addOptionsSection(ArrayNodeDefinition $rootNode): void { $rootNode @@ -89,7 +88,7 @@ private function addOptionsSection(ArrayNodeDefinition $rootNode): void ->children() ->scalarNode('adapter') ->isRequired()->cannotBeEmpty() - ->defaultValue('Psr\EventDispatcher\EventDispatcherInterface') + ->defaultValue(EventDispatcherInterface::class) ->end() ->end() ->end() @@ -97,23 +96,23 @@ private function addOptionsSection(ArrayNodeDefinition $rootNode): void ->addDefaultsIfNotSet() ->children() ->scalarNode('client') - ->defaultValue('Psr\Http\Client\ClientInterface') + ->defaultValue(ClientInterface::class) ->info('Reference to a service which implements PSR-18 HTTP Client') ->end() ->scalarNode('request_factory') - ->defaultValue('Psr\Http\Message\RequestFactoryInterface') + ->defaultValue(RequestFactoryInterface::class) ->info('Reference to a service which implements PSR-17 HTTP Factories') ->end() ->scalarNode('response_factory') - ->defaultValue('Psr\Http\Message\ResponseFactoryInterface') + ->defaultValue(ResponseFactoryInterface::class) ->info('Reference to a service which implements PSR-17 HTTP Factories') ->end() ->scalarNode('stream_factory') - ->defaultValue('Psr\Http\Message\StreamFactoryInterface') + ->defaultValue(StreamFactoryInterface::class) ->info('Reference to a service which implements PSR-17 HTTP Factories') ->end() ->scalarNode('uri_factory') - ->defaultValue('Psr\Http\Message\UriFactoryInterface') + ->defaultValue(UriFactoryInterface::class) ->info('Reference to a service which implements PSR-17 HTTP Factories') ->end() ->end() @@ -133,11 +132,6 @@ private function addOptionsSection(ArrayNodeDefinition $rootNode): void ; } - /** - * @param ArrayNodeDefinition $rootNode - * - * @return void - */ private function addLogSection(ArrayNodeDefinition $rootNode): void { $rootNode @@ -147,7 +141,7 @@ private function addLogSection(ArrayNodeDefinition $rootNode): void ->canBeEnabled() ->children() ->scalarNode('adapter') - ->defaultValue('Psr\Log\LoggerInterface') + ->defaultValue(LoggerInterface::class) ->info('When registering a channel in monolog as "tmdb" for example, monolog.logger.tmdb') ->end() ->arrayNode('request_logging') @@ -202,11 +196,6 @@ private function addLogSection(ArrayNodeDefinition $rootNode): void ; } - /** - * @param ArrayNodeDefinition $rootNode - * - * @return void - */ private function addCacheSection(ArrayNodeDefinition $rootNode): void { $rootNode diff --git a/DependencyInjection/TmdbSymfonyExtension.php b/DependencyInjection/TmdbSymfonyExtension.php index c295250..00659a3 100644 --- a/DependencyInjection/TmdbSymfonyExtension.php +++ b/DependencyInjection/TmdbSymfonyExtension.php @@ -41,11 +41,9 @@ class TmdbSymfonyExtension extends Extension { /** - * @param array $configs - * @param ContainerBuilder $container - * @return void + * @param array $configs */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); @@ -83,9 +81,9 @@ public function load(array $configs, ContainerBuilder $container) /** * Alias mapping for legacy constructs; public to abuse within test suite. * - * @return array + * @return array */ - public function getLegacyAliasMapping() + public function getLegacyAliasMapping(): array { return [ 'repositories' => [ @@ -128,10 +126,7 @@ public function getLegacyAliasMapping() * * @todo major release remove alias mapping of legacy muck :-) * - * @param ContainerBuilder $container * @param array $mapping - * - * @return void */ protected function performAliasMapping(ContainerBuilder $container, array $mapping = []): void { @@ -145,10 +140,6 @@ protected function performAliasMapping(ContainerBuilder $container, array $mappi /** * Handle general lgeacy aliases. - * - * @param ContainerBuilder $container - * - * @return void */ protected function handleLegacyGeneralAliases(ContainerBuilder $container): void { @@ -158,10 +149,6 @@ protected function handleLegacyGeneralAliases(ContainerBuilder $container): void /** * Map repository legacy aliases - * - * @param ContainerBuilder $container - * - * @return void */ protected function handleLegacyRepositoryAliases(ContainerBuilder $container): void { @@ -171,10 +158,6 @@ protected function handleLegacyRepositoryAliases(ContainerBuilder $container): v /** * Map twig legacy aliases - * - * @param ContainerBuilder $container - * - * @return void */ protected function handleLegacyTwigExtensionAlias(ContainerBuilder $container): void { diff --git a/README.md b/README.md index 3f3e142..1f19b35 100755 --- a/README.md +++ b/README.md @@ -5,16 +5,22 @@ [![Build Status](https://img.shields.io/github/workflow/status/php-tmdb/symfony/Continuous%20Integration?label=phpunit)](https://github.com/php-tmdb/symfony/actions?query=workflow%3A%22Continuous+Integration%22) [![Build Status](https://img.shields.io/github/workflow/status/php-tmdb/symfony/Coding%20Standards?label=phpcs)](https://github.com/php-tmdb/symfony/actions?query=workflow%3A%22Coding+Standards%22) [![codecov](https://img.shields.io/codecov/c/github/php-tmdb/symfony?token=gTM9AiO5vH)](https://codecov.io/gh/php-tmdb/symfony) -[![PHP](https://img.shields.io/badge/php->=7.3,%20>=8.0-8892BF.svg)](https://packagist.org/packages/php-tmdb/symfony) +[![PHP](https://img.shields.io/badge/php->=7.3,%20>=7.4,%20>=8.0-8892BF.svg)](https://packagist.org/packages/php-tmdb/api) [![Total Downloads](https://poser.pugx.org/php-tmdb/symfony/downloads.svg)](https://packagist.org/packages/php-tmdb/symfony) -Compatible with Symfony 4 and 5, PHP 7.3 and up. +Compatible with Symfony 5 and 6, PHP 7.4 and up. + +## Buy me a coffee, or a beer :-) + + + +My stomach will appreciate your donation! Installation ------------ - [Install Composer](https://getcomposer.org/doc/00-intro.md) -- [Install php-tmdb/api dependencies](https://github.com/php-tmdb/api/tree/release/4.0.0#installation) +- [Install php-tmdb/api dependencies](https://github.com/php-tmdb/api#installation) - For development within Symfony we recommend making use of Symfony's PSR-18 HTTP Client _`Symfony\Component\HttpClient\Psr18Client`_, as when non-cached results pass your profiler will be filled with data. @@ -256,13 +262,50 @@ Usage Obtaining the client ```php -$client = $this->get(Tmdb\Client::class); +client = $client; + } +} ``` Obtaining repositories ```php -$movie = $this->get(\Tmdb\Repository\MovieRepository::class)->load(13); +movieRepository = $movieRepository; + } + + public function findMovie(string $id): AbstractModel + { + // Use the auto-wired repository in any of your methods + return $this->movieRepository->load($id); + } +} ``` An overview of all the repositories can be found in the services configuration [repositories.xml](https://github.com/php-tmdb/symfony/blob/master/Resources/config/repositories.xml). @@ -276,4 +319,3 @@ There is also a Twig helper that makes use of the `Tmdb\Helper\ImageHelper` to o ``` **For all all other interactions take a look at [php-tmdb/api](https://github.com/php-tmdb/api).** - diff --git a/Tests/DependencyInjection/CompilerPass/ConfigurationPassTest.php b/Tests/DependencyInjection/CompilerPass/ConfigurationPassTest.php index f523a0e..207d00a 100644 --- a/Tests/DependencyInjection/CompilerPass/ConfigurationPassTest.php +++ b/Tests/DependencyInjection/CompilerPass/ConfigurationPassTest.php @@ -81,12 +81,12 @@ public function testAutowiring() $pass = new ConfigurationPass(); $pass->process($container); - $this->assertAlias($container, get_class($eventDispatcherMock), EventDispatcherInterface::class); - $this->assertAlias($container, get_class($httpClientMock), ClientInterface::class); - $this->assertAlias($container, get_class($requestFactoryMock), RequestFactoryInterface::class); - $this->assertAlias($container, get_class($responseFactoryMock), ResponseFactoryInterface::class); - $this->assertAlias($container, get_class($streamFactoryMock), StreamFactoryInterface::class); - $this->assertAlias($container, get_class($uriFactoryMock), UriFactoryInterface::class); + $this->assertTag($container, get_class($eventDispatcherMock), TmdbSymfonyBundle::PSR14_EVENT_DISPATCHERS); + $this->assertTag($container, get_class($httpClientMock), TmdbSymfonyBundle::PSR18_CLIENTS); + $this->assertTag($container, get_class($requestFactoryMock), TmdbSymfonyBundle::PSR17_REQUEST_FACTORIES); + $this->assertTag($container, get_class($responseFactoryMock), TmdbSymfonyBundle::PSR17_RESPONSE_FACTORIES); + $this->assertTag($container, get_class($streamFactoryMock), TmdbSymfonyBundle::PSR17_STREAM_FACTORIES); + $this->assertTag($container, get_class($uriFactoryMock), TmdbSymfonyBundle::PSR17_URI_FACTORIES); } /** diff --git a/Tests/DependencyInjection/TestCase.php b/Tests/DependencyInjection/TestCase.php index d093b2a..394e001 100644 --- a/Tests/DependencyInjection/TestCase.php +++ b/Tests/DependencyInjection/TestCase.php @@ -30,6 +30,16 @@ protected function assertAlias(ContainerBuilder $container, $value, $key): void $this->assertSame($value, (string)$container->getAlias($key), sprintf('%s alias is correct', $key)); } + /** + * @param ContainerBuilder $container + * @param string $class + * @param string $tag + */ + protected function assertTag(ContainerBuilder $container, string $class, string $tag): void + { + $this->assertArrayHasKey($class, $container->findTaggedServiceIds($tag)); + } + /** * @param string $key */ diff --git a/Tests/Twig/TmdbExtensionTest.php b/Tests/Twig/TmdbExtensionTest.php index 4124a0d..8001f12 100644 --- a/Tests/Twig/TmdbExtensionTest.php +++ b/Tests/Twig/TmdbExtensionTest.php @@ -1,18 +1,17 @@ setImages($responseData['images']); - $helper = new ImageHelper($configuration); - - $extension = new TmdbExtension($client); - $this->assertEquals($client, $extension->getClient()); - - $extension->setHelper($helper); - $extension->setClient($client); - $this->assertEquals($client, $extension->getClient()); + $extension = new TmdbExtension($client, $configuration); $image = new Image(); $image @@ -48,15 +40,14 @@ public function testTwigExtension() $this->assertEquals('//image.tmdb.org/t/p/original/foo.jpg', $extension->getUrl($image)); $this->assertEquals( - '', + '', $extension->getHtml($image) ); $this->assertEquals('tmdb_extension', $extension->getName()); - $this->assertEquals(2, count($extension->getFilters())); + $this->assertCount(2, $extension->getFilters()); } /** - * @test * @group Twig */ public function testRepository() @@ -70,18 +61,15 @@ public function testRepository() $configuration = new Configuration(); $configuration->setImages($responseData['images']); - $helper = new ImageHelper($configuration); - - $repository = $this->getMockBuilder(AbstractRepository::class) + $repository = $this->getMockBuilder(ConfigurationRepository::class) ->disableOriginalConstructor() - ->setMethods(['load', 'getApi', 'getFactory']) + ->onlyMethods(['load', 'getApi', 'getFactory']) ->getMock() ; $repository->method('load')->willReturn($configuration); - $extension = new TmdbExtension($client, $repository); - $this->assertEquals($client, $extension->getClient()); + $extension = new TmdbExtension($client, $repository->load()); $image = new Image(); $image @@ -96,10 +84,10 @@ public function testRepository() $this->assertEquals('//image.tmdb.org/t/p/original/foo.jpg', $extension->getUrl($image)); $this->assertEquals( - '', + '', $extension->getHtml($image) ); $this->assertEquals('tmdb_extension', $extension->getName()); - $this->assertEquals(2, count($extension->getFilters())); + $this->assertCount(2, $extension->getFilters()); } } diff --git a/TmdbSymfonyBundle.php b/TmdbSymfonyBundle.php index cf29829..6bd9d5e 100644 --- a/TmdbSymfonyBundle.php +++ b/TmdbSymfonyBundle.php @@ -28,10 +28,7 @@ class TmdbSymfonyBundle extends Bundle public const PSR17_URI_FACTORIES = 'tmdb_symfony.psr17.uri_factories'; public const PSR14_EVENT_DISPATCHERS = 'tmdb_symfony.psr17.event_dispatchers'; - /** - * @param ContainerBuilder $container - */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/Twig/TmdbExtension.php b/Twig/TmdbExtension.php index 673ac8d..72994fb 100644 --- a/Twig/TmdbExtension.php +++ b/Twig/TmdbExtension.php @@ -4,43 +4,29 @@ use Tmdb\Client; use Tmdb\Helper\ImageHelper; -use Tmdb\Repository\AbstractRepository; +use Tmdb\Model\Configuration; use Tmdb\Repository\ConfigurationRepository; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; class TmdbExtension extends AbstractExtension { - /** - * @var ImageHelper|null - */ - private $helper; - - /** - * @var Client - */ - private $client; - - /** - * @var AbstractRepository|ConfigurationRepository - */ - private $repository; + private ImageHelper $helper; /** * TmdbExtension constructor. - * @param Client $client - * @param AbstractRepository $repository */ - public function __construct(Client $client, AbstractRepository $repository = null) + public function __construct(Client $client, Configuration $configuration = null) { - $this->client = $client; - $this->repository = $repository ?? new ConfigurationRepository($client); + $configuration ??= (new ConfigurationRepository($client))->load(); + + $this->helper = new ImageHelper($configuration); } /** - * @return array|TwigFilter[] + * @return array */ - public function getFilters() + public function getFilters(): array { return array( new TwigFilter('tmdb_image_html', array($this, 'getHtml')), @@ -48,77 +34,18 @@ public function getFilters() ); } - /** - * @param string $image - * @param string $size - * @param int|null $width - * @param int|null $height - * @return string - */ public function getHtml(string $image, string $size = 'original', int $width = null, int $height = null): string { - return $this->getHelper()->getHtml($image, $size, $width, $height); + return $this->helper->getHtml($image, $size, $width, $height); } - /** - * @param string $image - * @param string $size - * @return string - */ public function getUrl(string $image, string $size = 'original'): string { - return $this->getHelper()->getUrl($image, $size); + return $this->helper->getUrl($image, $size); } - /** - * @return string - */ public function getName(): string { return 'tmdb_extension'; } - - /** - * @param Client $client - * @return $this - */ - public function setClient(Client $client) - { - $this->client = $client; - - return $this; - } - - /** - * @return Client|null - */ - public function getClient(): ?Client - { - return $this->client; - } - - /** - * @param ImageHelper $helper - * @return $this - */ - public function setHelper($helper) - { - $this->helper = $helper; - - return $this; - } - - /** - * @return ImageHelper - */ - public function getHelper() - { - if ($this->helper) { - return $this->helper; - } - - $this->helper = new ImageHelper($this->repository->load()); - - return $this->helper; - } } diff --git a/composer.json b/composer.json index eab7454..0ee83bb 100755 --- a/composer.json +++ b/composer.json @@ -13,15 +13,14 @@ } ], "require": { - "php": "^7.3 || ^8.0", - "php-tmdb/api": "^4", - "symfony/config": "^4.3.7 || <6", - "symfony/dependency-injection": "^4.3.7 || <6", - "symfony/event-dispatcher": "^4.3.7 || <6", - "symfony/http-kernel": "^4.3.7 || >=5.1.5", - "symfony/phpunit-bridge": "^4.2", - "symfony/yaml": "^4.3.7 || ^5.0", - "twig/twig": "^2.0 || ^3.0" + "php": "^7.4 || ^8.0", + "php-tmdb/api": "^4.0", + "symfony/config": "^5.4 || ^6.0", + "symfony/dependency-injection": "^5.4 || ^6.0", + "symfony/event-dispatcher": "^5.4 || ^6.0", + "symfony/http-kernel": "^5.4 || ^6.0", + "symfony/yaml": "^5.4 || ^6.0", + "twig/twig": "^3.0" }, "scripts": { "test": "vendor/bin/phpunit", @@ -36,13 +35,20 @@ "slevomat/coding-standard": "^6.4.1", "squizlabs/php_codesniffer": "^3.5.8", "php-http/guzzle7-adapter": "^0.1", - "phpstan/phpstan": "^0.12.18", + "phpstan/phpstan": "^1.0", "phpunit/phpunit": "^7.5 || ^8.0 || ^9.3", - "symfony/framework-bundle": "^4.3.7 || ^5.0", - "vimeo/psalm": "^4", + "symfony/framework-bundle": "^5.4 || ^6.0", + "symfony/phpunit-bridge": "^5.4 || ^6.0", + "vimeo/psalm": "^4.0", "php-http/cache-plugin": "^1.7" }, "autoload": { "psr-4": { "Tmdb\\SymfonyBundle\\": "" } + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "php-http/discovery": true + } } } diff --git a/phpstan.neon b/phpstan.neon index 7450740..ac7ebae 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,10 +1,8 @@ parameters: level: 2 inferPrivatePropertyTypeFromConstructor: true - ignoreErrors: - - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\)\.#' paths: - . - excludes_analyse: + excludePaths: - Tests - vendor