Passed
Pull Request — master (#17)
by
unknown
13:11 queued 03:05
created

ImportCreateDefaultConfigCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
dl 0
loc 43
rs 10
c 1
b 0
f 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A executeSimpleCommand() 0 16 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)
0 ignored issues
show
Bug introduced by
The constant TechDivision\Import\Util...s::IMPORT_CREATE_CONFIG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
    {
64
        $serializer = $this->createSerializer();
65
        $configValues = $serializer->serialize($configuration, 'json');
66
67
        // create new default json file
68
        $fs = new Filesystem();
69
        $fs->remove(ImportConfigDiffCommand::DEFAULT_FILE);
70
        $fs->appendToFile(ImportConfigDiffCommand::DEFAULT_FILE, $configValues);
71
72
        $output->writeln('[*] successfully created default file');
73
        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...
74
    }
75
}
76