Commit 6ac6fade authored by Oleksii Skorobogatko's avatar Oleksii Skorobogatko
Browse files

Fix #3063979: Be compatible with php7.0, remove primitive return types

parent f5650d52
Loading
Loading
Loading
Loading
+3 −4
Changes for src/Controller/WebPushNotificationController.php: 3 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
@@ -35,7 +34,7 @@ class WebPushNotificationController extends ControllerBase {
   *
   * @param \Drupal\Core\Extension\ModuleHandler $moduleHandler
   *   The module handler service.
   * @param KeysHelper $keysHelper
   * @param \Drupal\web_push_notification\KeysHelper $keysHelper
   *   The notification keys helper service.
   */
  public function __construct(ModuleHandler $moduleHandler, KeysHelper $keysHelper) {
@@ -59,7 +58,7 @@ class WebPushNotificationController extends ControllerBase {
   * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
   *  The service worker content.
   */
  public function serviceWorker(): BinaryFileResponse {
  public function serviceWorker() {
    $module_path = $this->moduleHandler->getModule('web_push_notification')->getPath();
    $uri = "{$module_path}/js/service_worker.js";

@@ -87,7 +86,7 @@ class WebPushNotificationController extends ControllerBase {
   *   When required parameter (key, token, endpoint) is missing.
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  public function subscribe(Request $request): Response {
  public function subscribe(Request $request) {

    // Cannot accept a user confirmation when push keys are empty.
    if (!$this->keysHelper->isKeysDefined()) {
+2 −2
Changes for src/Form/BundleConfigForm.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ class BundleConfigForm extends ConfigFormBase {
   * @return \Drupal\Core\Field\FieldDefinitionInterface[]
   *   The array of field definitions for the bundle, keyed by field name.
   */
  protected function getBundleFields(string $bundle): array {
  protected function getBundleFields($bundle) {
    return $this->entityFieldManager->getFieldDefinitions('node', $bundle);
  }

@@ -156,7 +156,7 @@ class BundleConfigForm extends ConfigFormBase {
   * @return array
   *   The list of node bundles.
   */
  protected function getBundles(): array {
  protected function getBundles() {
    return $this->bundleInfo->getBundleInfo('node');
  }

+1 −1
Changes for src/Form/SettingsForm.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -298,7 +298,7 @@ class SettingsForm extends ConfigFormBase {
   * @param string $privateKey
   *   The private key.
   */
  protected function saveKeys(string $publicKey, string $privateKey) {
  protected function saveKeys($publicKey, $privateKey) {
    $this->config('web_push_notification.settings')
      ->set('public_key', $publicKey)
      ->set('private_key', $privateKey)
+6 −5
Changes for src/KeysHelper.php: 6 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ class KeysHelper {
   * HelperService constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config
   *   The config factory.
   */
  public function __construct(ConfigFactoryInterface $config) {
    $this->config = $config->get(self::SETTINGS);
@@ -33,7 +34,7 @@ class KeysHelper {
   * @return string
   *   The public key.
   */
  public function getPublicKey(): string {
  public function getPublicKey() {
    return $this->config->get('public_key');
  }

@@ -43,7 +44,7 @@ class KeysHelper {
   * @return string
   *   The private key.
   */
  public function getPrivateKey(): string {
  public function getPrivateKey() {
    return $this->config->get('private_key');
  }

@@ -55,7 +56,7 @@ class KeysHelper {
   *
   * @throws \ErrorException
   */
  public function generateKeys(): array {
  public function generateKeys() {
    return VAPID::createVapidKeys();
  }

@@ -64,7 +65,7 @@ class KeysHelper {
   *
   * @return bool
   */
  public function isKeysDefined(): bool {
  public function isKeysDefined() {
    $public = $this->getPublicKey();
    $private = $this->getPublicKey();
    return $public && $private;
@@ -80,7 +81,7 @@ class KeysHelper {
   *
   * @return array
   */
  public function getVapidAuth(): array {
  public function getVapidAuth() {
    if (!$this->isKeysDefined()) {
      throw new AuthKeysException('Public, private keys must be defined.');
    }
+2 −2
Changes for src/NotificationItem.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ class NotificationItem {
   * @param string $body
   *   The notification message (body).
   */
  public function __construct(string $title = '', string $body = '') {
  public function __construct($title = '', $body = '') {
    $this->title = $title;
    $this->body = $body;
  }
@@ -57,7 +57,7 @@ class NotificationItem {
   * @return string
   *   A JSON encoded payload.
   */
  public function payload(): string {
  public function payload() {
    return json_encode([
      'title' => $this->title,
      'body' => $this->body,
Loading