Passed
Push — master ( b2175e...d070b7 )
by Julius
02:17
created

Builder::endPhpDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace JuliusHaertl\PHPDocToRst\Builder;
25
26
use JuliusHaertl\PHPDocToRst\Extension\Extension;
27
use phpDocumentor\Reflection\DocBlock;
28
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
29
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
30
use phpDocumentor\Reflection\DocBlock\Tags\See;
31
use phpDocumentor\Reflection\DocBlock\Tags\Since;
32
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
33
use phpDocumentor\Reflection\Element;
34
use phpDocumentor\Reflection\File;
35
use phpDocumentor\Reflection\Fqsen;
36
37
38
abstract class Builder extends RstBuilder {
39
40
    /** @var File */
41
    protected $file;
42
43
    /** @var Element */
44
    protected $element;
45
46
    /** @var Extension[] */
47
    protected $extensions = [];
48
49
    private $phpDomains = [];
0 ignored issues
show
Unused Code introduced by
The property $phpDomains is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
50
51
    protected abstract function render();
52
53
    public function __construct($file, $element, $extensions) {
54
        $this->file = $file;
55
        $this->extensions = $extensions;
56
        $this->element = $element;
57
        $this->render();
58
    }
59
60
    /**
61
     * @return Element that is used to build the rst file
62
     */
63
    public function getElement() {
64
        return $this->element;
65
    }
66
67
    public function getLink($type, $fqsen) {
68
        return ':php:' . $type . ':`' . RstBuilder::escape(substr($fqsen, 1)) . '`';
69
    }
70
71
    public function beginPhpDomain($type, $name, $indent=true) {
72
        // FIXME: Add checks if it is properly ended
73
        $this->addLine('.. php:' . $type . ':: '. $name)->addLine();
74
        if ($indent === true) {
75
            $this->indent();
76
        }
77
    }
78
79
    public function endPhpDomain($type='') {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

79
    public function endPhpDomain(/** @scrutinizer ignore-unused */ $type='') {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
        $this->unindent();
81
        $this->addLine();
82
    }
83
84
    /**
85
     * @param string $tag Name of the tag to parse
86
     * @param DocBlock $docBlock
87
     */
88
    protected function addDocblockTag($tag, DocBlock $docBlock) {
89
        $indent = 0;
90
        $tags = $docBlock->getTagsByName($tag);
91
        switch ($tag) {
92 View Code Duplication
            case 'return':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
                if (sizeof($tags) === 0) continue;
94
                /** @var Return_ $return */
95
                $return = $tags[0];
96
                $this->addIndentMultiline($indent, ':returns: ' . $return->getType() . ' ' . RstBuilder::escape($return->getDescription()), true);
97
                break;
98 View Code Duplication
            case 'throws':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
                if (sizeof($tags) === 0) continue;
100
                /** @var Throws $return */
101
                $return = $tags[0];
102
                $this->addIndentMultiline($indent, ':throws: ' . $return->getType() . ' ' . RstBuilder::escape($return->getDescription()), true);
103
                break;
104 View Code Duplication
            case 'since':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
                if (sizeof($tags) === 0) continue;
106
                /** @var Since $return */
107
                $return = $tags[0];
108
                $this->addIndentMultiline($indent, ':since: ' . $return->getVersion() . ' ' . RstBuilder::escape($return->getDescription()), true);
109
                break;
110 View Code Duplication
            case 'deprecated':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
                if (sizeof($tags) === 0) continue;
112
                /** @var Deprecated $return */
113
                $return = $tags[0];
114
                $this->addIndentMultiline($indent, ':deprecated: ' . $return->getVersion() . ' ' . RstBuilder::escape($return->getDescription()), true);
115
                break;
116 View Code Duplication
            case 'see':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
                if (sizeof($tags) === 0) continue;
118
                /** @var See $return */
119
                $return = $tags[0];
120
                $this->addIndentMultiline($indent, ':see: ' . $return->getReference() . ' ' . RstBuilder::escape($return->getDescription()), true);
121
                break;
122
            case 'license':
123
                if (sizeof($tags) === 0) continue;
124
                /** @var DocBlock\Tags\BaseTag $return */
125
                $return = $tags[0];
126
                $this->addIndentMultiline($indent, ':license: ' . RstBuilder::escape($return->getDescription()), true);
127
                break;
128
            case 'param':
129
                // param handling is done by subclasses since it is more that docbook parsing
130
                break;
131
            default:
132
                echo 'Tag handling not defined for: ' . $tag . PHP_EOL;
133
                break;
134
        }
135
136
    }
137
138
139
}