Completed
Push — master ( dfad4d...8cf454 )
by Philip
21:24
created

ConfigCheckCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 2
1
<?php
2
3
4
namespace Dontdrinkandroot\Gitki\WebBundle\Command;
5
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Yaml\Yaml;
9
10
class ConfigCheckCommand extends AbstractConfigCommand
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $config;
16
17
    /**
18
     * @var array
19
     */
20
    protected $securityConfig;
21
22
    protected function configure()
23
    {
24
        $this
25
            ->setName('gitki:config:check')
26
            ->setDescription('Check if the configuration is valid and configure mandatory parameters');
27
    }
28
29
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31
        $rootDir = $this->getRootDir();
32
        $configPath = $rootDir . '/app/config/config.yml';
33
        $securityConfigPath = $rootDir . '/app/config/security.yml';
34
        $this->config = Yaml::parse($configPath);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Symfony\Component\Yaml\Yaml::parse($configPath) can also be of type string or object<stdClass>. However, the property $config is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
35
        $this->securityConfig = Yaml::parse($securityConfigPath);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Symfony\Component\Yaml\...se($securityConfigPath) can also be of type string or object<stdClass>. However, the property $securityConfig is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
36
37
//        $this->doConfigSteps($input, $output);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
39
// TODO: continue
40
        $output->writeln(Yaml::dump($this->config, 10));
41
        file_put_contents($configPath, Yaml::dump($this->config, 10));
42
        $output->writeln(Yaml::dump($this->securityConfig, 10));
43
        file_put_contents($securityConfigPath, Yaml::dump($this->securityConfig, 10));
44
    }
45
46
//    protected function doConfigSteps(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
//    {
48
//        $this->configureRepositoryPath($input, $output);
49
//    }
50
//
51
//    protected function configureRepositoryPath($input, $output)
52
//    {
53
//        $repositoryPath = null;
54
//        if (isset($this->gitkiConfig['repository_path'])) {
55
//            $repositoryPath = $this->gitkiConfig['repository_path'];
56
//        }
57
//
58
//        $questionString = 'Please specify the git repository path';
59
//        if (null !== $repositoryPath) {
60
//            $questionString .= ' (or hit enter to use "' . $repositoryPath . '")';
61
//        }
62
//        $questionString .= ': ';
63
//        $question = new Question($questionString, $repositoryPath);
64
//        $this->gitkiConfig['repository_path'] = $this->getQuestionHelper()->ask($input, $output, $question);
65
//    }
66
}
67