| Conditions | 10 |
| Paths | 6 |
| Total Lines | 44 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 36 | public function php($data) |
||
| 37 | { |
||
| 38 | if (!parent::php($data)) { |
||
| 39 | return false; |
||
| 40 | } |
||
| 41 | |||
| 42 | // When the record is unsaved and the classname is not set throw an error |
||
| 43 | if ((!$this->record || !$this->record->exists()) && (!isset($data['ClassName']) || empty($data['ClassName']))) { |
||
| 44 | $this->validationError( |
||
| 45 | 'ClassName', |
||
| 46 | _t( |
||
| 47 | __CLASS__ . 'CLASSNAME_ERROR', |
||
| 48 | 'You need to select a field type before you can create the field' |
||
| 49 | ) |
||
| 50 | ); |
||
| 51 | return false; |
||
| 52 | } |
||
| 53 | |||
| 54 | // Skip unsaved records |
||
| 55 | if (!$this->record || !$this->record->exists()) { |
||
| 56 | return true; |
||
| 57 | } |
||
| 58 | |||
| 59 | // Skip validation if not required |
||
| 60 | if (empty($data['Required'])) { |
||
| 61 | return; |
||
| 62 | } |
||
| 63 | |||
| 64 | // Skip validation if no rules |
||
| 65 | $count = EditableCustomRule::get()->filter('ParentID', $this->record->ID)->count(); |
||
| 66 | if ($count == 0) { |
||
| 67 | return true; |
||
| 68 | } |
||
| 69 | |||
| 70 | // Both required = true and rules > 0 should error |
||
| 71 | $this->validationError( |
||
| 72 | 'Required_Error', |
||
| 73 | _t( |
||
| 74 | __CLASS__.'.REQUIRED_ERROR', |
||
| 75 | 'Form fields cannot be required and have conditional display rules.' |
||
| 76 | ), |
||
| 77 | 'error' |
||
| 78 | ); |
||
| 79 | return false; |
||
| 80 | } |
||
| 82 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths