Completed
Push — master ( db30e2...3405a3 )
by Paweł
08:38
created

CreateOrganizationCommand::sendOutput()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher MultiTenancyBundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\CoreBundle\Command;
16
17
use SWP\Bundle\CoreBundle\Model\OrganizationInterface;
18
use SWP\Bundle\MultiTenancyBundle\Command\CreateOrganizationCommand as BaseCreateOrganizationCommand;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
class CreateOrganizationCommand extends BaseCreateOrganizationCommand
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        parent::configure();
30
        $this
31
            ->setDescription('Creates a new organization or updates existing one.')
32
            ->addOption('secretToken', 's', InputOption::VALUE_REQUIRED, 'Organization secret token');
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function createOrganization($name, $input)
39
    {
40
        $secretToken = $input->getOption('secretToken');
41
        /** @var OrganizationInterface $organization */
42
        $organization = parent::createOrganization($name, $input);
43
        if ($secretToken) {
44
            $organization->setSecretToken($secretToken);
45
        }
46
47
        return $organization;
48
    }
49
50
    /**
51
     * @param OutputInterface       $output
52
     * @param OrganizationInterface $organization
53
     */
54
    protected function sendOutput(OutputInterface $output, $organization)
55
    {
56
        $output->writeln(
57
            sprintf(
58
                'Organization <info>%s</info> (code: <info>%s</info>%s) has been created and <info>%s</info>!',
59
                $organization->getName(),
60
                $organization->getCode(),
61
                $organization->getSecretToken() ? ', secret token: <info>'.$organization->getSecretToken().'</info>' : '',
62
                $organization->isEnabled() ? 'enabled' : 'disabled'
63
            )
64
        );
65
    }
66
}
67