Completed
Push — master ( c5110b...a167e6 )
by Valentyn
13:46
created

ImdbDataMapper::dateToObject()   A

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
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
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
    public function __construct(ImdbCountryRepository $countryRepository)
16
    {
17
        $this->countryRepository = $countryRepository;
18
19
        $countries = $countryRepository->findAll();
20
21
        foreach ($countries as $imdbCountry) {
22
            $this->countryMap[$imdbCountry->getName()] = $imdbCountry->getCountry()->getCode();
23
        }
24
    }
25
26
    /***
27
     * @throws
28
     */
29
    public function dateToObject(string $date): \DateTimeInterface
30
    {
31
        return new \DateTimeImmutable($date);
32
    }
33
34
    public function countryToCode(string $country): string
35
    {
36
        return $this->countryMap[$country] ?? $country;
37
    }
38
}
39