|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace App\Src\UseCases\Infra\Sql; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use App\Src\UseCases\Domain\Context\Dto\ContextDto; |
|
8
|
|
|
use App\Src\UseCases\Domain\Context\Model\Context; |
|
9
|
|
|
use App\Src\UseCases\Domain\Ports\ContextRepository; |
|
10
|
|
|
use App\Src\UseCases\Infra\Sql\Model\ContextModel; |
|
11
|
|
|
use App\User; |
|
12
|
|
|
|
|
13
|
|
|
class ContextRepositorySql implements ContextRepository |
|
14
|
|
|
{ |
|
15
|
|
|
public function getByUser(string $userId):?Context |
|
16
|
|
|
{ |
|
17
|
|
|
$user = User::where('uuid', $userId)->first(); |
|
18
|
|
|
return $user->context !== null ? $user->context->toDomain() : null; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function add(Context $context, string $userId) |
|
22
|
|
|
{ |
|
23
|
|
|
$contextData = collect($context->toArray()); |
|
24
|
|
|
$user = User::where('uuid', $userId)->first(); |
|
25
|
|
|
|
|
26
|
|
|
$characteristics = $contextData->get('characteristics'); |
|
27
|
|
|
$user->addCharacteristics($characteristics); |
|
28
|
|
|
|
|
29
|
|
|
$contextModel = (new ContextModel())->fill($contextData->except('characteristics')->toArray()); |
|
30
|
|
|
$contextModel->save(); |
|
31
|
|
|
$user->context_id = $contextModel->id; |
|
32
|
|
|
$user->save(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getByUserDto(string $userId): ?ContextDto |
|
36
|
|
|
{ |
|
37
|
|
|
$user = User::where('uuid', $userId)->first(); |
|
38
|
|
|
if($user === null){ |
|
39
|
|
|
return null; |
|
40
|
|
|
} |
|
41
|
|
|
return $user->context !== null ? $user->context->toDto($user->uuid) : null; |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function update(Context $context, string $userId) |
|
45
|
|
|
{ |
|
46
|
|
|
$user = User::where('uuid', $userId)->first(); |
|
47
|
|
|
if($user === null){ |
|
48
|
|
|
return null; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$contextModel = $user->context; |
|
52
|
|
|
if($contextModel === null){ |
|
53
|
|
|
return null; |
|
54
|
|
|
} |
|
55
|
|
|
$contextData = collect($context->toArray()); |
|
56
|
|
|
$contextModel->fill($contextData->except('characteristics')->toArray()); |
|
57
|
|
|
$contextModel->save(); |
|
58
|
|
|
|
|
59
|
|
|
$characteristics = $contextData->get('characteristics'); |
|
60
|
|
|
$user->syncCharacteristics($characteristics); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.