Completed
Pull Request — master (#11)
by
unknown
02:52
created

WriteCommand   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 11

Test Coverage

Coverage 96.36%

Importance

Changes 8
Bugs 2 Features 4
Metric Value
wmc 13
c 8
b 2
f 4
lcom 0
cbo 11
dl 0
loc 71
ccs 53
cts 55
cp 0.9636
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 17 1
F execute() 0 50 12
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 13
    protected function configure()
13
    {
14 13
        $this
15 13
            ->setName('write')
16 13
            ->setDescription('Generates PlantUML diagram from php source')
17 13
            ->addArgument(
18 13
                'files',
19
                InputArgument::IS_ARRAY
20 13
            )
21 13
            ->addOption('without-constants', null, null, 'Disables rendering of constants')
22 13
            ->addOption('without-methods', null, null, 'Disables rendering of methods')
23 13
            ->addOption('without-properties', null, null, 'Disables rendering of properties')
24 13
            ->addOption('without-doc-content', null, null, 'Disables parsing doc block for methods or properties')
25 13
            ->addOption('grouping', null, null, 'Enable deprecated and todo grouping for methods')
26 13
            ->addOption('without-function-params', null, null, 'Do not display function param, only count')
27 13
            ->addOption('max-length', null, null, 'Limit the output size of lines inside classes by truncating');
28 13
    }
29
30 13
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32 13
        $broker = new \TokenReflection\Broker(new \TokenReflection\Broker\Backend\Memory());
33
34 13
        foreach ($input->getArgument('files') as $fileToProcess) {
35 13
            if (is_dir($fileToProcess)) {
36
                $broker->processDirectory($fileToProcess);
37
            }
38
            else {
39 13
                $broker->processFile($fileToProcess);
40
            }
41 13
        }
42
43 13
        $writerOptions = new \Flagbit\Plantuml\TokenReflection\WriterOptions();
44 13
        if ($input->getOption('without-function-params')) {
45 1
            $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...
46 1
        }
47 13
        if($input->getOption('max-length')) {
48 1
            $writerOptions->maxLineLength = $input->getOption('max-length');
0 ignored issues
show
Documentation introduced by
The property $maxLineLength 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...
49 1
        }
50
51 13
        $classWriter = new \Flagbit\Plantuml\TokenReflection\ClassWriter();
52 13
        if (!$input->getOption('without-constants')) {
53 13
            $classWriter->setConstantWriter(new \Flagbit\Plantuml\TokenReflection\ConstantWriter($writerOptions));
54 13
        }
55 13
        if (!$input->getOption('without-properties')) {
56 13
            if ($input->getOption('grouping')) {
57 1
                $classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyGroupingWriter($writerOptions));
58 1
            } else {
59 12
                $classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyWriter($writerOptions));
60
            }
61 13
        }
62 13
        if (!$input->getOption('without-methods')) {
63 13
            if ($input->getOption('grouping')) {
64 1
                $classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodGroupingWriter($writerOptions));
65 1
            } else {
66 12
                $classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodWriter($writerOptions));
67
            }
68 13
        }
69 13
        if (!$input->getOption('without-doc-content')) {
70 13
            $classWriter->setDocContentWriter(new \Flagbit\Plantuml\TokenReflection\DocContentWriter());
71 13
        }
72
73 13
        $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...
74 13
        foreach ($broker->getClasses() as $class) {
75
            /** @var $class \TokenReflection\IReflectionClass */
76 13
            $output->write($classWriter->writeElement($class));
77 13
        }
78 13
        $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...
79 13
    }
80
}
81