ImportCreateDefaultConfigCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 13
c 2
b 1
f 1
dl 0
loc 58
ccs 0
cts 16
cp 0
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileName() 0 3 1
A configure() 0 8 1
A executeSimpleCommand() 0 15 1
A getFilePathComplete() 0 3 1
1
<?php
2
/**
3
 * TechDivision\Import\Cli\Command\ImportClearPidFileCommand
4
 *
5
 * PHP version 7
6
 *
7
 * @author    [email protected]
8
 * @copyright 2023 TechDivision GmbH <[email protected]>
9
 * @license   https://opensource.org/licenses/MIT
10
 * @link      https://github.com/techdivision/import-cli-simple
11
 * @link      http://www.techdivision.com
12
 */
13
14
namespace TechDivision\Import\Cli\Command;
15
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use TechDivision\Import\Configuration\ConfigurationInterface;
19
use TechDivision\Import\Utils\CommandNames;
20
use Symfony\Component\Filesystem\Filesystem;
21
22
/**
23
 * The import command implementation.
24
 *
25
 * @author    [email protected]
26
 * @copyright 2023 TechDivision GmbH <[email protected]>
27
 * @license   https://opensource.org/licenses/MIT
28
 * @link      https://github.com/techdivision/import-cli-simple
29
 * @link      http://www.techdivision.com
30
 */
31
class ImportCreateDefaultConfigCommand extends AbstractSimpleImportCommand
32
{
33
    /**
34
     * Configures the current command.
35
     *
36
     * @return void
37
     * @see \Symfony\Component\Console\Command\Command::configure()
38
     */
39
    protected function configure(): void
40
    {
41
        // initialize the command with the required/optional options
42
        $this->setName(CommandNames::IMPORT_CREATE_CONFIG)
43
            ->setDescription('Create the default config file which is used by the diff command');
44
45
        // invoke the parent method
46
        parent::configure();
47
    }
48
49
    /**
50
     * Finally executes the simple command.
51
     *
52
     * @param ConfigurationInterface $configuration The configuration instance
53
     * @param InputInterface         $input         An InputInterface instance
54
     * @param OutputInterface        $output        An OutputInterface instance
55
     *
56
     * @return int
57
     */
58
    protected function executeSimpleCommand(
59
        ConfigurationInterface $configuration,
60
        InputInterface $input,
61
        OutputInterface $output
62
    ): int {
63
        $serializer = $this->createSerializer();
64
        $configValues = $serializer->serialize($configuration, 'json');
65
66
        // create new default json file
67
        $fs = new Filesystem();
68
        $fs->remove($this->getFilePathComplete());
69
        $fs->appendToFile($this->getFilePathComplete(), $configValues);
70
71
        $output->writeln('[*] successfully created default file');
72
        return 0;
0 ignored issues
show
Bug Best Practice introduced by
The expression return 0 returns the type integer which is incompatible with the return type mandated by TechDivision\Import\Cli\...:executeSimpleCommand() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getFileName(): string
79
    {
80
        return ImportConfigDiffCommand::DEFAULT_FILE;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getFilePathComplete(): string
87
    {
88
        return __DIR__ . '/../../' . $this->getFileName() . '.simple';
89
    }
90
}
91