Completed
Pull Request — master (#10)
by
unknown
04:10
created

WriteCommand::execute()   D

Complexity

Conditions 10
Paths 216

Size

Total Lines 42
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 10.0222

Importance

Changes 5
Bugs 0 Features 3
Metric Value
c 5
b 0
f 3
dl 0
loc 42
ccs 31
cts 33
cp 0.9394
rs 4.2416
cc 10
eloc 26
nc 216
nop 2
crap 10.0222

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Flagbit\Plantuml\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class WriteCommand extends Command
11
{
12 11
    protected function configure()
13
    {
14 11
        $this
15 11
            ->setName('write')
16 11
            ->setDescription('Generates PlantUML diagram from php source')
17 11
            ->addArgument(
18 11
                'files',
19
                InputArgument::IS_ARRAY
20 11
            )
21 11
            ->addOption('without-constants', null, null, 'Disables rendering of constants')
22 11
            ->addOption('without-methods', null, null, 'Disables rendering of methods')
23 11
            ->addOption('without-properties', null, null, 'Disables rendering of properties')
24 11
            ->addOption('without-doc-content', null, null, 'Disables parsing doc block for methods or properties')
25 11
            ->addOption('grouping', null, null, 'Enable deprecated and todo grouping for methods');
26 11
    }
27
28 11
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30 11
        $broker = new \TokenReflection\Broker(new \TokenReflection\Broker\Backend\Memory());
31
32 11
        foreach ($input->getArgument('files') as $fileToProcess) {
33 11
            if (is_dir($fileToProcess)) {
34
                $broker->processDirectory($fileToProcess);
35
            }
36
            else {
37 11
                $broker->processFile($fileToProcess);
38
            }
39 11
        }
40
41 11
        $classWriter = new \Flagbit\Plantuml\TokenReflection\ClassWriter();
42 11
        if (!$input->getOption('without-constants')) {
43 11
            $classWriter->setConstantWriter(new \Flagbit\Plantuml\TokenReflection\ConstantWriter());
44 11
        }
45 11
        if (!$input->getOption('without-properties')) {
46 11
            if ($input->getOption('grouping')) {
47 1
                $classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyGroupingWriter());
48 1
            } else {
49 10
                $classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyWriter());
50
            }
51 11
        }
52 11
        if (!$input->getOption('without-methods')) {
53 11
            if ($input->getOption('grouping')) {
54 1
                $classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodGroupingWriter());
55 1
            } else {
56 10
                $classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodWriter());
57
            }
58 11
        }
59 11
        if (!$input->getOption('without-doc-content')) {
60 11
            $classWriter->setDocContentWriter(new \Flagbit\Plantuml\TokenReflection\DocContentWriter());
61 11
        }
62
63 11
        $output->write('@startuml', "\n");
0 ignored issues
show
Documentation introduced by
' ' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64 11
        foreach ($broker->getClasses() as $class) {
65
            /** @var $class \TokenReflection\IReflectionClass */
66 11
            $output->write($classWriter->writeElement($class));
67 11
        }
68 11
        $output->write('@enduml', "\n");
0 ignored issues
show
Documentation introduced by
' ' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69 11
    }
70
}
71