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

WriteCommand   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Test Coverage

Coverage 95.83%

Importance

Changes 6
Bugs 1 Features 3
Metric Value
wmc 11
c 6
b 1
f 3
lcom 0
cbo 9
dl 0
loc 64
ccs 46
cts 48
cp 0.9583
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 16 1
D execute() 0 44 10
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
            ->addOption('without-function-params', null, null, 'Do not display function param, only count');
27 11
    }
28
29 11
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31 11
        $broker = new \TokenReflection\Broker(new \TokenReflection\Broker\Backend\Memory());
32
33 11
        foreach ($input->getArgument('files') as $fileToProcess) {
34 11
            if (is_dir($fileToProcess)) {
35
                $broker->processDirectory($fileToProcess);
36
            }
37
            else {
38 11
                $broker->processFile($fileToProcess);
39
            }
40 11
        }
41
42 11
        $writerOptions = new \Flagbit\Plantuml\TokenReflection\WriterOptions();
0 ignored issues
show
Unused Code introduced by
$writerOptions is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
44 11
        $classWriter = new \Flagbit\Plantuml\TokenReflection\ClassWriter();
45 11
        if (!$input->getOption('without-constants')) {
46 11
            $classWriter->setConstantWriter(new \Flagbit\Plantuml\TokenReflection\ConstantWriter());
47 11
        }
48 11
        if (!$input->getOption('without-properties')) {
49 11
            if ($input->getOption('grouping')) {
50 1
                $classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyGroupingWriter());
51 1
            } else {
52 10
                $classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyWriter());
53
            }
54 11
        }
55 11
        if (!$input->getOption('without-methods')) {
56 11
            if ($input->getOption('grouping')) {
57 1
                $classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodGroupingWriter());
58 1
            } else {
59 10
                $classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodWriter());
60
            }
61 11
        }
62 11
        if (!$input->getOption('without-doc-content')) {
63 11
            $classWriter->setDocContentWriter(new \Flagbit\Plantuml\TokenReflection\DocContentWriter());
64 11
        }
65
66 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...
67 11
        foreach ($broker->getClasses() as $class) {
68
            /** @var $class \TokenReflection\IReflectionClass */
69 11
            $output->write($classWriter->writeElement($class));
70 11
        }
71 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...
72 11
    }
73
}
74