Completed
Push — master ( 636a3e...0d9cfe )
by Joachim
12:23
created

SyncTerminalsCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
B execute() 0 25 3
1
<?php
2
namespace Loevgaard\DandomainAltapayBundle\Command;
3
4
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
class SyncTerminalsCommand extends ContainerAwareCommand
9
{
10
    protected function configure()
11
    {
12
        $this->setName('loevgaard_dandomain_altapay:sync-terminals')
13
            ->setDescription('Synchronizes terminals from Altapay to the local database (one way sync)')
14
        ;
15
    }
16
17
    protected function execute(InputInterface $input, OutputInterface $output)
18
    {
19
        $terminalManager = $this->getContainer()->get('loevgaard_dandomain_altapay.terminal_manager');
20
        $altapayClient = $this->getContainer()->get('loevgaard_dandomain_altapay.altapay_client');
21
        $response = $altapayClient->getTerminals();
22
23
        foreach ($response->getTerminals() as $terminal) {
24
            $entity = $terminalManager->findTerminalByTitle($terminal->getTitle());
25
            if(!$entity) {
26
                $entity = $terminalManager->createTerminal();
27
            }
28
            $entity
29
                ->setTitle($terminal->getTitle())
30
                ->setCountry($terminal->getCountry())
31
                ->setNatures(array_map(function ($val) {
32
                    return (string)$val;
33
                }, $terminal->getNatures()))
34
                ->setCurrencies(array_map(function ($val) {
35
                    return (string)$val;
36
                }, $terminal->getCurrencies()))
37
            ;
38
39
            $terminalManager->updateTerminal($entity);
40
        }
41
    }
42
}