Conditions | 9 |
Paths | 22 |
Total Lines | 61 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
24 | public function getSearchFields() |
||
25 | { |
||
26 | $fields = parent::getSearchFields(); |
||
27 | $class = $this->modelClass; |
||
28 | $use_autocomplete = $this->getConvertToAutocomplete(); |
||
29 | |||
30 | $db = Config::inst()->get($class, "db"); |
||
31 | $has_one = Config::inst()->get($class, "has_one"); |
||
32 | $has_many = Config::inst()->get($class, "has_many"); |
||
33 | $many_many = Config::inst()->get($class, "many_many"); |
||
34 | $belongs_many_many = Config::inst()->get($class, "belongs_many_many"); |
||
35 | $associations = array_merge( |
||
36 | $has_one, |
||
37 | $has_many, |
||
38 | $many_many, |
||
39 | $belongs_many_many |
||
40 | ); |
||
41 | |||
42 | // Update search fields to autocomplete |
||
43 | foreach ($fields as $field) { |
||
44 | $field_class = $this->modelClass; |
||
45 | $name = $field->getName(); |
||
46 | $title = $field->Title(); |
||
47 | $db_field = $name; |
||
48 | $in_db = false; |
||
49 | |||
50 | // Find any text fields an replace with autocomplete fields |
||
51 | if (ClassInfo::class_name($field) == TextField::class && $use_autocomplete) { |
||
52 | // If this is a relation, switch class name |
||
53 | if (strpos($name, "__")) { |
||
54 | $parts = explode("__", $db_field); |
||
55 | $field_class = isset($associations[$parts[0]]) ? $associations[$parts[0]] : null; |
||
56 | $db_field = $parts[1]; |
||
57 | $in_db = ($field_class) ? true : false; |
||
58 | } |
||
59 | |||
60 | // If this is in the DB (not casted) |
||
61 | if (in_array($db_field, array_keys($db))) { |
||
62 | $in_db = true; |
||
63 | } |
||
64 | |||
65 | if ($in_db) { |
||
66 | $fields->replaceField( |
||
67 | $name, |
||
68 | $field = AutoCompleteField::create( |
||
69 | $name, |
||
70 | $title, |
||
71 | $field->Value(), |
||
72 | $field_class, |
||
73 | $db_field |
||
74 | )->setDisplayField($db_field) |
||
75 | ->setLabelField($db_field) |
||
76 | ->setStoredField($db_field) |
||
77 | ); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | $field->setName($name); |
||
82 | } |
||
83 | |||
84 | return $fields; |
||
85 | } |
||
110 |
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