Conditions | 17 |
Paths | 30 |
Total Lines | 56 |
Code Lines | 36 |
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 |
||
23 | public function safeUp() |
||
24 | { |
||
25 | // Don't make the same config changes twice |
||
26 | $schemaVersion = Craft::$app->projectConfig |
||
27 | ->get('plugins.cache-flag.schemaVersion', true); |
||
28 | |||
29 | if (\version_compare($schemaVersion, '1.0.1', '>=')) { |
||
30 | return; |
||
31 | } |
||
32 | |||
33 | $rows = (new Query()) |
||
34 | ->select(['flags', 'sectionId', 'categoryGroupId', 'tagGroupId', 'userGroupId', 'volumeId', 'globalSetId', 'elementType', 'uid']) |
||
35 | ->from('{{%cacheflag_flags}}') |
||
36 | ->all(); |
||
37 | |||
38 | foreach ($rows as $row) { |
||
39 | |||
40 | $source = null; |
||
41 | |||
42 | if ($row['sectionId']) { |
||
43 | if ($uid = Db::uidById(Table::SECTIONS, $row['sectionId'])) { |
||
44 | $source = "section:$uid"; |
||
45 | } |
||
46 | } else if ($row['categoryGroupId']) { |
||
47 | if ($uid = Db::uidById(Table::CATEGORYGROUPS, $row['categoryGroupId'])) { |
||
48 | $source = "categoryGroup:$uid"; |
||
49 | } |
||
50 | } else if ($row['tagGroupId']) { |
||
51 | if ($uid = Db::uidById(Table::TAGGROUPS, $row['tagGroupId'])) { |
||
52 | $source = "tagGroup:$uid"; |
||
53 | } |
||
54 | } else if ($row['userGroupId']) { |
||
55 | if ($uid = Db::uidById(Table::USERGROUPS, $row['userGroupId'])) { |
||
56 | $source = "userGroup:$uid"; |
||
57 | } |
||
58 | } else if ($row['volumeId']) { |
||
59 | if ($uid = Db::uidById(Table::VOLUMES, $row['volumeId'])) { |
||
60 | $source = "volume:$uid"; |
||
61 | } |
||
62 | } else if ($row['globalSetId']) { |
||
63 | if ($uid = Db::uidById(Table::GLOBALSETS, $row['globalSetId'])) { |
||
64 | $source = "globalSet:$uid"; |
||
65 | } |
||
66 | } else if ($row['elementType']) { |
||
67 | $source = 'elementType:' . $row['elementType']; |
||
68 | } |
||
69 | |||
70 | if (!$source) { |
||
71 | continue; |
||
72 | } |
||
73 | |||
74 | $path = "cacheFlags.{$row['uid']}"; |
||
75 | |||
76 | Craft::$app->projectConfig->set($path, [ |
||
77 | 'source' => $source, |
||
78 | 'flags' => $row['flags'], |
||
79 | ]); |
||
94 |