GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SubscribeEvent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Drupal\df_tools_message\Event;
4
5
use Drupal\Core\Url;
6
use Symfony\Component\EventDispatcher\Event;
7
8
/**
9
 * Event that is fired when a user registers for a subscription.
10
 *
11
 * Also contains a lot of site-wide information, to fill in for Rules problems.
12
 */
13
class SubscribeEvent extends Event {
14
15
  const EVENT_NAME = 'df_tools_message_subscribe';
16
17
  /**
18
   * An email address.
19
   *
20
   * @var string
21
   */
22
  public $email;
23
24
  /**
25
   * The site name.
26
   *
27
   * @var string
28
   */
29
  public $site;
30
31
  /**
32
   * The absolute URL to the site.
33
   *
34
   * @var string
35
   */
36
  public $url;
37
38
  /**
39
   * The current langcode.
40
   *
41
   * @var string
42
   */
43
  public $langcode;
44
45
  /**
46
   * Constructs the object.
47
   *
48
   * @param string $email
49
   *   An email address.
50
   */
51
  public function __construct($email) {
52
    $this->email = $email;
53
    $query_options = [
54
      'utm_source' => 'subscription',
55
      'utm_medium' => 'email',
56
    ];
57
    $url = new Url('<front>');
58
    $this->url = $url->setOption('query', $query_options)->setAbsolute(TRUE)->toString();
0 ignored issues
show
Documentation Bug introduced by
It seems like $url->setOption('query',...olute(TRUE)->toString() can also be of type Drupal\Core\GeneratedUrl. However, the property $url is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
59
    $this->site = \Drupal::configFactory()->get('system.site')->get('name');
60
    $this->langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
61
  }
62
63
}
64