ImdbDataMapper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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