Command::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ParcelValue\ApiClient\Domain\AuthenticationHash;
6
7
use WebServCo\Framework\Cli\Ansi;
8
use WebServCo\Framework\Cli\Response;
9
use WebServCo\Framework\Cli\Sgr;
10
use WebServCo\Framework\Interfaces\ResponseInterface;
11
12
final class Command extends \ParcelValue\ApiClient\AbstractController
13
{
14
    use \ParcelValue\ApiClient\Traits\ControllerApiTrait;
15
16
    protected \WebServCo\Framework\Interfaces\OutputLoggerInterface $outputLogger;
17
18
    public function __construct()
19
    {
20
        parent::__construct();
21
22
        $this->outputLogger = new \WebServCo\Framework\Log\CliOutputLogger();
23
    }
24
25
    public function generate(string $username, string $password): ResponseInterface
26
    {
27
        $this->init();
28
29
        $this->outputLogger->output(Ansi::clear(), true);
30
        $this->outputLogger->output(Ansi::sgr(__METHOD__, [Sgr::BOLD]), true);
31
        $this->outputLogger->output('');
32
33
        $hash = \hash('sha256', \sprintf('%s:%s', \trim($username), \md5(\trim($password))));
34
35
        $this->outputLogger->output(Ansi::sgr('Success!', [Sgr::GREEN]), false);
36
        $this->outputLogger->output(' Your hash is:', true);
37
        $this->outputLogger->output('');
38
        $this->outputLogger->output($hash, true);
39
        $this->outputLogger->output('');
40
        return new Response();
41
    }
42
}
43