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-1.x ( 869a51...b7bfed )
by Brant
03:09 queued 54s
created

MenuRouterRebuildSubscriber   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 8
c 2
b 0
f 2
lcom 0
cbo 0
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B onKernelRequestMenuRouterRebuild() 0 12 7
A getSubscribedEvents() 0 5 1
1
<?php
2
3
/**
4
 * @file
5
 * Contains \Drupal\df_admin\EventSubscriber\MenuRouterRebuildSubscriber.
6
 */
7
8
namespace Drupal\df_admin\EventSubscriber;
9
10
use Symfony\Component\HttpKernel\KernelEvents;
11
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
12
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13
14
/**
15
 * Rebuilds the menu router to ensure image derivatives are created.
16
 */
17
class MenuRouterRebuildSubscriber implements EventSubscriberInterface {
18
19
  /**
20
   * Rebuilds the menu router if the rebuild.dat file is found.
21
   *
22
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
23
   *   The Event to process.
24
   */
25
  public function onKernelRequestMenuRouterRebuild(GetResponseEvent $event) {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    if (file_exists("public://rebuild.dat")) {
27
      $site_path = preg_replace('/^sites\//', '', \Drupal::service('site.path'));
28
      if (!file_exists('public://.drushrc') && file_exists('public://') && is_writable('public://') && file_put_contents('public:///.drushrc', "<?php\n\$options['l'] = 'http://${site_path}';")) {
29
        drupal_chmod('public:///.drushrc', 0444);
30
      }
31
32
      if (\Drupal::service('router.builder')->rebuild()) {
33
        file_unmanaged_delete("public://rebuild.dat");
34
      }
35
    }
36
  }
37
38
  /**
39
   * {@inheritdoc}
40
   */
41
  static function getSubscribedEvents() {
42
    $events[KernelEvents::REQUEST][] = ['onKernelRequestMenuRouterRebuild', 255];
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...
43
44
    return $events;
45
  }
46
47
}
48
49