Conditions | 10 |
Paths | 14 |
Total Lines | 33 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 110 |
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 |
||
104 | protected function autoWriteTimestamp(string $name) |
||
105 | { |
||
106 | $value = time(); |
||
107 | |||
108 | if (isset($this->type[$name])) { |
||
109 | $type = $this->type[$name]; |
||
110 | |||
111 | if (strpos($type, ':')) { |
||
112 | list($type, $param) = explode(':', $type, 2); |
||
113 | } |
||
114 | |||
115 | switch ($type) { |
||
116 | case 'datetime': |
||
1 ignored issue
–
show
|
|||
117 | case 'date': |
||
1 ignored issue
–
show
|
|||
118 | case 'timestamp': |
||
1 ignored issue
–
show
|
|||
119 | $value = $this->formatDateTime('Y-m-d H:i:s.u'); |
||
120 | break; |
||
121 | default: |
||
1 ignored issue
–
show
|
|||
122 | if (false !== strpos($type, '\\')) { |
||
1 ignored issue
–
show
|
|||
123 | // 对象数据写入 |
||
124 | $value = new $type(); |
||
125 | if (method_exists($value, '__toString')) { |
||
1 ignored issue
–
show
|
|||
126 | // 对象数据写入 |
||
127 | $value = $value->__toString(); |
||
128 | } |
||
1 ignored issue
–
show
|
|||
129 | } |
||
1 ignored issue
–
show
|
|||
130 | } |
||
131 | } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), |
||
132 | ['datetime', 'date', 'timestamp'])) { |
||
133 | $value = $this->formatDateTime('Y-m-d H:i:s.u'); |
||
134 | } |
||
135 | |||
136 | return $value; |
||
137 | } |
||
190 |