Completed
Push — master ( 317dcf...a9b2d8 )
by Marius
02:57
created

SetUpServerCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 63.33%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 51
ccs 19
cts 30
cp 0.6333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 21 1
A execute() 0 17 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Paysera\PhpStormHelper\Command;
5
6
use Paysera\PhpStormHelper\Service\WorkspaceConfigurationHelper;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class SetUpServerCommand extends Command
13
{
14
    private $workspaceConfigurationHelper;
15
16 8
    public function __construct(WorkspaceConfigurationHelper $workspaceConfigurationHelper)
17
    {
18 8
        parent::__construct();
19
20 8
        $this->workspaceConfigurationHelper = $workspaceConfigurationHelper;
21 8
    }
22
23 8
    protected function configure()
24
    {
25
        $this
26 8
            ->setName('set-up-server')
27 8
            ->addArgument(
28 8
                'host-with-port',
29 8
                InputArgument::REQUIRED,
30 8
                'Host to listen for connections, for example my-project.docker:443'
31
            )
32 8
            ->addArgument(
33 8
                'remote-root',
34 8
                InputArgument::REQUIRED,
35 8
                'Path to root project directory inside server (or docker container), for example /project'
36
            )
37 8
            ->addArgument(
38 8
                'project-root-dir',
39 8
                InputArgument::OPTIONAL,
40 8
                'Project root directory in host machine. Default is current directory'
41
            )
42
        ;
43 8
    }
44
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        $target = $input->getArgument('project-root-dir');
48
        if ($target === null) {
49
            $target = realpath('.');
50
        }
51
52
        $target .= '/.idea/workspace.xml';
53
54
        $this->workspaceConfigurationHelper->addServer(
55
            $target,
56
            $input->getArgument('host-with-port'),
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('host-with-port') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, Paysera\PhpStormHelper\S...tionHelper::addServer() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
57
            $input->getArgument('remote-root')
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('remote-root') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, Paysera\PhpStormHelper\S...tionHelper::addServer() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
58
        );
59
60
        $output->writeln('Restart PhpStorm instance for changes to take effect');
61
    }
62
}
63