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.

LatestCheckSubscriber::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
Comprehensibility Best Practice introduced by
$events was never initialized. Although not strictly required by PHP, it is generally a good practice to add $events = array(); before regardless.
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
The assignment to $node is dead and can be removed.
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