Passed
Push — master ( 7c51ba...a22fab )
by Peter
04:20
created

ListCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

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

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;
8
use AbterPhp\Admin\Orm\UserGroupRepo;
9
use Opulence\Console\Commands\Command;
10
use Opulence\Console\Responses\IResponse;
11
12
class ListCommand extends Command
13
{
14
    const COMMAND_NAME        = 'usergroup:list';
15
    const COMMAND_DESCRIPTION = 'List available user groups';
16
17
    /** @var UserGroupRepo */
18
    protected $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