Completed
Push — develop ( efa997...824f66 )
by Jaap
10:28
created

StandardRouter::configure()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 51
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 33
nc 1
nop 0
dl 0
loc 51
rs 9.4109
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Transformer\Router;
13
14
use phpDocumentor\Descriptor\ClassDescriptor;
15
use phpDocumentor\Descriptor\ConstantDescriptor;
16
use phpDocumentor\Descriptor\FunctionDescriptor;
17
use phpDocumentor\Descriptor\InterfaceDescriptor;
18
use phpDocumentor\Descriptor\MethodDescriptor;
19
use phpDocumentor\Descriptor\NamespaceDescriptor;
20
use phpDocumentor\Descriptor\PackageDescriptor;
21
use phpDocumentor\Descriptor\ProjectDescriptorBuilder;
22
use phpDocumentor\Descriptor\PropertyDescriptor;
23
use phpDocumentor\Descriptor\TraitDescriptor;
24
use phpDocumentor\Descriptor\FileDescriptor;
25
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen;
26
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url;
27
28
/**
29
 * The default router for phpDocumentor.
30
 */
31
class StandardRouter extends RouterAbstract
0 ignored issues
show
Complexity introduced by
The class StandardRouter has a coupling between objects value of 24. Consider to reduce the number of dependencies under 13.
Loading history...
32
{
33
    /** @var ProjectDescriptorBuilder */
34
    private $projectDescriptorBuilder;
35
36
    /**
37
     * Initializes this router with a list of all elements.
38
     *
39
     * @param ProjectDescriptorBuilder $projectDescriptorBuilder
40
     */
41
    public function __construct(ProjectDescriptorBuilder $projectDescriptorBuilder)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $projectDescriptorBuilder exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
42
    {
43
        $this->projectDescriptorBuilder = $projectDescriptorBuilder;
44
45
        parent::__construct();
46
    }
47
48
    /**
49
     * Configuration function to add routing rules to a router.
50
     *
51
     * @return void
52
     */
53
    public function configure()
54
    {
55
        $projectDescriptorBuilder = $this->projectDescriptorBuilder;
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $projectDescriptorBuilder exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
56
57
        $fileGenerator      = new UrlGenerator\Standard\FileDescriptor();
58
        $namespaceGenerator = new UrlGenerator\Standard\NamespaceDescriptor();
59
        $packageGenerator   = new UrlGenerator\Standard\PackageDescriptor();
60
        $classGenerator     = new UrlGenerator\Standard\ClassDescriptor();
61
        $methodGenerator    = new UrlGenerator\Standard\MethodDescriptor();
62
        $constantGenerator  = new UrlGenerator\Standard\ConstantDescriptor();
63
        $functionGenerator  = new UrlGenerator\Standard\FunctionDescriptor();
64
        $propertyGenerator  = new UrlGenerator\Standard\PropertyDescriptor();
65
        $fqsenGenerator     = new UrlGenerator\Standard\FqsenDescriptor();
66
67
        // Here we cheat! If a string element is passed to this rule then we try to transform it into a Descriptor
68
        // if the node is translated we do not let it match and instead fall through to one of the other rules.
69
        $stringRule = function (&$node) use ($projectDescriptorBuilder) {
70
            $elements = $projectDescriptorBuilder->getProjectDescriptor()->getIndexes()->get('elements');
71
            if (is_string($node) && isset($elements[$node])) {
72
                $node = $elements[$node];
73
            };
74
75
            return false;
76
        };
77
78
        // @codingStandardsIgnoreStart
79
        $this[] = new Rule($stringRule, function () { return false; });
80
        $this[] = new Rule(function ($node) { return ($node instanceof FileDescriptor); }, $fileGenerator);
81
        $this[] = new Rule(function ($node) { return ($node instanceof PackageDescriptor); }, $packageGenerator);
82
        $this[] = new Rule(function ($node) { return ($node instanceof TraitDescriptor); }, $classGenerator);
83
        $this[] = new Rule(function ($node) { return ($node instanceof NamespaceDescriptor); }, $namespaceGenerator);
84
        $this[] = new Rule(function ($node) { return ($node instanceof InterfaceDescriptor); }, $classGenerator );
85
        $this[] = new Rule(function ($node) { return ($node instanceof ClassDescriptor); }, $classGenerator);
86
        $this[] = new Rule(function ($node) { return ($node instanceof ConstantDescriptor); }, $constantGenerator);
87
        $this[] = new Rule(function ($node) { return ($node instanceof MethodDescriptor); }, $methodGenerator);
88
        $this[] = new Rule(function ($node) { return ($node instanceof FunctionDescriptor); }, $functionGenerator);
89
        $this[] = new Rule(function ($node) { return ($node instanceof PropertyDescriptor); }, $propertyGenerator);
90
        $this[] = new Rule(function ($node) { return ($node instanceof Fqsen); }, $fqsenGenerator);
91
92
        // if this is a link to an external page; return that URL
93
        $this[] = new Rule(
94
            function ($node) {
95
                return $node instanceof Url;
96
            },
97
            function ($node) { return (string)$node; }
98
        );
99
100
        // do not generate a file for every unknown type
101
        $this[] = new Rule(function () { return true; }, function () { return false; });
102
        // @codingStandardsIgnoreEnd
103
    }
104
}
105