| Conditions | 13 |
| Paths | 240 |
| Total Lines | 40 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 25 | public function toSyntax() |
||
| 26 | { |
||
| 27 | $title = ''; |
||
| 28 | if (!empty($this->attrs['title'])) { |
||
| 29 | $title = '|' . $this->attrs['title']; |
||
| 30 | } |
||
| 31 | |||
| 32 | $leftAlign = ''; |
||
| 33 | $rightAlign = ''; |
||
| 34 | if (!empty($this->attrs['align'])) { |
||
| 35 | if ($this->attrs['align'] === 'left') { |
||
| 36 | $rightAlign = ' '; |
||
| 37 | } elseif ($this->attrs['align'] === 'right') { |
||
| 38 | $leftAlign = ' '; |
||
| 39 | } elseif ($this->attrs['align'] === 'center') { |
||
| 40 | $leftAlign = ' '; |
||
| 41 | $rightAlign = ' '; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | $query = []; |
||
| 46 | if (!empty($this->attrs['height'])) { |
||
| 47 | $query[] = $this->attrs['width'] . 'x' . $this->attrs['height']; |
||
| 48 | } elseif (!empty($this->attrs['width'])) { |
||
| 49 | $query[] = $this->attrs['width']; |
||
| 50 | } |
||
| 51 | if (!empty($this->attrs['linking']) && $this->attrs['linking'] !== 'details') { |
||
| 52 | $query[] = $this->attrs['linking']; |
||
| 53 | } |
||
| 54 | if (!empty($this->attrs['cache']) && $this->attrs['cache'] !== 'cache') { |
||
| 55 | $query[] = $this->attrs['cache']; |
||
| 56 | } |
||
| 57 | |||
| 58 | $queryString = ''; |
||
| 59 | if (!empty($query)) { |
||
| 60 | $queryString = '?' . implode('&', $query); |
||
| 61 | } |
||
| 62 | |||
| 63 | |||
| 64 | return '{{' . $leftAlign . $this->attrs['id'] . $queryString . $rightAlign . $title . '}}'; |
||
| 65 | } |
||
| 186 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: