Skip to content
Snippets Groups Projects
Commit 1008423a authored by Patrick Kenny's avatar Patrick Kenny
Browse files

Issue #3483587 by ptmkenny: Require PHP 8.3

parent a032e132
No related branches found
No related tags found
1 merge request!40Require PHP 8.3
Pipeline #321453 passed
......@@ -43,3 +43,6 @@ variables:
OPT_IN_TEST_PREVIOUS_MAJOR: '1'
# _CURL_TEMPLATES_REF: 'main'
composer (previous major):
variables:
PHP_VERSION: '8.3'
......@@ -3,7 +3,7 @@
"description": "Provides firebase-php as a service for Drupal.",
"type": "drupal-module",
"require": {
"php": ">=8.1",
"php": ">=8.3",
"ext-sodium": "*",
"kreait/firebase-php": "^7"
},
......
......@@ -19,6 +19,7 @@ class FirebasePhpConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function getFormId(): string {
return self::FORM_ID;
}
......@@ -26,6 +27,7 @@ class FirebasePhpConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
protected function getEditableConfigNames(): array {
return [self::FORM_ID];
}
......@@ -33,6 +35,7 @@ class FirebasePhpConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function buildForm(array $form, FormStateInterface $form_state): array {
$config = $this->config(self::FORM_ID);
......@@ -70,6 +73,7 @@ class FirebasePhpConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function submitForm(array &$form, FormStateInterface $form_state): void {
$config = $this->config(self::FORM_ID);
$config
......@@ -83,6 +87,7 @@ class FirebasePhpConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function validateForm(array &$form, FormStateInterface $form_state): void {
$settings = $form_state->getValues();
$file_path = $settings[FirebasePhpSettings::CredentialsPath->value];
......@@ -100,7 +105,7 @@ class FirebasePhpConfigurationForm extends ConfigFormBase {
}
// Is it obviously insecure?
if (str_starts_with('public://', $file_path)) {
if (str_starts_with('public://', (string) $file_path)) {
$form_state->setErrorByName('path_invalid', $this->t('You cannot use a public file. That is insecure.'));
return;
}
......
......@@ -14,22 +14,18 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* Provides a form to send a test push notification.
*/
final class FirebasePhpSendTestMessageForm extends FormBase {
/**
* The Firebase PHP messaging service from this module.
*
* @var \Drupal\firebase_php\FirebasePhpMessagingApiInterface
*/
protected FirebasePhpMessagingApiInterface $messagingService;
public function __construct(FirebasePhpMessagingApiInterface $messagingService) {
$this->messagingService = $messagingService;
public function __construct(
protected FirebasePhpMessagingApiInterface $messagingService,
) {
}
/**
* {@inheritdoc}
*/
#[\Override]
public static function create(ContainerInterface $container): FirebasePhpSendTestMessageForm {
return new static(
return new self(
$container->get('firebase_php.messaging_drupal_api')
);
}
......@@ -37,6 +33,7 @@ final class FirebasePhpSendTestMessageForm extends FormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function getFormId(): string {
return 'firebase_php_send_test_message_form';
}
......@@ -44,6 +41,7 @@ final class FirebasePhpSendTestMessageForm extends FormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function buildForm(array $form, FormStateInterface $form_state): array {
$form['title'] = [
'#type' => 'textfield',
......@@ -90,6 +88,7 @@ final class FirebasePhpSendTestMessageForm extends FormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function submitForm(array &$form, FormStateInterface $form_state): void {
try {
$this->messagingService->sendMessageSingleDevice(
......
......@@ -14,22 +14,18 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* Provides a form to validate tokens for sending push notifications.
*/
final class FirebasePhpValidateTokenForm extends FormBase {
/**
* The Firebase PHP messaging service from this module.
*
* @var \Drupal\firebase_php\FirebasePhpMessagingApiInterface
*/
protected FirebasePhpMessagingApiInterface $messagingService;
public function __construct(FirebasePhpMessagingApiInterface $messagingService) {
$this->messagingService = $messagingService;
public function __construct(
protected FirebasePhpMessagingApiInterface $messagingService,
) {
}
/**
* {@inheritdoc}
*/
#[\Override]
public static function create(ContainerInterface $container): FirebasePhpValidateTokenForm {
return new static(
return new self(
$container->get('firebase_php.messaging_drupal_api')
);
}
......@@ -37,6 +33,7 @@ final class FirebasePhpValidateTokenForm extends FormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function getFormId(): string {
return 'firebase_php_validate_token_form';
}
......@@ -44,6 +41,7 @@ final class FirebasePhpValidateTokenForm extends FormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function buildForm(array $form, FormStateInterface $form_state): array {
$form['device_token'] = [
'#type' => 'textarea',
......@@ -71,12 +69,13 @@ final class FirebasePhpValidateTokenForm extends FormBase {
/**
* {@inheritdoc}
*/
#[\Override]
public function submitForm(array &$form, FormStateInterface $form_state): void {
try {
$tokens_string = $form_state->getValue('device_token');
// array_filter removes the empty strings.
/** @var non-empty-string[] $tokens_array */
$tokens_array = array_filter(explode(',', $tokens_string));
$tokens_array = array_filter(explode(',', (string) $tokens_string));
$output = $this->messagingService->getMessaging()->validateRegistrationTokens($tokens_array);
$output_message = $this->t('Device token validation results: %output', [
......
......@@ -27,6 +27,7 @@ class FirebasePhpMessagingApi extends FirebasePhpMessagingService implements Fir
/**
* {@inheritdoc}
*/
#[\Override]
public function getMessaging(): Messaging {
return $this->messaging;
}
......@@ -34,6 +35,7 @@ class FirebasePhpMessagingApi extends FirebasePhpMessagingService implements Fir
/**
* {@inheritdoc}
*/
#[\Override]
public function sendMessageSingleDevice(
string $device_token,
?string $notification_title,
......@@ -53,6 +55,7 @@ class FirebasePhpMessagingApi extends FirebasePhpMessagingService implements Fir
/**
* {@inheritdoc}
*/
#[\Override]
public function sendMessageTopic(
string $topic,
?string $notification_title,
......@@ -72,6 +75,7 @@ class FirebasePhpMessagingApi extends FirebasePhpMessagingService implements Fir
/**
* {@inheritdoc}
*/
#[\Override]
public function sendMessageMultipleDevices(
array $device_tokens,
?string $notification_title,
......@@ -216,6 +220,7 @@ class FirebasePhpMessagingApi extends FirebasePhpMessagingService implements Fir
/**
* {@inheritdoc}
*/
#[\Override]
public function validateToken(string $token): bool {
if (trim($token) === '') {
throw new FirebasePhpInvalidArgumentException('Token cannot be an empty string!');
......@@ -225,10 +230,7 @@ class FirebasePhpMessagingApi extends FirebasePhpMessagingService implements Fir
$output = $messaging_service->validateRegistrationTokens($token);
// We are only validating one token, so if there is a single invalid result,
// the token is invalid.
if (isset($output['invalid'][0])) {
return FALSE;
}
return TRUE;
return !isset($output['invalid'][0]);
}
}
......@@ -13,7 +13,7 @@ use Drupal\KernelTests\KernelTestBase;
*/
class FirebasePhpInstallTest extends KernelTestBase {
private const MODULE_NAME = 'firebase_php';
private const string MODULE_NAME = 'firebase_php';
/**
* Test that the module can be installed and uninstalled.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment