| Conditions | 10 |
| Paths | 6 |
| Total Lines | 31 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 72 | function checkSensitiveWords(string $text, $mode = null) |
||
| 73 | { |
||
| 74 | if (!is_null($mode) && !in_array($mode, ['noun', 'verb', 'exclusive'])) { |
||
| 75 | throw new \InvalidArgumentException('mode参数无效,只能为null值、noun、exclusive'); |
||
| 76 | } |
||
| 77 | |||
| 78 | $tires = initTire(); |
||
| 79 | if (!is_null($mode)) { |
||
| 80 | return $tires[$mode]->seek($text); |
||
| 81 | } |
||
| 82 | |||
| 83 | $result = []; |
||
| 84 | $return = []; |
||
| 85 | foreach ($tires as $k => $tire) { |
||
| 86 | $result[$k] = $tire->seek($text); |
||
| 87 | } |
||
| 88 | if (!empty($result['noun']) && !empty($result['verb'])) { |
||
| 89 | $data = mapTypeToVerbOfSensitiveWords(); |
||
| 90 | foreach ($result['noun'] as $noun) { |
||
| 91 | $type = Cache::rememberForever('sensitive_words_noun_type', function () use ($noun) { |
||
| 92 | return SensitiveWord::query()->where('noun', $noun)->value('type'); |
||
| 93 | }); |
||
| 94 | $type = $type ? $type : 'others'; |
||
| 95 | $verbs = array_intersect($data[$type], $result['verb']); |
||
| 96 | if (!empty($verbs)) { |
||
| 97 | array_push($verbs, $noun); |
||
| 98 | $return[] = implode(' ', $verbs); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | return array_merge($return, $result['exclusive']); |
||
| 103 | } |
||
| 104 |