Conditions | 8 |
Paths | 40 |
Total Lines | 58 |
Code Lines | 34 |
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 declare(strict_types=1); |
||
49 | public function sourceRecords($params): SS_List |
||
50 | { |
||
51 | $methods = $this->getMethodClassToTitleMapping(); |
||
52 | |||
53 | // Any GridFieldAction will submit all form inputs, regardless of whether or not they have valid values. |
||
54 | // This results in zero results when no filters have been set, as the query then filters for empty string |
||
55 | // on all parameters. `stlen` is a safe function, as all user input comes through to PHP as strings. |
||
56 | $params = array_filter($params, 'strlen'); |
||
57 | |||
58 | // Having a WHERE limits the results, which means the the COUNT will be off (GROUP BY applied after WHERE) |
||
59 | // So clip the count filter and apply it after the database query, only if Methods filter is also set |
||
60 | // this way we can delegate to the database where possible, which should be faster. |
||
61 | if (isset($params['Count'])) { |
||
62 | $desiredCount = (int)$params['Count']; |
||
63 | if (isset($params['Methods'])) { |
||
64 | $countFilter = $desiredCount; |
||
65 | unset($params['Count']); |
||
66 | } elseif ($desiredCount) { |
||
67 | // When querying SQL COUNT() - this will always factor in the backup method, which is excluded in the |
||
68 | // secondary query below to get the list of method names the user has registered. So to compensate we |
||
69 | // need to bump up the entered number by 1. |
||
70 | $params['Count'] = $desiredCount + 1; |
||
71 | } |
||
72 | } |
||
73 | |||
74 | $filteredList = ArrayList::create([]); |
||
75 | $backupClass = $this->getBackupMethodClass(); |
||
76 | /** @var Member[]&MemberExtension[] $members */ |
||
77 | $members = $this->applyParams(Member::get(), $params)->toArray(); |
||
78 | foreach ($members as $member) { |
||
79 | $defaultMethod = $member->getDefaultRegisteredMethod(); |
||
80 | $defaultMethodClassName = $defaultMethod ? $defaultMethod->MethodClassName : ''; |
||
81 | |||
82 | $registeredMethods = $member |
||
83 | ->RegisteredMFAMethods() |
||
84 | ->exclude('MethodClassName', $backupClass) |
||
85 | ->column('MethodClassName'); |
||
86 | $registeredMethodNames = array_map(function (string $methodClass) use ($methods): string { |
||
87 | return $methods[$methodClass]; |
||
88 | }, $registeredMethods); |
||
89 | |||
90 | $memberReportData = ArrayData::create(); |
||
91 | foreach ($member->summaryFields() as $field => $name) { |
||
92 | $memberReportData->$field = $member->$field; |
||
93 | } |
||
94 | |||
95 | $memberReportData->methodCount = (string)count($registeredMethods); |
||
96 | $memberReportData->registeredMethods = implode(', ', $registeredMethodNames); |
||
97 | $memberReportData->defaultMethodName = $methods[$defaultMethodClassName] ?? ''; |
||
98 | $memberReportData->skippedRegistration = $member->dbObject('HasSkippedMFARegistration')->Nice(); |
||
99 | |||
100 | $filteredList->push($memberReportData); |
||
101 | }; |
||
102 | if (isset($countFilter)) { |
||
103 | $filteredList = $filteredList->filter('methodCount', $countFilter); |
||
104 | } |
||
105 | $this->extend('updateSourceRecords', $filteredList); |
||
106 | return $filteredList; |
||
107 | } |
||
223 |
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