Conditions | 16 |
Paths | 14 |
Total Lines | 64 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 272 |
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 |
||
45 | public static function extract(AnnotatedInterface $model, $minBoost = 1.0) |
||
46 | { |
||
47 | $texts = []; |
||
48 | |||
49 | foreach(ManganelMeta::create($model)->fields() as $metaProperty) |
||
50 | { |
||
51 | /* @var $metaProperty DocumentPropertyMeta */ |
||
52 | $name = $metaProperty->name; |
||
53 | |||
54 | // Skip system fields |
||
55 | if(in_array($name, self::$banFields)) |
||
56 | { |
||
57 | continue; |
||
58 | } |
||
59 | |||
60 | if($metaProperty->searchBoost < $minBoost) |
||
61 | { |
||
62 | continue; |
||
63 | } |
||
64 | if(!$metaProperty->searchable) |
||
65 | { |
||
66 | continue; |
||
67 | } |
||
68 | |||
69 | $values = $model->$name; |
||
70 | if(!is_array($values) && !is_string($values)) |
||
71 | { |
||
72 | continue; |
||
73 | } |
||
74 | if(!is_array($values) && is_string($values)) |
||
75 | { |
||
76 | $values = [$values]; |
||
77 | } |
||
78 | foreach($values as $value) |
||
79 | { |
||
80 | if (is_string($value)) |
||
81 | { |
||
82 | // Skip class names |
||
83 | if(strpos($value, '\\') !== false && ClassChecker::exists($value)) |
||
84 | { |
||
85 | continue; |
||
86 | } |
||
87 | if(empty($value)) |
||
88 | { |
||
89 | continue; |
||
90 | } |
||
91 | |||
92 | // Ignore ID's |
||
93 | if(MongoId::isValid($value)) |
||
94 | { |
||
95 | continue; |
||
96 | } |
||
97 | $texts[] = $value; |
||
98 | } |
||
99 | } |
||
100 | } |
||
101 | |||
102 | foreach(new CompositionIterator($model) as $subModel) |
||
103 | { |
||
104 | $texts = array_merge($texts, self::extract($subModel, $minBoost)); |
||
105 | } |
||
106 | |||
107 | return $texts; |
||
108 | } |
||
109 | } |