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