Test Failed
Push — dev ( 17f6d8...392257 )
by Janko
10:17 queued 12s
created

SessionStringFactory::createSessionString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Session;
6
7
use Stu\Module\Control\StuTime;
8
use Stu\Orm\Entity\UserInterface;
9
use Stu\Orm\Repository\SessionStringRepositoryInterface;
10
11
class SessionStringFactory implements SessionStringFactoryInterface
12
{
13
    public function __construct(
14
        private SessionStringRepositoryInterface $sessionStringRepository,
15
        private StuTime $stuTime
16
    ) {}
17
18
    public function createSessionString(UserInterface $user): string
19
    {
20
        $string = bin2hex(random_bytes(15));
21
22
        $sessionString =
23
            $this->sessionStringRepository->prototype()
24
            ->setUser($user)
25
            ->setDate($this->stuTime->dateTime())
26
            ->setSessionString($string);
27
28
        $this->sessionStringRepository->save($sessionString);
29
30
        return $string;
31
    }
32
}
33