Passed
Push — master ( fdb26f...810f98 )
by Christian
23:44 queued 11s
created

BlueGreenDeploymentService::getCreateTableQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Recovery\Install\Service;
4
5
use Doctrine\DBAL\Connection;
6
7
class BlueGreenDeploymentService
8
{
9
    public const ENV_NAME = 'BLUE_GREEN_DEPLOYMENT';
10
11
    /**
12
     * @var Connection
13
     */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    public function setEnvironmentVariable(): void
22
    {
23
        $_ENV[self::ENV_NAME] = $_SESSION[self::ENV_NAME] = $this->checkIfMayCreateTrigger();
24
    }
25
26
    private function checkIfMayCreateTrigger(): bool
27
    {
28
        try {
29
            $this->connection->executeQuery($this->getCreateTableQuery());
30
            $this->connection->executeQuery($this->getTriggerQuery());
31
        } catch (\Doctrine\DBAL\DBALException $exception) {
32
            return false;
33
        } finally {
34
            $this->connection->executeQuery('DROP TABLE IF EXISTS example');
35
        }
36
37
        return true;
38
    }
39
40
    private function getCreateTableQuery(): string
41
    {
42
        return <<<SQL
43
            CREATE TABLE IF NOT EXISTS `example` (
44
              `id` int NOT NULL
45
            );
46
SQL;
47
    }
48
49
    private function getTriggerQuery(): string
50
    {
51
        return <<<SQL
52
            CREATE TRIGGER example_trigger BEFORE UPDATE ON `example`
53
                FOR EACH ROW
54
                BEGIN
55
                END;
56
SQL;
57
    }
58
}
59