ListCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 10
c 0
b 0
f 0
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A define() 0 3 1
A __construct() 0 5 1
A doExecute() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Console\Commands\UserGroup;
6
7
use AbterPhp\Admin\Domain\Entities\UserGroup; // @phan-suppress-current-line PhanUnreferencedUseNormal
8
use AbterPhp\Admin\Orm\UserGroupRepo;
9
use Opulence\Console\Commands\Command;
10
use Opulence\Console\Responses\IResponse;
11
12
// @phan-suppress-current-line PhanUnreferencedUseNormal
13
class ListCommand extends Command
14
{
15
    public const COMMAND_NAME        = 'usergroup:list';
16
    public const COMMAND_DESCRIPTION = 'List available user groups';
17
18
    protected UserGroupRepo $userGroupRepo;
19
20
    /**
21
     * ListCommand constructor.
22
     *
23
     * @param UserGroupRepo $userGroupRepo
24
     */
25
    public function __construct(UserGroupRepo $userGroupRepo)
26
    {
27
        $this->userGroupRepo = $userGroupRepo;
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
     */
43
    protected function doExecute(IResponse $response)
44
    {
45
        /** @var UserGroup[] $userGroups */
46
        $userGroups = $this->userGroupRepo->getAll();
47
48
        foreach ($userGroups as $userGroup) {
49
            $response->writeln($userGroup->getIdentifier());
50
        }
51
    }
52
}
53