Passed
Push — 8.x-2.x ( 28cdbd...dac389 )
by Frédéric G.
01:03 queued 11s
created

SettingsCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 59
loc 59
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A configure() 9 9 1
A execute() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Drupal\mongodb\Command;
6
7
use Drupal\Component\Serialization\SerializationInterface;
8
use Drupal\mongodb\Install\Tools;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Drupal\Console\Core\Command\ContainerAwareCommand;
12
// @codingStandardsIgnoreLine
13
use Drupal\Console\Annotations\DrupalCommand;
14
15
/**
16
 * Class SettingsCommand.
17
 *
18
 * @DrupalCommand (
19
 *     extension="mongodb",
20
 *     extensionType="module"
21
 * )
22
 */
23 View Code Duplication
class SettingsCommand extends ContainerAwareCommand {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
25
  const NAME = 'commands.mongodb.settings';
26
27
  /**
28
   * The mongodb.tools service.
29
   *
30
   * @var \Drupal\mongodb\Install\Tools
31
   */
32
  protected $tools;
33
34
  /**
35
   * The serialization.yaml service.
36
   *
37
   * @var \Drupal\Component\Serialization\SerializationInterface
38
   */
39
  protected $serialization;
40
41
  /**
42
   * SettingsCommand constructor.
43
   *
44
   * @param \Drupal\mongodb\Install\Tools $tools
45
   *   The mongodb.tools service.
46
   * @param \Drupal\Component\Serialization\SerializationInterface $yaml
47
   *   The serialization.yaml service.
48
   */
49
  public function __construct(Tools $tools, SerializationInterface $yaml) {
50
    parent::__construct();
51
    $this->serialization = $yaml;
52
    $this->tools = $tools;
53
  }
54
55
  /**
56
   * {@inheritdoc}
57
   */
58
  protected function configure() {
59
    $name = static::NAME;
60
61
    $this
62
      ->setName('mongodb:settings')
63
      ->setAliases(['mdbs', 'mo-set'])
64
      ->setDescription($this->trans("${name}.description"))
65
      ->setHelp($this->trans("${name}.help"));
66
  }
67
68
  /**
69
   * {@inheritdoc}
70
   */
71
  protected function execute(InputInterface $input, OutputInterface $output) {
72
    $this
73
      ->getIo()
74
      ->write(
75
        $this->serialization->encode(
76
          $this->tools->settings()
77
        )
78
      );
79
  }
80
81
}
82