| Conditions | 9 |
| Paths | 1 |
| Total Lines | 67 |
| Code Lines | 31 |
| 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 |
||
| 47 | private function initializeVisitors() |
||
| 48 | { |
||
| 49 | $this->visitors = array( |
||
| 50 | |||
| 51 | 'property.public' => function(array $config) { |
||
| 52 | return new PublicAttributes(); |
||
| 53 | }, |
||
| 54 | |||
| 55 | 'class.public' => function(array $config) { |
||
| 56 | $visitor = new PublicClass(); |
||
| 57 | |||
| 58 | if(isset($config['threshold']) && is_numeric($config['threshold'])) |
||
| 59 | { |
||
| 60 | $visitor->setThreshold($config['threshold']); |
||
| 61 | } |
||
| 62 | |||
| 63 | if(isset($config['minMethodCount']) && is_numeric($config['minMethodCount'])) |
||
| 64 | { |
||
| 65 | $visitor->setMinMethodCount($config['minMethodCount']); |
||
| 66 | } |
||
| 67 | |||
| 68 | return $visitor; |
||
| 69 | }, |
||
| 70 | |||
| 71 | 'getterSetter.fluid' => function(array $config) { |
||
| 72 | return new FluidSetters(); |
||
| 73 | }, |
||
| 74 | |||
| 75 | 'getterSetter.encapsulationViolation' => function(array $config) { |
||
| 76 | return new EncapsulationViolation(); |
||
| 77 | }, |
||
| 78 | |||
| 79 | 'dependency.magical' => function(array $config) { |
||
| 80 | return new MagicalInstantiation(); |
||
| 81 | }, |
||
| 82 | |||
| 83 | 'dependency.strongCoupling' => function(array $config) { |
||
| 84 | $visitor = new StrongCoupling(); |
||
| 85 | |||
| 86 | $visitor->addExcludePattern('~Iterator$~') |
||
| 87 | ->addExcludePattern('~^Null~') |
||
| 88 | ->addExcludePattern('~Exception$~'); |
||
| 89 | |||
| 90 | if(isset($config['excludePatterns'])) |
||
| 91 | { |
||
| 92 | foreach($config['excludePatterns'] as $pattern) |
||
| 93 | { |
||
| 94 | $visitor->addExcludePattern("~$pattern~"); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | if(isset($config['allowedClasses'])) |
||
| 99 | { |
||
| 100 | foreach($config['allowedClasses'] as $fullyQualifiedClassName) |
||
| 101 | { |
||
| 102 | $visitor->addAllowedClass($fullyQualifiedClassName); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return $visitor; |
||
| 107 | }, |
||
| 108 | |||
| 109 | 'dependency.interfaceSegregation' => function(array $config) { |
||
| 110 | return new InterfaceSegregation($this->objectTypesList); |
||
| 111 | }, |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | |||
| 136 | } |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.