Version20201125192634   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 23
c 0
b 0
f 0
dl 0
loc 58
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setTimetableSettings() 0 2 1
A postUp() 0 15 2
A up() 0 4 1
A down() 0 4 1
A preUp() 0 3 1
A setTimetableTimeHelper() 0 2 1
A getDescription() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineMigrations;
6
7
use App\Migrations\TimetableSettingsDependentMigrationInterface;
8
use App\Migrations\TimetableTimeHelperDependentMigrationInterface;
9
use App\Settings\TimetableSettings;
10
use App\Timetable\TimetableTimeHelper;
11
use DateTime;
12
use Doctrine\DBAL\Schema\Schema;
13
use Doctrine\Migrations\AbstractMigration;
14
15
/**
16
 * Auto-generated Migration: Please modify to your needs!
17
 */
18
final class Version20201125192634 extends AbstractMigration implements TimetableTimeHelperDependentMigrationInterface, TimetableSettingsDependentMigrationInterface
19
{
20
    private ?TimetableTimeHelper $timetableTimeHelper = null;
21
22
    private ?TimetableSettings $timetableSettings = null;
23
24
    /** @var array[] */
25
    private array $sickNotes = [ ];
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function setTimetableTimeHelper(TimetableTimeHelper $timetableTimeHelper): void {
31
        $this->timetableTimeHelper = $timetableTimeHelper;
32
    }
33
34
    public function setTimetableSettings(TimetableSettings $settings): void {
35
        $this->timetableSettings = $settings;
36
    }
37
38
    public function preUp(Schema $schema): void {
39
        $stmt = $this->connection->executeQuery('SELECT * FROM sick_note');
40
        $this->sickNotes = $stmt->fetchAllAssociative();
41
    }
42
43
    public function postUp(Schema $schema): void {
44
        foreach($this->sickNotes as $note) {
45
            $createdAt = new DateTime($note['created_at']);
46
            $from = $this->timetableTimeHelper->getLessonDateForDateTime($createdAt);
0 ignored issues
show
Bug introduced by
The method getLessonDateForDateTime() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
            /** @scrutinizer ignore-call */ 
47
            $from = $this->timetableTimeHelper->getLessonDateForDateTime($createdAt);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
48
            $until = new DateTime($note['until']);
49
            $until->setTime(0, 0, 0);
50
51
            $stmt = $this->connection->prepare('UPDATE sick_note SET from_date = ?, from_lesson = ?, until_date = ?, until_lesson = ? WHERE id = ?');
52
            $stmt->bindValue(1, $from->getDate(), "date");
53
            $stmt->bindValue(2, $from->getLesson(), "integer");
54
            $stmt->bindValue(3, $until, "date");
55
            $stmt->bindValue(4, $this->timetableSettings->getMaxLessons(), "integer");
0 ignored issues
show
Bug introduced by
The method getMaxLessons() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
            $stmt->bindValue(4, $this->timetableSettings->/** @scrutinizer ignore-call */ getMaxLessons(), "integer");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
            $stmt->bindValue(5, $note['id'], "string");
57
            $stmt->execute();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Statement::execute() has been deprecated: Statement::execute() is deprecated, use Statement::executeQuery() or executeStatement() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

57
            /** @scrutinizer ignore-deprecated */ $stmt->execute();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
58
        }
59
    }
60
61
    public function getDescription() : string
62
    {
63
        return '';
64
    }
65
66
    public function up(Schema $schema) : void
67
    {
68
        // this up() migration is auto-generated, please modify it to your needs
69
        $this->addSql('ALTER TABLE sick_note ADD from_date DATE NOT NULL, ADD from_lesson INT NOT NULL, ADD until_date DATE NOT NULL, ADD until_lesson INT NOT NULL, DROP until');
70
    }
71
72
    public function down(Schema $schema) : void
73
    {
74
        // this down() migration is auto-generated, please modify it to your needs
75
        $this->addSql('ALTER TABLE sick_note ADD until DATETIME NOT NULL, DROP from_date, DROP from_lesson, DROP until_date, DROP until_lesson');
76
    }
77
78
79
}
80