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.
Passed
Push — 8.x-4.x ( d31c87...fae10e )
by Kevin
05:08
created

one_preprocess_html()   B

Complexity

Conditions 11
Paths 15

Size

Total Lines 33
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 19
c 1
b 0
f 0
nc 15
nop 1
dl 0
loc 33
rs 7.3166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @file
4
 * Theme and preprocess functions for html.
5
 */
6
7
/**
8
 * Implements template_preprocess_html().
9
 *
10
 * Adds additional classes
11
 */
12
function one_preprocess_html(&$variables) {
13
  /* @var Drupal\Core\Language\LanguageInterface */
14
  $language = \Drupal::languageManager()->getCurrentLanguage();
15
  $site_language = $language->getId();
16
  $request = \Drupal::request();
17
18
  // Add language body class.
19
  $variables['attributes']['class'][] = 'lang-' . $site_language;
20
21
  // Classes for body element. Allows advanced theming based on context
22
  $is_front_page = \Drupal::service('path.matcher')->isFrontPage();
23
  if (!$is_front_page) {
24
    $path = trim($request->getRequestUri(), '/');
25
    // Add unique class for each website section.
26
    $arg = explode('/', $path);
27
    $section = $arg[0];
28
    if ($arg[0] == 'node' && isset($arg[1])) {
29
      if ($arg[1] == 'add') {
30
        $section = 'node-add';
31
      }
32
      elseif (isset($arg[2]) && is_numeric($arg[1]) && ($arg[2] == 'edit' || $arg[2] == 'delete')) {
33
        $section = 'node-' . $arg[2];
34
      }
35
    }
36
    $variables['attributes']['class'][] = \Drupal\Component\Utility\Html::getClass('section-' . $section);
37
  }
38
39
  // Store the menu item since it has some useful information.
40
  if ($request->attributes->get('view_id')) {
41
    $variables['attributes']['class'][] = 'views-page';
42
  }
43
  elseif ($request->attributes->get('panel')) {
44
    $variables['attributes']['class'][] = 'panels-page';
45
  }
46
}
47