Test Failed
Pull Request — master (#461)
by
unknown
21:05 queued 17:23
created

SchemaClearCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Command\Fixture;
6
7
use App\Blog\Entity\PostTag;
8
use App\Blog\Entity\Tag;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Yiisoft\Yii\Console\ExitCode;
13
use Yiisoft\Yii\Cycle\Command\CycleDependencyProxy;
14
use App\Blog\Entity\Comment;
15
use App\Blog\Entity\Post;
16
use App\User\User;
17
18
19
final class SchemaClearCommand extends Command
20
{
21
    protected static $defaultName = 'fixture/schema/clear';
22
23
    private CycleDependencyProxy $promise;
24
25
26
    public function __construct(
27
        CycleDependencyProxy $promise,
28
    ) {
29
        $this->promise = $promise;
30
        parent::__construct();
31
    }
32
33
    public function configure(): void
34
    {
35
        $this
36
            ->setDescription('Clear database from fixtures')
37
            ->setHelp('This command delete all tables');
38
    }
39
40
    protected function execute(InputInterface $input, OutputInterface $output): int
41
    {
42
        $this->promise
43
            ->getDatabaseProvider()
44
            ->database()
45
            ->delete('post')
46
            ->run();
47
48
        $this->promise
49
            ->getDatabaseProvider()
50
            ->database()
51
            ->delete('post_tag')
52
            ->run();
53
54
        $this->promise
55
            ->getDatabaseProvider()
56
            ->database()
57
            ->delete('tag')
58
            ->run();
59
60
        $this->promise
61
            ->getDatabaseProvider()
62
            ->database()
63
            ->delete('user')
64
            ->run();
65
66
        $this->promise
67
            ->getDatabaseProvider()
68
            ->database()
69
            ->delete('comment')
70
            ->run();
71
72
        return 0 === $this->promise
73
                ->getORM()
74
                ->getRepository(Post::class)
75
                ->select()
76
                ->count() +
77
            $this->promise
78
                ->getORM()
79
                ->getRepository(PostTag::class)
80
                ->select()
81
                ->count() +
82
            $this->promise
83
                ->getORM()
84
                ->getRepository(Tag::class)
85
                ->select()
86
                ->count() +
87
            $this->promise
88
                ->getORM()
89
                ->getRepository(User::class)
90
                ->select()
91
                ->count() +
92
            $this->promise
93
                ->getORM()
94
                ->getRepository(Comment::class)
95
                ->select()
96
                ->count()
97
            ? ExitCode::OK
98
            : ExitCode::UNSPECIFIED_ERROR;
99
100
    }
101
102
}
103