| Conditions | 10 |
| Paths | 8 |
| Total Lines | 49 |
| Code Lines | 23 |
| 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 |
||
| 15 | private function getEntityColumnCheck($property) |
||
|
|
|||
| 16 | { |
||
| 17 | // debug時のみ発動する |
||
| 18 | if (!Configure::read('debug')) { |
||
| 19 | return; |
||
| 20 | } |
||
| 21 | // 設定されていなくても例外的にOKとするメソッド |
||
| 22 | $exceptOkProperties = [ |
||
| 23 | 'entityColumnCheckAllowField', |
||
| 24 | '_method', |
||
| 25 | ]; |
||
| 26 | // フィールド許可用のメソッドは対象外とする |
||
| 27 | if (in_array($property, $exceptOkProperties, true)) { |
||
| 28 | return; |
||
| 29 | } |
||
| 30 | |||
| 31 | // 新規の場合はチェックしない |
||
| 32 | if ($this->isNew()) { |
||
| 33 | return; |
||
| 34 | } |
||
| 35 | |||
| 36 | // プロパティに値がいる場合はOK |
||
| 37 | if (array_key_exists($property, $this->_properties)) { |
||
| 38 | return; |
||
| 39 | } |
||
| 40 | |||
| 41 | // プロパティが設定されている場合はOK |
||
| 42 | if (property_exists($this, $property)) { |
||
| 43 | return; |
||
| 44 | } |
||
| 45 | |||
| 46 | // getterがセットされている場合はOK |
||
| 47 | $snakeMethod = '_get' . Inflector::underscore($property); |
||
| 48 | $camelMethod = '_get' . Inflector::camelize($property); |
||
| 49 | if ( |
||
| 50 | method_exists($this, $snakeMethod ) || |
||
| 51 | method_exists($this, $camelMethod ) |
||
| 52 | ) { |
||
| 53 | return; |
||
| 54 | } |
||
| 55 | |||
| 56 | // entityColumnCheckAllowFieldに値がセットされている場合はOKとする |
||
| 57 | if (is_array($this->entityColumnCheckAllowField) && in_array($property, $this->entityColumnCheckAllowField)) { |
||
| 58 | return; |
||
| 59 | } |
||
| 60 | |||
| 61 | // 上記条件に当てはまらない場合はException |
||
| 62 | throw new InternalErrorException('invalid entity(' . get_class($this) . ') paramater(' . $property . ')'); |
||
| 63 | } |
||
| 64 | } |
||
| 65 |