Completed
Push — master ( d582b4...acdf9f )
by Greg
02:27
created

CommandDocBlockParser2::addOptionOrArgumentTag()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
1
<?php
2
namespace Consolidation\AnnotatedCommand\Parser\Internal;
3
4
use phpDocumentor\Reflection\DocBlock;
5
use phpDocumentor\Reflection\DocBlock\Tag\ParamTag;
6
use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag;
7
use Consolidation\AnnotatedCommand\Parser\CommandInfo;
8
use Consolidation\AnnotatedCommand\Parser\DefaultsWithDescriptions;
9
10
/**
11
 * Given a class and method name, parse the annotations in the
12
 * DocBlock comment, and provide accessor methods for all of
13
 * the elements that are needed to create an annotated Command.
14
 */
15
class CommandDocBlockParser2 extends AbstractCommandDocBlockParser
16
{
17
    /**
18
     * Parse the docBlock comment for this command, and set the
19
     * fields of this class with the data thereby obtained.
20
     */
21
    public function parse()
22
    {
23
        $docblockComment = $this->reflection->getDocComment();
24
        $phpdoc = new DocBlock($docblockComment);
25
26
        // First set the description (synopsis) and help.
27
        $this->commandInfo->setDescription((string)$phpdoc->getShortDescription());
0 ignored issues
show
Bug introduced by
The method getShortDescription() does not seem to exist on object<phpDocumentor\Reflection\DocBlock>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
        $this->commandInfo->setHelp((string)$phpdoc->getLongDescription());
0 ignored issues
show
Bug introduced by
The method getLongDescription() does not seem to exist on object<phpDocumentor\Reflection\DocBlock>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
30
        $this->processAllTags($phpdoc);
31
    }
32
33
    protected function getTagContents($tag)
34
    {
35
        return $tag->getContent();
36
    }
37
38
    /**
39
     * Store the data from a @arg annotation in our argument descriptions.
40
     */
41
    protected function processArgumentTag($tag)
42
    {
43
        $this->addOptionOrArgumentTag($tag, $this->commandInfo->arguments());
44
    }
45
46
    /**
47
     * Store the data from a @param annotation in our argument descriptions.
48
     */
49
    protected function processParamTag($tag)
50
    {
51
        if (!$tag instanceof ParamTag) {
0 ignored issues
show
Bug introduced by
The class phpDocumentor\Reflection\DocBlock\Tag\ParamTag does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
52
            return;
53
        }
54
        return parent::processParamTag($tag);
55
    }
56
57
    /**
58
     * Store the data from a @return annotation in our argument descriptions.
59
     */
60
    protected function processReturnTag($tag)
61
    {
62
        if (!$tag instanceof ReturnTag) {
0 ignored issues
show
Bug introduced by
The class phpDocumentor\Reflection\DocBlock\Tag\ReturnTag does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
63
            return;
64
        }
65
        $this->commandInfo->setReturnType($tag->getType());
66
    }
67
}
68