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.
Completed
Push — 8.x-2.x ( acccba...703370 )
by Devin
03:51
created

LatestCheckSubscriber   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 4 1
A checkForLatest() 0 9 3
1
<?php
2
3
namespace Drupal\df_tools_workflow\EventSubscriber;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Symfony\Component\EventDispatcher\Event;
7
use Symfony\Component\HttpKernel\Event\KernelEvent;
8
use Symfony\Component\HttpKernel\KernelEvents;
9
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
10
use Drupal\Core\Cache\CacheTagsInvalidator;
11
use Drupal\Core\Theme\ThemeManager;
12
13
14
/**
15
 * Class LatestCheckSubscriber.
16
 *
17
 * @package Drupal\df_tools_workflow
18
 */
19
class LatestCheckSubscriber implements EventSubscriberInterface {
20
21
  /**
22
   * Drupal\Core\Cache\CacheTagsInvalidator definition.
23
   *
24
   * @var \Drupal\Core\Cache\CacheTagsInvalidator
25
   */
26
  protected $cacheTagsInvalidator;
27
28
  /**
29
   * Drupal\Core\Theme\ThemeManager definition.
30
   *
31
   * @var \Drupal\Core\Theme\ThemeManager
32
   */
33
  protected $themeManager;
34
35
  /**
36
   * Constructor.
37
   */
38
  public function __construct(CacheTagsInvalidator $cache_tags_invalidator, ThemeManager $theme_manager) {
39
    $this->cacheTagsInvalidator = $cache_tags_invalidator;
40
    $this->themeManager = $theme_manager;
41
  }
42
43
  /**
44
   * {@inheritdoc}
45
   */
46
  static function getSubscribedEvents() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
47
    $events[KernelEvents::REQUEST][] = array('checkForLatest');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$events was never initialized. Although not strictly required by PHP, it is generally a good practice to add $events = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
48
    return $events;
49
  }
50
51
  /**
52
   * Given 'node' in the request params,
53
   * and the current user can view 'latest' revisions:
54
   * Invalidate the current theme's local actions cache,
55
   * so that hook_menu_local_tasks_alter() is called.
56
   *
57
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
58
   */
59
  public function checkForLatest(GetResponseEvent $event) {
60
    if ($node = $event->getRequest()->get('node')) {
0 ignored issues
show
Unused Code introduced by
$node is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
      if (\Drupal::currentUser()->hasPermission('view latest version')) {
62
        $theme = $this->themeManager->getActiveTheme()->getName();
63
        $tag = 'config:block.block.' . $theme . '_local_actions';
64
        $this->cacheTagsInvalidator->invalidateTags([$tag]);
65
      }
66
    }
67
  }
68
69
}
70