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

WriteCommand   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Test Coverage

Coverage 95%

Importance

Changes 7
Bugs 2 Features 3
Metric Value
wmc 12
c 7
b 2
f 3
lcom 0
cbo 9
dl 0
loc 67
ccs 38
cts 40
cp 0.95
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 16 1
F execute() 0 47 11
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 10
    protected function configure()
13
    {
14 10
        $this
15 10
            ->setName('write')
16 10
            ->setDescription('Generates PlantUML diagram from php source')
17 10
            ->addArgument(
18 10
                'files',
19
                InputArgument::IS_ARRAY
20 10
            )
21 10
            ->addOption('without-constants', null, null, 'Disables rendering of constants')
22 10
            ->addOption('without-methods', null, null, 'Disables rendering of methods')
23 10
            ->addOption('without-properties', null, null, 'Disables rendering of properties')
24 10
            ->addOption('without-doc-content', null, null, 'Disables parsing doc block for methods or properties')
25 10
            ->addOption('grouping', null, null, 'Enable deprecated and todo grouping for methods')
26
            ->addOption('without-function-params', null, null, 'Do not display function param, only count');
27 10
    }
28
29 10
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31 10
        $broker = new \TokenReflection\Broker(new \TokenReflection\Broker\Backend\Memory());
32 10
33
        foreach ($input->getArgument('files') as $fileToProcess) {
34
            if (is_dir($fileToProcess)) {
35
                $broker->processDirectory($fileToProcess);
36 10
            }
37
            else {
38 10
                $broker->processFile($fileToProcess);
39
            }
40 10
        }
41 10
42 10
        $writerOptions = new \Flagbit\Plantuml\TokenReflection\WriterOptions();
43 10
        if ($input->getOption('without-function-params')) {
44 10
            $writerOptions->withoutFunctionParameter = true;
0 ignored issues
show
Documentation introduced by
The property $withoutFunctionParameter is declared private in Flagbit\Plantuml\TokenReflection\WriterOptions. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

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