Conditions | 14 |
Paths | 1027 |
Total Lines | 68 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
107 | public function buildDirective($interchange, $hash) |
||
108 | { |
||
109 | $directive = new HTMLPurifier_ConfigSchema_Interchange_Directive(); |
||
110 | |||
111 | // These are required elements: |
||
112 | $directive->id = $this->id($hash->offsetGet('ID')); |
||
113 | $id = $directive->id->toString(); // convenience |
||
114 | |||
115 | if (isset($hash['TYPE'])) { |
||
116 | $type = explode('/', $hash->offsetGet('TYPE')); |
||
117 | if (isset($type[1])) { |
||
118 | $directive->typeAllowsNull = true; |
||
119 | } |
||
120 | $directive->type = $type[0]; |
||
121 | } else { |
||
122 | throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '$id' not defined"); |
||
123 | } |
||
124 | |||
125 | if (isset($hash['DEFAULT'])) { |
||
126 | try { |
||
127 | $directive->default = $this->varParser->parse( |
||
128 | $hash->offsetGet('DEFAULT'), |
||
129 | $directive->type, |
||
130 | $directive->typeAllowsNull |
||
131 | ); |
||
132 | } catch (HTMLPurifier_VarParserException $e) { |
||
133 | throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in DEFAULT in directive hash '$id'"); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | if (isset($hash['DESCRIPTION'])) { |
||
138 | $directive->description = $hash->offsetGet('DESCRIPTION'); |
||
139 | } |
||
140 | |||
141 | if (isset($hash['ALLOWED'])) { |
||
142 | $directive->allowed = $this->lookup($this->evalArray($hash->offsetGet('ALLOWED'))); |
||
143 | } |
||
144 | |||
145 | if (isset($hash['VALUE-ALIASES'])) { |
||
146 | $directive->valueAliases = $this->evalArray($hash->offsetGet('VALUE-ALIASES')); |
||
147 | } |
||
148 | |||
149 | if (isset($hash['ALIASES'])) { |
||
150 | $raw_aliases = trim($hash->offsetGet('ALIASES')); |
||
151 | $aliases = preg_split('/\s*,\s*/', $raw_aliases); |
||
152 | foreach ($aliases as $alias) { |
||
153 | $directive->aliases[] = $this->id($alias); |
||
154 | } |
||
155 | } |
||
156 | |||
157 | if (isset($hash['VERSION'])) { |
||
158 | $directive->version = $hash->offsetGet('VERSION'); |
||
159 | } |
||
160 | |||
161 | if (isset($hash['DEPRECATED-USE'])) { |
||
162 | $directive->deprecatedUse = $this->id($hash->offsetGet('DEPRECATED-USE')); |
||
163 | } |
||
164 | |||
165 | if (isset($hash['DEPRECATED-VERSION'])) { |
||
166 | $directive->deprecatedVersion = $hash->offsetGet('DEPRECATED-VERSION'); |
||
167 | } |
||
168 | |||
169 | if (isset($hash['EXTERNAL'])) { |
||
170 | $directive->external = preg_split('/\s*,\s*/', trim($hash->offsetGet('EXTERNAL'))); |
||
171 | } |
||
172 | |||
173 | $interchange->addDirective($directive); |
||
174 | } |
||
175 | |||
227 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.