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

Issue #3446597 by ptmkenny: Raise PHPStan to level 8

parent 6e3cd775
No related branches found
No related tags found
1 merge request!6raise the PHPStan level
Pipeline #170259 failed
parameters:
checkGenericClassInNonGenericObjectType: false
# Sometimes Drupal gets it wrong.
treatPhpDocTypesAsCertain: false
level: 8
ignoreErrors:
# Drupal does not define its own arrays.
- '#no value type specified in iterable type array#'
......@@ -17,21 +17,21 @@ class FirebasePhpConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
public function getFormId(): string {
return self::FORM_ID;
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
protected function getEditableConfigNames(): array {
return [self::FORM_ID];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
public function buildForm(array $form, FormStateInterface $form_state): array {
$config = $this->config(self::FORM_ID);
$form['firebase'] = [
......@@ -59,7 +59,7 @@ class FirebasePhpConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state): void {
$config = $this->config(self::FORM_ID);
$config
->set(self::KEY_CREDENTIALS_PATH, $form_state->getValue(self::KEY_CREDENTIALS_PATH))
......@@ -71,7 +71,7 @@ class FirebasePhpConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
public function validateForm(array &$form, FormStateInterface $form_state): void {
$settings = $form_state->getValues();
$file_path = $settings[self::KEY_CREDENTIALS_PATH];
......
......@@ -28,7 +28,7 @@ final class FirebasePhpSendTestMessageForm extends FormBase {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
public static function create(ContainerInterface $container): FirebasePhpSendTestMessageForm {
return new static(
$container->get('firebase_php.messaging')
);
......
......@@ -102,7 +102,10 @@ class FirebasePhpMessagingService implements FirebasePhpMessagingServiceInterfac
]);
if ($report->hasFailures()) {
foreach ($report->failures()->getItems() as $failure) {
$failure_message = '';
if ($failure instanceof \Throwable) {
$failure_message = $failure->error()->getMessage();
}
$this->logger->warning('Failed to send push notification to user @uid: @failure_message', [
'@uid' => $this->account->id(),
'@failure_message' => $failure_message,
......@@ -121,9 +124,9 @@ class FirebasePhpMessagingService implements FirebasePhpMessagingServiceInterfac
* The optional badge count.
* @param string|null $deviceToken
* The optional device token.
* @param array $data
* @param array|null $data
* The optional message data.
* @param array $apns_data
* @param array|null $apns_data
* The optional APNS data.
* @param string|null $topic
* The optional topic.
......@@ -135,20 +138,23 @@ class FirebasePhpMessagingService implements FirebasePhpMessagingServiceInterfac
Notification $notification,
?int $badge_count = NULL,
?string $deviceToken = NULL,
array $data = [],
array $apns_data = [],
?array $data = NULL,
?array $apns_data = NULL,
?string $topic = NULL,
): Message {
$message_inputs = [
'notification' => $notification,
];
if ($data) {
if (is_array($data)) {
$message_inputs['data'] = $data;
}
if (is_string($deviceToken)) {
if (is_string($deviceToken) && trim($deviceToken) !== '') {
/** @var non-empty-string $deviceToken */
$message_inputs['token'] = $deviceToken;
}
elseif (is_string($topic)) {
elseif (is_string($topic) && trim($topic) !== '') {
/** @var non-empty-string $topic */
$message_inputs['topic'] = $topic;
}
else {
......@@ -156,7 +162,8 @@ class FirebasePhpMessagingService implements FirebasePhpMessagingServiceInterfac
}
$message = CloudMessage::fromArray($message_inputs);
if (!empty($apns_data)) {
if (is_array($apns_data)) {
$message = $message->withApnsConfig($apns_data);
}
elseif (is_int($badge_count) && $badge_count >= 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment