From f503fe28edaffe6205d2bc6cfa8f88541213b41c Mon Sep 17 00:00:00 2001 From: dsbe-ak <72384646+dsbe-ak@users.noreply.github.com> Date: Wed, 16 Nov 2022 11:41:49 +0100 Subject: [PATCH] php 8 and symfony 6 update (#47) * php 8 and symfony 6 update * php 8 and symfony 6 update --- .travis.yml | 7 +- DependencyInjection/Configuration.php | 10 +- .../GoogleTagManagerExtension.php | 6 +- EventListener/GoogleTagManagerListener.php | 14 +- Helper/GoogleTagManagerHelper.php | 57 ++------- Helper/GoogleTagManagerHelperInterface.php | 52 ++------ Service/GoogleTagManager.php | 120 ++++-------------- Service/GoogleTagManagerFactory.php | 10 +- Service/GoogleTagManagerInterface.php | 76 ++--------- .../AbstractGoogleTagManagerExtensionTest.php | 6 +- Tests/Service/GoogleTagManagerTest.php | 4 +- composer.json | 17 +-- phpunit.xml.dist | 28 ++-- 13 files changed, 109 insertions(+), 298 deletions(-) diff --git a/.travis.yml b/.travis.yml index 531b588..b87f2e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,8 @@ language: php php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 + - 8.0 + - 8.1 sudo: false dist: xenial diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 7b99422..e896b4d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,17 +23,11 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('google_tag_manager'); - if (method_exists($treeBuilder, 'getRootNode')) { - $rootNode = $treeBuilder->getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('google_tag_manager'); - } - + $rootNode = $treeBuilder->getRootNode(); $rootNode ->children() ->booleanNode('enabled')->end() diff --git a/DependencyInjection/GoogleTagManagerExtension.php b/DependencyInjection/GoogleTagManagerExtension.php index f1a1f5c..7ad6563 100644 --- a/DependencyInjection/GoogleTagManagerExtension.php +++ b/DependencyInjection/GoogleTagManagerExtension.php @@ -10,6 +10,7 @@ namespace Xynnn\GoogleTagManagerBundle\DependencyInjection; +use Exception; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -24,8 +25,9 @@ class GoogleTagManagerExtension extends Extension { /** * {@inheritdoc} + * @throws Exception */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); @@ -41,7 +43,7 @@ public function load(array $configs, ContainerBuilder $container) /** * @return string */ - public function getAlias() + public function getAlias(): string { return 'google_tag_manager'; } diff --git a/EventListener/GoogleTagManagerListener.php b/EventListener/GoogleTagManagerListener.php index 7d4c3c3..5ae806e 100644 --- a/EventListener/GoogleTagManagerListener.php +++ b/EventListener/GoogleTagManagerListener.php @@ -15,28 +15,28 @@ class GoogleTagManagerListener /** * @var Environment */ - private $environment; + private Environment $environment; /** * @var GoogleTagManagerExtension */ - private $extension; + private GoogleTagManagerExtension $extension; /** * @var bool */ - private $autoAppend; + private bool $autoAppend; /** * @param Environment $environment * @param GoogleTagManagerExtension $extension * @param bool $autoAppend */ - public function __construct(Environment $environment, GoogleTagManagerExtension $extension, $autoAppend) + public function __construct(Environment $environment, GoogleTagManagerExtension $extension, bool $autoAppend) { $this->environment = $environment; $this->extension = $extension; - $this->autoAppend = (bool)$autoAppend; + $this->autoAppend = $autoAppend; } /** @@ -44,7 +44,7 @@ public function __construct(Environment $environment, GoogleTagManagerExtension * * @return bool */ - public function onKernelResponse($event) + public function onKernelResponse(mixed $event): bool { if (!$this->allowRender($event)) { return false; @@ -83,7 +83,7 @@ public function onKernelResponse($event) * * @return bool */ - private function allowRender($event) + private function allowRender(mixed $event): bool { // not configured to append automatically if (!$this->autoAppend) { diff --git a/Helper/GoogleTagManagerHelper.php b/Helper/GoogleTagManagerHelper.php index 627a154..ca4e636 100644 --- a/Helper/GoogleTagManagerHelper.php +++ b/Helper/GoogleTagManagerHelper.php @@ -23,7 +23,7 @@ class GoogleTagManagerHelper extends Helper implements GoogleTagManagerHelperInt /** * @var GoogleTagManagerInterface */ - private $service; + private GoogleTagManagerInterface $service; /** * @param GoogleTagManagerInterface $service @@ -33,90 +33,57 @@ public function __construct(GoogleTagManagerInterface $service) $this->service = $service; } - /** - * {@inheritdoc} - */ - public function enable() + public function enable(): void { $this->service->enable(); } - /** - * {@inheritdoc} - */ - public function disable() + public function disable(): void { $this->service->disable(); } - /** - * {@inheritdoc} - */ - public function isEnabled() + public function isEnabled(): bool { return $this->service->isEnabled(); } - /** - * {@inheritdoc} - */ - public function getId() + public function getId(): string { return $this->service->getId(); } - /** - * {@inheritdoc} - */ - public function setId($id) + public function setId($id): void { $this->service->setId($id); } - /** - * {@inheritdoc} - */ - public function getData() + public function getData(): array { return $this->service->getData(); } - /** - * {@inheritdoc} - */ - public function hasData() + public function hasData(): bool { return $this->service->hasData(); } - /** - * {@inheritdoc} - */ - public function getPush() + public function getPush(): array { return $this->service->getPush(); } - /** - * {@inheritdoc} - */ - public function getName() + public function getName(): string { return 'google_tag_manager'; } - /** - * {@inheritdoc} - */ - public function setAdditionalParameters($additionalParameters) + public function setAdditionalParameters($additionalParameters): void { $this->service->setAdditionalParameters($additionalParameters); } - /** - * {@inheritdoc} - */ - public function getAdditionalParameters() + public function getAdditionalParameters(): string { return $this->service->getAdditionalParameters(); } diff --git a/Helper/GoogleTagManagerHelperInterface.php b/Helper/GoogleTagManagerHelperInterface.php index b8097ec..49d9f51 100644 --- a/Helper/GoogleTagManagerHelperInterface.php +++ b/Helper/GoogleTagManagerHelperInterface.php @@ -19,55 +19,23 @@ */ interface GoogleTagManagerHelperInterface extends HelperInterface { - /** - * @return void - */ - public function enable(); + public function enable(): void; - /** - * @return void - */ - public function disable(); + public function disable(): void; - /** - * @return bool - */ - public function isEnabled(); + public function isEnabled(): bool; - /** - * @return string - */ - public function getId(); + public function getId(): string; - /** - * @param string $id - * @return void - */ - public function setId($id); + public function setId(string $id): void; - /** - * @return array - */ - public function getData(); + public function getData(): array; - /** - * @return bool - */ - public function hasData(); + public function hasData(): bool; - /** - * @return array - */ - public function getPush(); + public function getPush(): array; - /** - * @param string $additionalParameters - * @return void - */ - public function setAdditionalParameters($additionalParameters); + public function setAdditionalParameters(string $additionalParameters): void; - /** - * @return string - */ - public function getAdditionalParameters(); + public function getAdditionalParameters(): string; } diff --git a/Service/GoogleTagManager.php b/Service/GoogleTagManager.php index 9074d86..a1673ad 100644 --- a/Service/GoogleTagManager.php +++ b/Service/GoogleTagManager.php @@ -17,61 +17,33 @@ */ class GoogleTagManager implements GoogleTagManagerInterface { - /** - * @var bool - */ - private $enabled; - - /** - * @var string - */ - private $id; - - /** - * @var array - */ - private $data = array(); - - /** - * @var array - */ - private $push = array(); - - /** - * @var string - */ - private $additionalParameters; - - /** - * @param $enabled - * @param $id - */ - public function __construct($enabled, $id) - { - $this->enabled = (bool)$enabled; + private bool $enabled; + + private string $id; + + private array $data = array(); + + private array $push = array(); + + private string $additionalParameters; + + public function __construct(bool $enabled, string $id) + { + $this->enabled = $enabled; $this->id = $id; } - /** - * {@inheritdoc} - */ - public function addData($key, $value) + public function addData(string $key, mixed $value) { $this->setData($key, $value); } - /** - * {@inheritdoc} - */ - public function setData($key, $value) + public function setData(string $key, mixed $value): void { $this->data[$key] = $value; } - /** - * {@inheritdoc} - */ - public function mergeData($key, $value) + public function mergeData(string $key, mixed $value): void { $merge = array(); if (array_key_exists($key, $this->data)) { @@ -81,100 +53,64 @@ public function mergeData($key, $value) $this->setData($key, array_merge_recursive($merge, $value)); } - /** - * {@inheritdoc} - */ - public function enable() + public function enable(): void { $this->enabled = true; } - /** - * {@inheritdoc} - */ - public function disable() + public function disable(): void { $this->enabled = false; } - /** - * {@inheritdoc} - */ - public function isEnabled() + public function isEnabled(): bool { return $this->enabled; } - /** - * {@inheritdoc} - */ - public function getId() + public function getId(): string { return $this->id; } - /** - * {@inheritdoc} - */ - public function setId($id) + public function setId($id): void { $this->id = $id; } - /** - * {@inheritdoc} - */ - public function getData() + public function getData(): array { return $this->data; } - /** - * {@inheritdoc} - */ - public function addPush($value) + public function addPush($value): void { $this->push[] = $value; } - /** - * {@inheritdoc} - */ - public function getPush() + public function getPush(): array { return $this->push; } - /** - * {@inheritdoc} - */ - public function hasData() + public function hasData(): bool { return is_array($this->getData()) && count($this->getData()) > 0; } - /** - * Reset internal state at the end of the request - */ - public function reset() + public function reset(): void { $this->data = array(); $this->push = array(); } - /** - * {@inheritdoc} - */ - public function setAdditionalParameters($additionalParameters) + public function setAdditionalParameters($additionalParameters): void { $this->additionalParameters = $additionalParameters; } - /** - * {@inheritdoc} - */ - public function getAdditionalParameters() + public function getAdditionalParameters(): string { return $this->additionalParameters; } diff --git a/Service/GoogleTagManagerFactory.php b/Service/GoogleTagManagerFactory.php index 7c76a4e..f359711 100644 --- a/Service/GoogleTagManagerFactory.php +++ b/Service/GoogleTagManagerFactory.php @@ -22,18 +22,12 @@ class GoogleTagManagerFactory { use ContainerAwareTrait; - /** - * @return ContainerInterface - */ - private function getContainer() + private function getContainer(): ContainerInterface { return $this->container; } - /** - * @return GoogleTagManagerInterface - */ - public function create() + public function create(): GoogleTagManagerInterface { $container = $this->getContainer(); diff --git a/Service/GoogleTagManagerInterface.php b/Service/GoogleTagManagerInterface.php index dc51c24..a13340c 100644 --- a/Service/GoogleTagManagerInterface.php +++ b/Service/GoogleTagManagerInterface.php @@ -18,81 +18,33 @@ interface GoogleTagManagerInterface { /** - * @param $key - * @param $value * @deprecated Use 'setData' or 'mergeData' methods */ - public function addData($key, $value); + public function addData(string $key, mixed $value); - /** - * @param $key - * @param $value - * @return void - */ - public function setData($key, $value); + public function setData(string $key, mixed $value): void; - /** - * @param $key - * @param $value - * @return void - */ - public function mergeData($key, $value); + public function mergeData(string $key, mixed $value): void; - /** - * @return void - */ - public function enable(); + public function enable(): void; - /** - * @return void - */ - public function disable(); + public function disable(): void; - /** - * @return bool - */ - public function isEnabled(); + public function isEnabled(): bool; - /** - * @return string - */ - public function getId(); + public function getId(): string; - /** - * @param string $id - * @return void - */ - public function setId($id); + public function setId(string $id): void; - /** - * @return array - */ - public function getData(); + public function getData(): array; - /** - * @return bool - */ - public function hasData(); + public function hasData(): bool; - /** - * @return array - */ - public function getPush(); + public function getPush(): array; - /** - * @param $value - * @return void - */ - public function addPush($value); + public function addPush($value): void; - /** - * @param string $additionalParameters - * @return void - */ - public function setAdditionalParameters($additionalParameters); + public function setAdditionalParameters(string $additionalParameters): void; - /** - * @return string - */ - public function getAdditionalParameters(); + public function getAdditionalParameters(): string; } diff --git a/Tests/DependencyInjection/AbstractGoogleTagManagerExtensionTest.php b/Tests/DependencyInjection/AbstractGoogleTagManagerExtensionTest.php index f75e075..0e0cc23 100644 --- a/Tests/DependencyInjection/AbstractGoogleTagManagerExtensionTest.php +++ b/Tests/DependencyInjection/AbstractGoogleTagManagerExtensionTest.php @@ -10,7 +10,7 @@ namespace Xynnn\GoogleTagManagerBundle\Tests\DependencyInjection; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Xynnn\GoogleTagManagerBundle\DependencyInjection\GoogleTagManagerExtension; @@ -19,7 +19,7 @@ * * @package Xynnn\GoogleTagManagerBundle\Tests\DependencyInjection */ -abstract class AbstractGoogleTagManagerExtensionTest extends PHPUnit_Framework_TestCase +abstract class AbstractGoogleTagManagerExtensionTest extends TestCase { /** @var GoogleTagManagerExtension $extension */ private $extension; @@ -27,7 +27,7 @@ abstract class AbstractGoogleTagManagerExtensionTest extends PHPUnit_Framework_T /** @var ContainerBuilder $container */ private $container; - protected function setUp() + protected function setUp(): void { $this->extension = new GoogleTagManagerExtension(); diff --git a/Tests/Service/GoogleTagManagerTest.php b/Tests/Service/GoogleTagManagerTest.php index 77748fd..d87a5f9 100644 --- a/Tests/Service/GoogleTagManagerTest.php +++ b/Tests/Service/GoogleTagManagerTest.php @@ -10,7 +10,7 @@ namespace Xynnn\GoogleTagManagerBundle\Tests\Service; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Xynnn\GoogleTagManagerBundle\Service\GoogleTagManager; /** @@ -18,7 +18,7 @@ * * @package Xynnn\GoogleTagManagerBundle\Tests\Service */ -class GoogleTagManagerTest extends PHPUnit_Framework_TestCase +class GoogleTagManagerTest extends TestCase { public function testEnabledConfiguration() { diff --git a/composer.json b/composer.json index c42a236..d5ef2b9 100644 --- a/composer.json +++ b/composer.json @@ -11,17 +11,18 @@ "email": "philipp.braeutigam@googlemail.com" } ], - "minimum-stability": "dev", + "minimum-stability": "stable", "require": { - "php": ">=5.6", - "symfony/dependency-injection": "~2.8|~3.0|~4.0|~5.0", - "symfony/http-kernel": "~2.8|~3.0|~4.0|~5.0", - "symfony/config": "~2.8|~3.0|~4.0|~5.0", - "symfony/templating": "~2.8|~3.0|~4.0|~5.0", - "twig/twig": "~1.34|~2.0|~3.0" + "php": ">=8.0.2", + "symfony/dependency-injection": "^6.0", + "symfony/http-kernel": "^6.0", + "symfony/config": "^6.0", + "symfony/templating": "^6.0", + "twig/twig": "~1.34|~2.0|~3.0", + "symfony/yaml": "^6.0" }, "require-dev": { - "phpunit/phpunit": "~5" + "phpunit/phpunit": "^9" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 13d6ade..e961250 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,16 @@ - - - - ./Tests - - - - - ./ - - ./Tests - - - + + + + ./ + + + ./Tests + + + + + ./Tests + + \ No newline at end of file