diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33fd308..0ad379c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: operating-system: ['ubuntu-latest'] - php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php-versions: ['8.1', '8.2'] steps: - name: Checkout @@ -24,16 +24,7 @@ jobs: php-version: ${{ matrix.php-versions }} ini-values: post_max_size=256M, max_execution_time=180 - # Legacy PHP versions ^7.1 - name: Install Dependencies - if: ${{ matrix.php-versions < '8.0' }} - run: composer update $COMPOSER_FLAGS --no-interaction --prefer-dist --no-progress --ansi - env: - COMPOSER_FLAGS: "--prefer-lowest --prefer-stable" - - # Modern PHP versions >= 8.0 - - name: Install Dependencies - if: ${{ matrix.php-versions >= '8.0' }} run: composer update $COMPOSER_FLAGS --no-interaction --prefer-dist --no-progress --ansi - name: Process the tests diff --git a/composer.json b/composer.json index 697c602..0741c8a 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=7.1", + "php": ">=8.1", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", diff --git a/src/Action/RegisterSubscriptionAction.php b/src/Action/RegisterSubscriptionAction.php index 2e132f7..100584c 100644 --- a/src/Action/RegisterSubscriptionAction.php +++ b/src/Action/RegisterSubscriptionAction.php @@ -12,17 +12,11 @@ final class RegisterSubscriptionAction { - /** - * @var UserSubscriptionManagerRegistry - */ - private $registry; - /** * RegisterSubscriptionAction constructor. */ - public function __construct(UserSubscriptionManagerRegistry $registry) + public function __construct(private readonly UserSubscriptionManagerRegistry $registry) { - $this->registry = $registry; } /** @@ -31,7 +25,7 @@ public function __construct(UserSubscriptionManagerRegistry $registry) * @throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException * @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ - private function subscribe(UserInterface $user, string $subscriptionHash, array $subscription, array $options = []) + private function subscribe(UserInterface $user, string $subscriptionHash, array $subscription, array $options = []): void { $manager = $this->registry->getManager($user); $userSubscription = $manager->getUserSubscription($user, $subscriptionHash) @@ -43,7 +37,7 @@ private function subscribe(UserInterface $user, string $subscriptionHash, array * @throws BadRequestHttpException * @throws \RuntimeException */ - private function unsubscribe(UserInterface $user, string $subscriptionHash) + private function unsubscribe(UserInterface $user, string $subscriptionHash): void { $manager = $this->registry->getManager($user); $subscription = $manager->getUserSubscription($user, $subscriptionHash); diff --git a/src/Command/WebPushGenerateKeysCommand.php b/src/Command/WebPushGenerateKeysCommand.php index 3a3ceeb..aea5ac1 100644 --- a/src/Command/WebPushGenerateKeysCommand.php +++ b/src/Command/WebPushGenerateKeysCommand.php @@ -25,6 +25,7 @@ protected function configure() /** * {@inheritdoc} + * @throws \ErrorException */ protected function execute(InputInterface $input, OutputInterface $output): int { diff --git a/src/DependencyInjection/WebPushCompilerPass.php b/src/DependencyInjection/WebPushCompilerPass.php index f10264f..aa3a1fb 100644 --- a/src/DependencyInjection/WebPushCompilerPass.php +++ b/src/DependencyInjection/WebPushCompilerPass.php @@ -9,7 +9,7 @@ final class WebPushCompilerPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $registry = $container->getDefinition(UserSubscriptionManagerRegistry::class); $taggedSubscriptionManagers = $container->findTaggedServiceIds('bentools_webpush.subscription_manager'); diff --git a/src/DependencyInjection/WebPushExtension.php b/src/DependencyInjection/WebPushExtension.php index bf2122a..7d6c651 100644 --- a/src/DependencyInjection/WebPushExtension.php +++ b/src/DependencyInjection/WebPushExtension.php @@ -17,7 +17,7 @@ class WebPushExtension extends Extension /** * {@inheritdoc} */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); diff --git a/src/Model/Message/PushMessage.php b/src/Model/Message/PushMessage.php index f6126ca..2303b2d 100644 --- a/src/Model/Message/PushMessage.php +++ b/src/Model/Message/PushMessage.php @@ -10,19 +10,14 @@ */ final class PushMessage { - private $payload; - private $options; - private $auth; - /** * PushMessage constructor. */ - public function __construct(?string $payload = null, array $options = [], array $auth = []) - { - $this->payload = $payload; - $this->options = $options; - $this->auth = $auth; - } + public function __construct( + private ?string $payload = null, + private array $options = [], + private array $auth = [], + ) {} public function setPayload(?string $payload): void { diff --git a/src/Model/Message/PushNotification.php b/src/Model/Message/PushNotification.php index 1f91723..1e9b083 100644 --- a/src/Model/Message/PushNotification.php +++ b/src/Model/Message/PushNotification.php @@ -24,24 +24,13 @@ final class PushNotification implements JsonSerializable, ArrayAccess const ACTIONS = 'actions'; const TIMESTAMP = 'timestamp'; - /** - * @var string|null - */ - private $title; - - /** - * @var array - */ - private $options; - /** * PushNotification constructor. */ - public function __construct(?string $title, array $options = []) - { - $this->title = $title; - $this->options = $options; - } + public function __construct( + private ?string $title, + private array $options = [], + ) {} public function getTitle(): ?string { @@ -63,10 +52,7 @@ public function setOptions(array $options): void $this->options = $options; } - /** - * @param mixed $value - */ - public function setOption(string $key, $value): void + public function setOption(string $key, mixed $value): void { if (null === $value) { unset($this->options[$key]); @@ -77,7 +63,7 @@ public function setOption(string $key, $value): void $this->options[$key] = $value; } - public function getOption($key) + public function getOption(string $key): mixed { return $this->options[$key] ?? null; } @@ -116,7 +102,7 @@ public function __toString(): string * * @since 5.0.0 */ - public function offsetExists($offset): bool + public function offsetExists(mixed $offset): bool { return array_key_exists($offset, $this->options); } @@ -134,7 +120,7 @@ public function offsetExists($offset): bool * * @since 5.0.0 */ - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { return $this->options[$offset] ?? null; } @@ -155,7 +141,7 @@ public function offsetGet($offset) * * @since 5.0.0 */ - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { $this->options[$offset] = $value; } @@ -173,12 +159,12 @@ public function offsetSet($offset, $value): void * * @since 5.0.0 */ - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { unset($this->options[$offset]); } - private static function sanitize($input) + private static function sanitize(mixed $input): mixed { if (is_array($input)) { foreach ($input as $key => $value) { diff --git a/src/Model/Response/PushResponse.php b/src/Model/Response/PushResponse.php index a3aeb26..bd569ce 100644 --- a/src/Model/Response/PushResponse.php +++ b/src/Model/Response/PushResponse.php @@ -13,24 +13,13 @@ final class PushResponse const PAYLOAD_SIZE_TOO_LARGE = 413; const TOO_MANY_REQUESTS = 429; - /** - * @var int - */ - private $statusCode; - - /** - * @var UserSubscriptionInterface - */ - private $subscription; - /** * WebPushResponse constructor. */ - public function __construct(UserSubscriptionInterface $subscription, int $statusCode) - { - $this->subscription = $subscription; - $this->statusCode = $statusCode; - } + public function __construct( + private UserSubscriptionInterface $subscription, + private int $statusCode, + ) {} public function getSubscription(): UserSubscriptionInterface { diff --git a/src/Model/Subscription/UserSubscriptionManagerRegistry.php b/src/Model/Subscription/UserSubscriptionManagerRegistry.php index b507c9f..a735451 100644 --- a/src/Model/Subscription/UserSubscriptionManagerRegistry.php +++ b/src/Model/Subscription/UserSubscriptionManagerRegistry.php @@ -12,12 +12,12 @@ final class UserSubscriptionManagerRegistry implements UserSubscriptionManagerIn /** * @var UserSubscriptionManagerInterface[] */ - private $registry = []; + private array $registry = []; /** * @throws \InvalidArgumentException */ - public function register(string $userClass, UserSubscriptionManagerInterface $userSubscriptionManager) + public function register(string $userClass, UserSubscriptionManagerInterface $userSubscriptionManager): void { if (!is_a($userClass, UserInterface::class, true)) { throw new \InvalidArgumentException(sprintf('Expected class implementing %s, %s given', UserInterface::class, $userClass)); @@ -42,7 +42,7 @@ public function register(string $userClass, UserSubscriptionManagerInterface $us * @throws \InvalidArgumentException * @throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException */ - public function getManager($userClass): UserSubscriptionManagerInterface + public function getManager(UserInterface|string $userClass): UserSubscriptionManagerInterface { if (!is_a($userClass, UserInterface::class, true)) { throw new \InvalidArgumentException(sprintf('Expected class or object that implements %s, %s given', UserInterface::class, is_object($userClass) ? get_class($userClass) : gettype($userClass))); diff --git a/src/Twig/WebPushTwigExtension.php b/src/Twig/WebPushTwigExtension.php index 65957ab..691143f 100644 --- a/src/Twig/WebPushTwigExtension.php +++ b/src/Twig/WebPushTwigExtension.php @@ -7,15 +7,9 @@ final class WebPushTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * @var string - */ - private $publicKey; - - public function __construct(?string $publicKey) - { - $this->publicKey = $publicKey; - } + public function __construct( + private ?string $publicKey, + ) {} /** * {@inheritdoc}