Completed
Push — master ( 1235b0...90fadd )
by Tim
15s
created

ImportClearPidFileCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
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\Utils\CommandNames;
24
use TechDivision\Import\ConfigurationInterface;
25
use Symfony\Component\Console\Input\InputInterface;
26
use Symfony\Component\Console\Output\OutputInterface;
27
28
/**
29
 * The remove PID command implementation.
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @copyright 2016 TechDivision GmbH <[email protected]>
33
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
 * @link      https://github.com/techdivision/import-cli-simple
35
 * @link      http://www.techdivision.com
36
 */
37
class ImportClearPidFileCommand extends AbstractSimpleImportCommand
38
{
39
40
    /**
41
     * Configures the current command.
42
     *
43
     * @return void
44
     * @see \Symfony\Component\Console\Command\Command::configure()
45
     */
46
    protected function configure()
47
    {
48
49
        // initialize the command with the required/optional options
50
        $this->setName(CommandNames::IMPORT_CLEAR_PID_FILE)
51
             ->setDescription('Clears the PID file from a previous import process, if it has not been cleaned up');
52
53
        // invoke the parent method
54
        parent::configure();
55
    }
56
57
    /**
58
     * Finally executes the simple command.
59
     *
60
     * @param \TechDivision\Import\ConfigurationInterface       $configuration The configuration instance
61
     * @param \Symfony\Component\Console\Input\InputInterface   $input         An InputInterface instance
62
     * @param \Symfony\Component\Console\Output\OutputInterface $output        An OutputInterface instance
63
     *
64
     * @return void
65
     */
66
    protected function executeSimpleCommand(
67
        ConfigurationInterface $configuration,
68
        InputInterface $input,
69
        OutputInterface $output
70
    ) {
71
72
        // query whether or not a PID file exists and delete it
73
        if (file_exists($pidFilename = $configuration->getPidFilename())) {
74
            if (!unlink($pidFilename)) {
75
                throw new \Exception(sprintf('Can\'t delete PID file %s', $pidFilename));
76
            }
77
78
            // write a message to the console
79
            $output->writeln(sprintf('<info>Successfully deleted PID file %s</info>', $pidFilename));
80
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
81
        } else {
82
            // write a message to the console
83
            $output->writeln(sprintf('<error>PID file %s not available</error>', $pidFilename));
84
        }
85
    }
86
}
87