TerminalSynchronizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A syncAll() 0 23 3
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Synchronizer;
4
5
use Loevgaard\AltaPay\Client\Client as AltapayClient;
6
use Loevgaard\DandomainAltapayBundle\Entity\Terminal;
7
use Loevgaard\DandomainAltapayBundle\Entity\TerminalRepository;
8
9
class TerminalSynchronizer
10
{
11
    /**
12
     * @var TerminalRepository
13
     */
14
    protected $terminalRepository;
15
16
    /**
17
     * @var AltapayClient
18
     */
19
    protected $altapayClient;
20
21
    public function __construct(TerminalRepository $terminalRepository, AltapayClient $altapayClient)
22
    {
23
        $this->terminalRepository = $terminalRepository;
24
        $this->altapayClient = $altapayClient;
25
    }
26
27
    public function syncAll()
28
    {
29
        $response = $this->altapayClient->getTerminals();
30
31
        foreach ($response->getTerminals() as $terminal) {
32
            $entity = $this->terminalRepository->findTerminalByTitle($terminal->getTitle());
33
            if (!$entity) {
34
                $entity = new Terminal();
35
            }
36
            $entity
37
                ->setTitle($terminal->getTitle())
38
                ->setCountry($terminal->getCountry())
39
                ->setNatures(array_map(function ($val) {
40
                    return (string) $val;
41
                }, $terminal->getNatures()))
42
                ->setCurrencies(array_map(function ($val) {
43
                    return (string) $val;
44
                }, $terminal->getCurrencies()))
45
            ;
46
47
            $this->terminalRepository->save($entity);
48
        }
49
    }
50
}
51