Passed
Push — master ( 956624...05ed8c )
by Bertrand
08:49
created

GetUserPractises::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Context\Queries;
5
6
7
use App\Src\UseCases\Domain\Ports\InteractionRepository;
8
9
class GetUserPractises
10
{
11
    private $interactionsRepository;
12
13
    public function __construct(InteractionRepository $interactionRepository)
14
    {
15
        $this->interactionsRepository = $interactionRepository;
16
    }
17
18
    public function get(string $userId):array
19
    {
20
        $practisesToReturn = [];
21
        $practises = $this->interactionsRepository->getDoneByUser($userId);
22
        foreach ($practises as $practise){
23
            $year = $practise->doneAt() !== null ? $practise->doneAt()->format('Y') : 'Non datée';
24
            $practisesToReturn[$year][] = $practise->toArray();
25
        }
26
27
        krsort($practisesToReturn, SORT_NUMERIC);
28
29
        return $practisesToReturn;
30
    }
31
}
32