Passed
Pull Request — master (#309)
by Sander
04:30 queued 01:41
created

ConsoleUserProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setCurrentCommand() 0 6 2
A __invoke() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\AuditorBundle\User;
6
7
use DH\Auditor\User\User;
8
use DH\Auditor\User\UserInterface;
9
use DH\Auditor\User\UserProviderInterface;
10
use Symfony\Component\Console\Command\Command;
11
12
class ConsoleUserProvider implements UserProviderInterface
13
{
14
    private ?string $currentCommand = null;
15
16
    public function __invoke(): ?UserInterface
17
    {
18
        if (null === $this->currentCommand) {
19
            return null;
20
        }
21
22
        return new User(
23
            'command',
24
            $this->currentCommand ?? ''
25
        );
26
    }
27
28
    public function setCurrentCommand(?Command $command): void
29
    {
30
        if (null === $command) {
31
            $this->currentCommand = null;
32
        } else {
33
            $this->currentCommand = $command->getName();
34
        }
35
    }
36
}
37