Conditions | 10 |
Paths | 80 |
Total Lines | 28 |
Code Lines | 18 |
Lines | 17 |
Ratio | 60.71 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
43 | public function __construct($name, array $subNodes = array(), array $attributes = array()) { |
||
44 | parent::__construct($attributes); |
||
45 | $this->type = isset($subNodes['type']) ? $subNodes['type'] : 0; |
||
46 | $this->name = $name; |
||
47 | $this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : null; |
||
48 | $this->implements = isset($subNodes['implements']) ? $subNodes['implements'] : array(); |
||
49 | $this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array(); |
||
50 | |||
51 | View Code Duplication | if (null !== $this->name && isset(self::$specialNames[strtolower($this->name)])) { |
|
|
|||
52 | throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name)); |
||
53 | } |
||
54 | |||
55 | View Code Duplication | if (isset(self::$specialNames[strtolower($this->extends)])) { |
|
56 | throw new Error( |
||
57 | sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends), |
||
58 | $this->extends->getAttributes() |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | View Code Duplication | foreach ($this->implements as $interface) { |
|
63 | if (isset(self::$specialNames[strtolower($interface)])) { |
||
64 | throw new Error( |
||
65 | sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface), |
||
66 | $interface->getAttributes() |
||
67 | ); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
113 |
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.