Completed
Push — master ( 7c1eaa...80d841 )
by Joachim
15:53
created

TerminalSynchronizer   A

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
lcom 1
cbo 5
dl 0
loc 42
c 0
b 0
f 0
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 as AltapayClient;
6
use Loevgaard\DandomainAltapayBundle\Manager\TerminalManager;
7
8
class TerminalSynchronizer
9
{
10
    /**
11
     * @var TerminalManager
12
     */
13
    protected $terminalManager;
14
15
    /**
16
     * @var AltapayClient
17
     */
18
    protected $altapayClient;
19
20
    public function __construct(TerminalManager $terminalManager, AltapayClient $altapayClient)
21
    {
22
        $this->terminalManager = $terminalManager;
23
        $this->altapayClient = $altapayClient;
24
    }
25
26
    public function syncAll()
27
    {
28
        $response = $this->altapayClient->getTerminals();
29
30
        foreach ($response->getTerminals() as $terminal) {
31
            $entity = $this->terminalManager->findTerminalByTitle($terminal->getTitle());
32
            if (!$entity) {
33
                $entity = $this->terminalManager->create();
34
            }
35
            $entity
36
                ->setTitle($terminal->getTitle())
37
                ->setCountry($terminal->getCountry())
38
                ->setNatures(array_map(function ($val) {
39
                    return (string) $val;
40
                }, $terminal->getNatures()))
41
                ->setCurrencies(array_map(function ($val) {
42
                    return (string) $val;
43
                }, $terminal->getCurrencies()))
44
            ;
45
46
            $this->terminalManager->update($entity);
47
        }
48
    }
49
}
50