Conditions | 11 |
Paths | 72 |
Total Lines | 55 |
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 |
||
24 | public function up(Schema $schema): void |
||
25 | { |
||
26 | $this->addSql("ALTER TABLE session_rel_user ADD access_start_date DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)'"); |
||
27 | $this->addSql("ALTER TABLE session_rel_user ADD access_end_date DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)'"); |
||
28 | |||
29 | $sessions = $this->getSessionWithNoDuration(); |
||
30 | |||
31 | foreach ($sessions as $session) { |
||
32 | $sRUs = $this->getSessionRelUsers($session['id']); |
||
33 | |||
34 | foreach ($sRUs as $sru) { |
||
35 | $isCoach = $this->isCoach($session['id'], $sru['user_id']); |
||
36 | |||
37 | $startDate = $isCoach && $session['coach_access_start_date'] |
||
38 | ? $session['coach_access_start_date'] |
||
39 | : $session['access_start_date']; |
||
40 | |||
41 | $endDate = $isCoach && $session['coach_access_end_date'] |
||
42 | ? $session['coach_access_end_date'] |
||
43 | : $session['access_end_date']; |
||
44 | |||
45 | $this->addSql( |
||
46 | 'UPDATE session_rel_user SET access_start_date = :startDate, access_end_date = :endDate WHERE id = :id', |
||
47 | [ |
||
48 | 'startDate' => $startDate, |
||
49 | 'endDate' => $endDate, |
||
50 | 'id' => $sru['id'], |
||
51 | ] |
||
52 | ); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | $sessions = $this->getSessionWithDuration(); |
||
57 | |||
58 | foreach ($sessions as $session) { |
||
59 | $sRUs = $this->getSessionRelUsers($session['id']); |
||
60 | |||
61 | foreach ($sRUs as $sru) { |
||
62 | $duration = (int) $session['duration'] + (int) $sru['duration']; |
||
63 | |||
64 | $firstAccessToSession = $this->getFirstAccessToSession($session['id'], $sru['user_id']); |
||
65 | |||
66 | $calculatedLastAccessToSession = $firstAccessToSession + $duration * 24 * 60 * 60; |
||
67 | |||
68 | $startDate = $firstAccessToSession ?: null; |
||
69 | $endDate = $firstAccessToSession ? $calculatedLastAccessToSession : null; |
||
70 | |||
71 | $this->addSql( |
||
72 | 'UPDATE session_rel_user |
||
73 | SET access_start_date = FROM_UNIXTIME(:startDate), access_end_date = FROM_UNIXTIME(:endDate) |
||
74 | WHERE id = :id', |
||
75 | [ |
||
76 | 'startDate' => $startDate, |
||
77 | 'endDate' => $endDate, |
||
78 | 'id' => $sru['id'], |
||
79 | ] |
||
184 | } |