| Conditions | 15 |
| Paths | 59 |
| Total Lines | 36 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 240 |
| 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 |
||
| 98 | protected function autoWriteTimestamp(string $name) |
||
| 99 | { |
||
| 100 | $value = time(); |
||
| 101 | |||
| 102 | if (isset($this->type[$name])) { |
||
| 103 | $type = $this->type[$name]; |
||
| 104 | |||
| 105 | if (strpos($type, ':')) { |
||
| 106 | list($type, $param) = explode(':', $type, 2); |
||
| 107 | } |
||
| 108 | |||
| 109 | switch ($type) { |
||
| 110 | case 'datetime': |
||
|
1 ignored issue
–
show
|
|||
| 111 | case 'date': |
||
|
1 ignored issue
–
show
|
|||
| 112 | case 'timestamp': |
||
|
1 ignored issue
–
show
|
|||
| 113 | $format = !empty($param) ? $param : $this->dateFormat; |
||
| 114 | $format .= strpos($format, 'u') || false !== strpos($format, '\\') ? '' : '.u'; |
||
| 115 | $value = $this->formatDateTime($format); |
||
| 116 | break; |
||
| 117 | default: |
||
|
1 ignored issue
–
show
|
|||
| 118 | if (false !== strpos($type, '\\')) { |
||
|
1 ignored issue
–
show
|
|||
| 119 | // 对象数据写入 |
||
| 120 | $value = new $type(); |
||
| 121 | if (method_exists($value, '__toString')) { |
||
|
1 ignored issue
–
show
|
|||
| 122 | // 对象数据写入 |
||
| 123 | $value = $value->__toString(); |
||
| 124 | } |
||
|
1 ignored issue
–
show
|
|||
| 125 | } |
||
|
1 ignored issue
–
show
|
|||
| 126 | } |
||
| 127 | } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), |
||
| 128 | ['datetime', 'date', 'timestamp'])) { |
||
| 129 | $format = strpos($this->dateFormat, 'u') || false !== strpos($this->dateFormat, '\\') ? '' : '.u'; |
||
| 130 | $value = $this->formatDateTime($this->dateFormat . $format); |
||
| 131 | } |
||
| 132 | |||
| 133 | return $value; |
||
| 134 | } |
||
| 187 |