Skip to content

Commit

Permalink
Upgrade to PHP8.1 (#41)
Browse files Browse the repository at this point in the history
BREAKING: Drop support for PHP7

Fixes compatibility with PHP8.2 (ArrayAccess implementation). Makes use of PHP8 syntax improvements across the bundle
  • Loading branch information
121593 committed Apr 25, 2023
1 parent e90319c commit 102ac1c
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 84 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=7.1",
"php": ">=8.1",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down
12 changes: 3 additions & 9 deletions src/Action/RegisterSubscriptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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)
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Command/WebPushGenerateKeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function configure()

/**
* {@inheritdoc}
* @throws \ErrorException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/WebPushCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/WebPushExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
15 changes: 5 additions & 10 deletions src/Model/Message/PushMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
36 changes: 11 additions & 25 deletions src/Model/Message/PushNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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]);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down
19 changes: 4 additions & 15 deletions src/Model/Response/PushResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Subscription/UserSubscriptionManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)));
Expand Down
12 changes: 3 additions & 9 deletions src/Twig/WebPushTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 102ac1c

Please sign in to comment.