Passed
Push — master ( a54619...073016 )
by Derek Stephen
01:49
created

ClientScopeCommand   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 98
rs 10
c 0
b 0
f 0
ccs 0
cts 41
cp 0
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A removeScope() 0 3 1
A getArgOrGetUpset() 0 5 2
A configure() 0 4 1
A execute() 0 14 4
A addScope() 0 5 1
A listScopes() 0 3 1
A __construct() 0 8 1
1
<?php
2
3
namespace OAuth\Command;
4
5
use Exception;
6
use OAuth\Client;
7
use OAuth\Repository\ScopeRepository;
8
use OAuth\Scope;
9
use OAuth\Service\ClientService;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Helper\QuestionHelper;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Symfony\Component\Console\Question\ChoiceQuestion;
16
use Symfony\Component\Console\Question\ConfirmationQuestion;
17
use Symfony\Component\Console\Question\Question;
18
19
/**
20
 * Class ClientCommand
21
 * @package OAuth\Command
22
 */
23
class ClientScopeCommand extends Command
24
{
25
    /**
26
     * @var ClientService $clientService
27
     */
28
    private $clientService;
29
30
    /**
31
     * @var ScopeRepository $scopeRepository
32
     */
33
    private $scopeRepository;
34
35
    /** @var QuestionHelper $helper */
36
    private $helper;
0 ignored issues
show
introduced by
The private property $helper is not used, and could be removed.
Loading history...
37
38
    public function __construct(ClientService $clientService, ScopeRepository $scopeRepository)
39
    {
40
        $this->clientService = $clientService;
41
        $this->scopeRepository = $scopeRepository;
42
        parent::__construct('client:scope');
43
        $this->addArgument('operation', InputArgument::REQUIRED, 'list, add, or remove.');
44
        $this->addArgument('client', InputArgument::OPTIONAL, 'The client identifier.');
45
        $this->addArgument('scope', InputArgument::OPTIONAL, 'The scope name when adding or removing.');
46
    }
47
48
    /**
49
     * configure options
50
     */
51
    protected function configure()
52
    {
53
        $this->setDescription('Add, remove, or list scopes for each client.');
54
        $this->setHelp('Client scope administration');
55
    }
56
57
    /**
58
     * @param InputInterface $input
59
     * @param OutputInterface $output
60
     * @return int|void|null
61
     * @throws Exception
62
     */
63
    protected function execute(InputInterface $input, OutputInterface $output)
64
    {
65
        $output->writeln('Client scope administration');
66
        $operation = $input->getArgument('operation');
67
        switch ($operation) {
68
            case 'list';
69
                $this->listScopes($input, $output);
70
                break;
71
            case 'add';
72
                $this->addScope($input, $output);
73
                break;
74
            case 'remove';
75
                $this->removeScope($input, $output);
76
                break;
77
        }
78
    }
79
80
    /**
81
     * @param string $argName
82
     * @param string $value
83
     * @throws Exception
84
     */
85
    private function getArgOrGetUpset(InputInterface $input, string $argName)
86
    {
87
        $value = $input->getArgument($argName);
88
        if (!$value) {
89
            throw new Exception('No ' . $argName . ' provided');
90
        }
91
    }
92
93
    /**
94
     * @param InputInterface $input
95
     * @param OutputInterface $output
96
     */
97
    private function listScopes(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

97
    private function listScopes(/** @scrutinizer ignore-unused */ InputInterface $input, OutputInterface $output)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
    {
99
        $output->writeln('List scopes for client');
100
    }
101
102
    /**
103
     * @param InputInterface $input
104
     * @param OutputInterface $output
105
     * @throws Exception
106
     */
107
    private function addScope(InputInterface $input, OutputInterface $output)
108
    {
109
        $client = $this->getArgOrGetUpset($input, 'client');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $client is correct as $this->getArgOrGetUpset($input, 'client') targeting OAuth\Command\ClientScop...and::getArgOrGetUpset() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
110
        $scope = $this->getArgOrGetUpset($input, 'scope');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $scope is correct as $this->getArgOrGetUpset($input, 'scope') targeting OAuth\Command\ClientScop...and::getArgOrGetUpset() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
111
        $output->writeln('Scope '. $scope . ', client ' . $client);
112
    }
113
114
    /**
115
     * @param InputInterface $input
116
     * @param OutputInterface $output
117
     */
118
    private function removeScope(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

118
    private function removeScope(/** @scrutinizer ignore-unused */ InputInterface $input, OutputInterface $output)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
119
    {
120
        $output->writeln('Remove scope for client');
121
    }
122
}