| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 31 |
| 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 |
||
| 19 | public function up(Schema $schema): void |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * This query copies the existing tree structure from resource_node.parent_id |
||
| 23 | * into resource_link.parent_id, per context |
||
| 24 | * (course, session, usergroup, group, user, resource_type_group). |
||
| 25 | * |
||
| 26 | * For each resource_link (rl), we: |
||
| 27 | * - join its node (rn), |
||
| 28 | * - locate the parent node (rn.parent_id), |
||
| 29 | * - then find the corresponding resource_link (parent_rl) of that parent node |
||
| 30 | * in the same context, |
||
| 31 | * - and store parent_rl.id into rl.parent_id. |
||
| 32 | * |
||
| 33 | * Root nodes (rn.parent_id IS NULL) are left with parent_id = NULL. |
||
| 34 | * |
||
| 35 | * This keeps the same visible hierarchy as resource_node for all existing links, |
||
| 36 | * and will later allow the tree to diverge per context when moving shared documents. |
||
| 37 | */ |
||
| 38 | $sql = <<<SQL |
||
| 39 | UPDATE resource_link rl |
||
| 40 | INNER JOIN resource_node rn ON rn.id = rl.resource_node_id |
||
| 41 | LEFT JOIN resource_link parent_rl |
||
| 42 | ON parent_rl.resource_node_id = rn.parent_id |
||
| 43 | AND ( |
||
| 44 | (parent_rl.c_id = rl.c_id) |
||
| 45 | OR (parent_rl.c_id IS NULL AND rl.c_id IS NULL) |
||
| 46 | ) |
||
| 47 | AND ( |
||
| 48 | (parent_rl.session_id = rl.session_id) |
||
| 49 | OR (parent_rl.session_id IS NULL AND rl.session_id IS NULL) |
||
| 50 | ) |
||
| 51 | AND ( |
||
| 52 | (parent_rl.usergroup_id = rl.usergroup_id) |
||
| 53 | OR (parent_rl.usergroup_id IS NULL AND rl.usergroup_id IS NULL) |
||
| 54 | ) |
||
| 55 | AND ( |
||
| 56 | (parent_rl.group_id = rl.group_id) |
||
| 57 | OR (parent_rl.group_id IS NULL AND rl.group_id IS NULL) |
||
| 58 | ) |
||
| 59 | AND ( |
||
| 60 | (parent_rl.user_id = rl.user_id) |
||
| 61 | OR (parent_rl.user_id IS NULL AND rl.user_id IS NULL) |
||
| 62 | ) |
||
| 63 | AND parent_rl.resource_type_group = rl.resource_type_group |
||
| 64 | SET rl.parent_id = parent_rl.id |
||
| 65 | WHERE rn.parent_id IS NOT NULL |
||
| 66 | AND rl.parent_id IS NULL |
||
| 67 | SQL; |
||
| 68 | |||
| 69 | $this->addSql($sql); |
||
| 70 | } |
||
| 79 |