Completed
Push — master ( 0c27d5...96f1c9 )
by Dragos
03:55
created

CustomerCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Speicher210\FastbillBundle\Command;
4
5
use Speicher210\Fastbill\Api\Service\Customer\Get\RequestData;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Helper\Table;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Command for listing customers.
14
 */
15
class CustomerCommand extends ContainerAwareCommand
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected function configure()
21
    {
22
        $this
23
            ->setName('sp210:fastbill:customer')
24
            ->setDescription('List information about the customers.')
25
            ->addOption('id', null, InputOption::VALUE_REQUIRED, 'Optional Fastbill customer ID')
26
            ->addOption('ext-id', null, InputOption::VALUE_REQUIRED, 'Optional external ID');
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        /** @var \Speicher210\Fastbill\Api\Service\Customer\CustomerService $customerService */
35
        $customerService = $this->getContainer()->get('speicher210_fastbill.service.customer');
36
37
        $requestData = new RequestData();
38
        $requestData->setCustomerId($input->getOption('id'));
39
        $requestData->setCustomerExternalUid($input->getOption('ext-id'));
40
        $apiResponse = $customerService->getCustomers($requestData);
41
        $customers = $apiResponse->getResponse()->getCustomers();
42
43
        $table = new Table($output);
44
        $table->setHeaders(
45
            array(
46
                'ID',
47
                'External ID',
48
                'Create data',
49
                'Name',
50
                'Organization',
51
                'Email',
52
                'Phone',
53
                'Comment',
54
                'Last update',
55
            )
56
        );
57
58
        foreach ($customers as $customer) {
59
            $table->addRow(
60
                array(
61
                    $customer->getCustomerId(),
62
                    $customer->getCustomerExternalUid(),
63
                    $customer->getCreated() ? $customer->getCreated()->format(\DateTime::W3C) : null,
64
                    $customer->getFirstName().' '.$customer->getLastName(),
65
                    $customer->getOrganization(),
66
                    $customer->getEmail(),
67
                    $customer->getPhone(),
68
                    $customer->getComment(),
69
                    $customer->getLastUpdate() ? $customer->getLastUpdate()->format(\DateTime::W3C) : null,
70
                )
71
            );
72
        }
73
74
        $table->render();
75
    }
76
}
77