Passed
Pull Request — 8.x-2.x (#58)
by Frédéric G.
03:34
created

SettingsCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
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