ConsoleUserProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 2
A setCurrentCommand() 0 3 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
        $this->currentCommand = null === $command ? null : $command->getName();
31
    }
32
}
33