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

ImdbDataMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 30
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A dateToObject() 0 4 1
A countryToCode() 0 4 1
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