ImdbDataMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3
ccs 0
cts 12
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A dateToObject() 0 4 1
A countryToCode() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Movies\Service;
6
7
use App\Countries\Repository\ImdbCountryRepository;
8
9
class ImdbDataMapper
10
{
11
    private $countryMap = [];
12
13
    private $countryRepository;
14
15
    private $isMapped = false;
16
17
    public function __construct(ImdbCountryRepository $countryRepository)
18
    {
19
        $this->countryRepository = $countryRepository;
20
    }
21
22
    /***
23
     * @throws
24
     */
25
    public function dateToObject(string $date): \DateTimeInterface
26
    {
27
        return new \DateTimeImmutable($date);
28
    }
29
30
    public function countryToCode(string $country): string
31
    {
32
        if ($this->isMapped === false) {
33
            $this->isMapped = true;
34
            $countries = $this->countryRepository->findAll();
35
            foreach ($countries as $imdbCountry) {
36
                $this->countryMap[$imdbCountry->getName()] = $imdbCountry->getCountry()->getCode();
37
            }
38
        }
39
40
        return $this->countryMap[$country] ?? $country;
41
    }
42
}
43