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

GetUserPractises   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 12 3
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