Completed
Push — master ( fe686a...ccb6c2 )
by dima
03:59
created

TestCommand::getNativeDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Symfony\Component\Console\Command;
13
14
use Symfony\Component\Console\Helper\DescriptorHelper;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\Console\Input\InputDefinition;
20
21
/**
22
 * ListCommand displays the list of all available commands for the application.
23
 *
24
 * @author Fabien Potencier <[email protected]>
25
 */
26
class TestCommand extends Command
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function configure()
32
    {
33
        $this
34
            ->setName('test')
35
            ->setDefinition($this->createDefinition())
36
            ->setDescription('Test commands')
37
            ->setHelp(<<<'EOF'
38
This is test commands
39
EOF
40
            )
41
        ;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getNativeDefinition()
48
    {
49
        return $this->createDefinition();
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $helper = new DescriptorHelper();
58
        $helper->describe($output, $this->getApplication(), array(
0 ignored issues
show
Bug introduced by
It seems like $this->getApplication() can be null; however, describe() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
59
            'valuename' => $input->getOption('valuename'),
60
        ));
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    private function createDefinition()
67
    {
68
        return new InputDefinition(array(
69
            new InputArgument('valuename', InputArgument::OPTIONAL, 'The value name'),
70
//            new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
71
//            new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
72
        ));
73
    }
74
}
75