Completed
Pull Request — 8.x-2.x (#24)
by Frédéric G.
03:06
created

ControllerBase::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace Drupal\mongodb_watchdog\Controller;
4
5
use Drupal\Core\Config\ImmutableConfig;
6
use Drupal\Core\Controller\ControllerBase as CoreControllerBase;
7
use Drupal\mongodb_watchdog\Logger;
8
use Psr\Log\LoggerAwareTrait;
9
use Psr\Log\LoggerInterface;
10
use Symfony\Component\DependencyInjection\ContainerInterface;
11
12
abstract class ControllerBase extends CoreControllerBase {
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
13
14
  use LoggerAwareTrait;
15
16
  /**
17
   * The items_per_page configuration value.
18
   *
19
   * @var int
20
   */
21
  protected $itemsPerPage;
22
23
  /**
24
   * The MongoDB logger, to load events.
25
   *
26
   * @var \Drupal\mongodb_watchdog\Logger
27
   */
28
  protected $watchdog;
29
30
  /**
31
   * ControllerBase constructor.
32
   *
33
   * @param \Drupal\Core\Config\ImmutableConfig $config
34
   *   The module configuration.
35
   */
36
  public function __construct(LoggerInterface $logger, Logger $watchdog, ImmutableConfig $config) {
37
    $this->setLogger($logger);
38
39
    $this->itemsPerPage = $config->get('items_per_page');
40
    $this->watchdog = $watchdog;
41
  }
42
43
  public static function create(ContainerInterface $container) {
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
44
    $logger = $container->get('logger.channel.mongodb_watchdog');
45
    $watchdog = $container->get('mongodb.logger');
0 ignored issues
show
Unused Code introduced by
$watchdog 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...
introduced by
Unused variable $watchdog.
Loading history...
46
47
    return new static($logger);
48
  }
49
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
50