SchemaClearCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 59
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 52
nc 2
nop 2
dl 0
loc 59
rs 9.0472
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Command\Fixture;
6
7
use App\Blog\Entity\Comment;
8
use App\Blog\Entity\Post;
9
use App\Blog\Entity\PostTag;
10
use App\Blog\Entity\Tag;
11
use App\User\User;
12
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Yiisoft\Yii\Console\ExitCode;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Console\ExitCode was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Yiisoft\Yii\Cycle\Command\CycleDependencyProxy;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Cycle\Command\CycleDependencyProxy was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
final class SchemaClearCommand extends Command
19
{
20
    protected static $defaultName = 'fixture/schema/clear';
21
22
    public function __construct(
23
        private CycleDependencyProxy $promise,
24
    ) {
25
        parent::__construct();
26
    }
27
28
    public function configure(): void
29
    {
30
        $this
31
            ->setDescription('Clear database from fixtures')
32
            ->setHelp('This command delete all tables');
33
    }
34
35
    protected function execute(InputInterface $input, OutputInterface $output): int
36
    {
37
        $this->promise
38
            ->getDatabaseProvider()
39
            ->database()
40
            ->delete('post')
41
            ->run();
42
43
        $this->promise
44
            ->getDatabaseProvider()
45
            ->database()
46
            ->delete('post_tag')
47
            ->run();
48
49
        $this->promise
50
            ->getDatabaseProvider()
51
            ->database()
52
            ->delete('tag')
53
            ->run();
54
55
        $this->promise
56
            ->getDatabaseProvider()
57
            ->database()
58
            ->delete('user')
59
            ->run();
60
61
        $this->promise
62
            ->getDatabaseProvider()
63
            ->database()
64
            ->delete('comment')
65
            ->run();
66
67
        return 0 === $this->promise
68
                ->getORM()
69
                ->getRepository(Post::class)
70
                ->select()
71
                ->count() +
72
            $this->promise
73
                ->getORM()
74
                ->getRepository(PostTag::class)
75
                ->select()
76
                ->count() +
77
            $this->promise
78
                ->getORM()
79
                ->getRepository(Tag::class)
80
                ->select()
81
                ->count() +
82
            $this->promise
83
                ->getORM()
84
                ->getRepository(User::class)
85
                ->select()
86
                ->count() +
87
            $this->promise
88
                ->getORM()
89
                ->getRepository(Comment::class)
90
                ->select()
91
                ->count()
92
            ? ExitCode::OK
93
            : ExitCode::UNSPECIFIED_ERROR;
94
    }
95
}
96