| Conditions | 13 |
| Paths | 12 |
| Total Lines | 38 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 92 | public function getPlaceholder() |
||
| 93 | { |
||
| 94 | //Check if a class name was specified |
||
| 95 | if (class_exists($this->type)) { |
||
| 96 | $object = new $this->type(); |
||
| 97 | if ($object instanceof NamedDBElement) { |
||
| 98 | if (is_string($this->placeholder) && $this->placeholder !== "") { |
||
| 99 | $object->setName($this->placeholder); |
||
| 100 | } |
||
| 101 | $object->setName('???'); |
||
| 102 | } |
||
| 103 | return $object; |
||
| 104 | } |
||
| 105 | |||
| 106 | |||
| 107 | if (null === $this->placeholder) { |
||
| 108 | switch ($this->type) { |
||
| 109 | case 'integer': |
||
| 110 | return 0; |
||
| 111 | case 'float': |
||
| 112 | return 0.0; |
||
| 113 | case 'string': |
||
| 114 | return '???'; |
||
| 115 | case 'object': |
||
| 116 | return null; |
||
| 117 | case 'collection': |
||
| 118 | return new ArrayCollection(); |
||
| 119 | case 'boolean': |
||
| 120 | return false; |
||
| 121 | case 'datetime': |
||
| 122 | $date = new \DateTime(); |
||
| 123 | return $date->setTimestamp(0); |
||
| 124 | default: |
||
| 125 | throw new InvalidArgumentException('Unknown type! You have to specify a placeholder!'); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | return $this->placeholder; |
||
| 130 | } |
||
| 132 |