Conditions | 3 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
53 | public function configure() |
||
54 | { |
||
55 | $projectDescriptorBuilder = $this->projectDescriptorBuilder; |
||
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 |