FrontendUserManager::save()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 12
ccs 0
cts 11
cp 0
crap 6
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DMK\MKSamlAuth\Manager;
6
7
use DMK\MKSamlAuth\Model\FrontendUser;
8
use DMK\MKSamlAuth\Repository\FrontendUserRepository;
9
use TYPO3\CMS\Core\Database\ConnectionPool;
10
11
class FrontendUserManager
12
{
13
    /**
14
     * @var ConnectionPool
15
     */
16
    private $pool;
17
18
    /**
19
     * @var \ReflectionClass
20
     */
21
    private $reflection;
22
23
    public function __construct(ConnectionPool $pool)
24
    {
25
        $this->reflection = new \ReflectionClass(FrontendUser::class);
26
        $this->pool = $pool;
27
    }
28
29
    public function getRepository(): FrontendUserRepository
30
    {
31
        return new FrontendUserRepository($this->pool);
32
    }
33
34
    public function save(FrontendUser $user)
35
    {
36
        $property = $this->reflection->getProperty('data');
37
        $property->setAccessible(true);
38
        $data = $property->getValue($user);
39
40
        if (null === $user->getUid()) {
41
            $this->pool->getConnectionForTable('fe_users')->insert('fe_users', $data);
42
            $user->setProperty('uid', $this->pool->getConnectionForTable('fe_users')->lastInsertId());
43
        } else {
44
            $this->pool->getConnectionForTable('fe_users')->update('fe_users', $data, [
45
                'uid' => $user->getUid(),
46
            ]);
47
        }
48
    }
49
}
50