ListCommand::doExecute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Console\Commands\AdminResource;
6
7
use AbterPhp\Admin\Domain\Entities\AdminResource; // @phan-suppress-current-line PhanUnreferencedUseNormal
8
use AbterPhp\Admin\Orm\AdminResourceRepo;
9
use Opulence\Console\Commands\Command;
10
use Opulence\Console\Responses\IResponse;
11
use Opulence\Orm\OrmException;
12
13
class ListCommand extends Command
14
{
15
    protected const COMMAND_NAME        = 'adminresource:list';
16
    protected const COMMAND_DESCRIPTION = 'List available admin resources';
17
18
    protected AdminResourceRepo $adminResourceRepo;
19
20
    /**
21
     * ListCommand constructor.
22
     *
23
     * @param AdminResourceRepo $adminResourceRepo
24
     */
25
    public function __construct(AdminResourceRepo $adminResourceRepo)
26
    {
27
        $this->adminResourceRepo = $adminResourceRepo;
28
29
        parent::__construct();
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    protected function define()
36
    {
37
        $this->setName(static::COMMAND_NAME)->setDescription(static::COMMAND_DESCRIPTION);
38
    }
39
40
    /**
41
     * @inheritdoc
42
     * @throws OrmException
43
     */
44
    protected function doExecute(IResponse $response)
45
    {
46
        /** @var AdminResource[] $adminResources */
47
        $adminResources = $this->adminResourceRepo->getAll();
48
49
        foreach ($adminResources as $adminResource) {
50
            $response->writeln($adminResource->getIdentifier());
51
        }
52
    }
53
}
54