ListOrganizationsCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\MultiTenancyBundle\Command;
16
17
use SWP\Component\MultiTenancy\Model\OrganizationInterface;
18
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
19
use Symfony\Component\Console\Helper\Table;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
class ListOrganizationsCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
24
{
25
    protected static $defaultName = 'swp:organization:list';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function configure()
31
    {
32
        $this
33
            ->setName('swp:organization:list')
34
            ->setDescription('List all available organizations.');
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        /** @var OrganizationInterface[] $organizations */
43
        $organizations = $this->getContainer()->get('swp.repository.organization')->findAll();
44
        if (0 === count($organizations)) {
45
            $output->writeln('<error>There are no organizations defined.</error>');
46
47
            return;
48
        }
49
50
        $output->writeln('<info>List of all available organizations:</info>');
51
        $table = new Table($output);
52
        $table->setHeaders(['Id', 'Code', 'Name', 'Is active?', 'Created at']);
53
        foreach ($organizations as $organization) {
54
            $table->addRow([
55
                $organization->getId(),
56
                $organization->getCode(),
57
                $organization->getName(),
58
                $organization->isEnabled() ? 'yes' : 'no',
59
                $organization->getCreatedAt()->format('Y-m-d H:i:s'),
60
            ]);
61
        }
62
63
        $table->render();
64
    }
65
}
66