Completed
Pull Request — master (#74)
by Tim
14:37 queued 05:46
created

ImportClearPidFileCommand::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 27
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 27
loc 27
rs 8.8571
c 0
b 0
f 0
ccs 0
cts 25
cp 0
cc 1
eloc 20
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Cli\Command\ImportClearPidFileCommand
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-cli-simple
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Cli\Command;
22
23
use TechDivision\Import\ConfigurationInterface;
24
use TechDivision\Import\Configuration\Jms\Configuration;
25
use Symfony\Component\Console\Input\InputOption;
26
use Symfony\Component\Console\Input\InputInterface;
27
use Symfony\Component\Console\Output\OutputInterface;
28
29
/**
30
 * The remove PID command implementation.
31
 *
32
 * @author    Tim Wagner <[email protected]>
33
 * @copyright 2016 TechDivision GmbH <[email protected]>
34
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
 * @link      https://github.com/techdivision/import-cli-simple
36
 * @link      http://www.techdivision.com
37
 */
38
class ImportClearPidFileCommand extends AbstractSimpleImportCommand
39
{
40
41
    /**
42
     * Configures the current command.
43
     *
44
     * @return void
45
     * @see \Symfony\Component\Console\Command\Command::configure()
46
     */
47 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method 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...
48
    {
49
50
        // initialize the command with the required/optional options
51
        $this->setName('import:clear:pid-file')
52
            ->setDescription('Clears the PID file from a previous import process, if it has not been cleaned up')
53
            ->addOption(
54
                InputOptionKeys::CONFIGURATION,
55
                null,
56
                InputOption::VALUE_REQUIRED,
57
                'Specify the pathname to the configuration file to use',
58
                sprintf('%s/techdivision-import.json', getcwd())
59
            )
60
            ->addOption(
61
                InputOptionKeys::LOG_LEVEL,
62
                null,
63
                InputOption::VALUE_REQUIRED,
64
                'The log level to use'
65
            )
66
            ->addOption(
67
                InputOptionKeys::PID_FILENAME,
68
                null,
69
                InputOption::VALUE_REQUIRED,
70
                'The explicit PID filename to use',
71
                sprintf('%s/%s', sys_get_temp_dir(), Configuration::PID_FILENAME)
72
            );
73
    }
74
75
    /**
76
     * Finally executes the simple command.
77
     *
78
     * @param \TechDivision\Import\ConfigurationInterface       $configuration The configuration instance
79
     * @param \Symfony\Component\Console\Input\InputInterface   $input         An InputInterface instance
80
     * @param \Symfony\Component\Console\Output\OutputInterface $output        An OutputInterface instance
81
     *
82
     * @return void
83
     */
84
    protected function executeSimpleCommand(
85
        ConfigurationInterface $configuration,
86
        InputInterface $input,
87
        OutputInterface $output
88
    ) {
89
90
        // query whether or not a PID file exists and delete it
91
        if (file_exists($pidFilename = $configuration->getPidFilename())) {
92
            if (!unlink($pidFilename)) {
93
                throw new \Exception(sprintf('Can\'t delete PID file %s', $pidFilename));
94
            }
95
96
            // write a message to the console
97
            $output->writeln(sprintf('<info>Successfully deleted PID file %s</info>', $pidFilename));
98
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
99
        } else {
100
            // write a message to the console
101
            $output->writeln(sprintf('<error>PID file %s not available</error>', $pidFilename));
102
        }
103
    }
104
}
105