Conditions | 3 |
Paths | 3 |
Total Lines | 62 |
Lines | 9 |
Ratio | 14.52 % |
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 |
||
86 | protected function getDefinitionFromTokens($tokens, $getRecursive = false) |
||
87 | { |
||
88 | // First of all we need a new TraitDefinition to fill |
||
89 | View Code Duplication | if (is_null($this->currentDefinition)) { |
|
90 | $this->currentDefinition = new TraitDefinition(); |
||
91 | |||
|
|||
92 | } elseif (!$this->currentDefinition instanceof TraitDefinition) { |
||
93 | throw new GeneratorException(sprintf( |
||
94 | 'The structure definition %s does not seem to be a trait definition.', |
||
95 | $this->currentDefinition->getQualifiedName() |
||
96 | )); |
||
97 | } |
||
98 | |||
99 | // Save the path of the original definition for later use |
||
100 | $this->currentDefinition->setPath($this->file); |
||
101 | |||
102 | // File based namespaces do not make much sense, so hand it over here. |
||
103 | $this->currentDefinition->setNamespace($this->getNamespace()); |
||
104 | $this->currentDefinition->setName($this->getName($tokens)); |
||
105 | $this->currentDefinition->setUsedStructures($this->getUsedStructures()); |
||
106 | |||
107 | // For our next step we would like to get the doc comment (if any) |
||
108 | $this->currentDefinition->setDocBlock($this->getDocBlock($tokens, $this->getToken())); |
||
109 | |||
110 | // Get start and end line |
||
111 | $this->currentDefinition->setStartLine($this->getStartLine($tokens)); |
||
112 | $this->currentDefinition->setEndLine($this->getEndLine($tokens)); |
||
113 | |||
114 | // So we got our docBlock, now we can parse the invariant annotations from it |
||
115 | $annotationParser = new AnnotationParser($this->file, $this->config, $this->tokens, $this->currentDefinition); |
||
116 | $this->currentDefinition->setInvariantConditions( |
||
117 | $annotationParser->getConditions( |
||
118 | $this->currentDefinition->getDocBlock(), |
||
119 | Invariant::ANNOTATION |
||
120 | ) |
||
121 | ); |
||
122 | |||
123 | // Only thing still missing are the methods, so ramp up our FunctionParser |
||
124 | $functionParser = new FunctionParser( |
||
125 | $this->file, |
||
126 | $this->config, |
||
127 | $this->structureDefinitionHierarchy, |
||
128 | $this->structureMap, |
||
129 | $this->currentDefinition, |
||
130 | $this->tokens |
||
131 | ); |
||
132 | |||
133 | $this->currentDefinition->setFunctionDefinitions( |
||
134 | $functionParser->getDefinitionListFromTokens( |
||
135 | $tokens, |
||
136 | $getRecursive |
||
137 | ) |
||
138 | ); |
||
139 | |||
140 | // Lets get the attributes the class might have |
||
141 | $this->currentDefinition->setAttributeDefinitions($this->getAttributes($tokens)); |
||
142 | |||
143 | // Before exiting we will add the entry to the current structure definition hierarchy |
||
144 | $this->structureDefinitionHierarchy->insert($this->currentDefinition); |
||
145 | |||
146 | return $this->currentDefinition; |
||
147 | } |
||
148 | } |
||
149 |