Completed
Pull Request — master (#30)
by Anton
17:34
created

StopCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 31.11 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 36.84%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 2
cbo 3
dl 14
loc 45
ccs 7
cts 19
cp 0.3684
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 14 14 1
A execute() 0 19 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/bluzman
5
 */
6
7
namespace Bluzman\Command\Server;
8
9
use Bluzman\Input\InputOption;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Process\Process;
13
14
/**
15
 * StopCommand
16
 *
17
 * @package  Bluzman\Command\Server
18
 *
19
 * @author   Pavel Machekhin
20
 * @created  2013-06-17 14:47
21
 */
22
class StopCommand extends AbstractServerCommand
23
{
24
    /**
25
     * Command configuration
26
     */
27 14 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...
28
    {
29
        $this
30
            // the name of the command (the part after "bin/bluzman")
31 14
            ->setName('server:stop')
32
            // the short description shown while running "php bin/bluzman list"
33 14
            ->setDescription('Stop a built-in PHP server')
34
            // the full command description shown when running the command with
35
            // the "--help" option
36 14
            ->setHelp('This command allows you to stop built-in PHP server')
37
        ;
38 14
        $this->addOption('host', null, InputOption::VALUE_OPTIONAL, 'IP address of the server', '0.0.0.0');
39 14
        $this->addOption('port', null, InputOption::VALUE_OPTIONAL, 'Port of the server', '8000');
40 14
    }
41
42
    /**
43
     * @param InputInterface $input
44
     * @param OutputInterface $output
45
     * @return int|null|void
46
     */
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        $this->info('Running "server:stop" command');
50
51
        $host = $input->getOption('host');
52
        $port = $input->getOption('port');
53
54
        $pid = $this->getProcessId($host, $port) ?: false;
55
56
        if (empty($pid)) {
57
            $this->comment('Server is not running');
58
            return;
59
        }
60
61
        $process = new Process("kill -9 $pid");
62
        $process->run();
63
64
        $this->write("Server <info>$host:$port</info> stopped");
65
    }
66
}
67