Completed
Push — master ( 8fae0f...b69ce8 )
by Taosikai
14:32
created

ShowNationalityCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 2
1
<?php
2
/*
3
 * This file is part of the Slince/China package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace China\Command\Dashboard;
11
12
use China\Nationality\NationalityInterface;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Symfony\Component\Console\Style\SymfonyStyle;
16
17
class ShowNationalityCommand extends DashboardCommand
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function configure()
23
    {
24
        $this->setName('dashboard:nationality');
25
        $this->setDescription('展示民族数据信息');
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $nationalityService = $this->getChina()->getNationality();
34
        $style = new SymfonyStyle($input, $output);
35
        $headers = ['名称', '拼音', '人口'];
36
37
        $nationalities = $nationalityService->findAll()->toArray();
38
        $rows = array_map(function(NationalityInterface $nationality){
39
            return [
40
                "<info>{$nationality->getName()}</info>",
41
                $nationality->getPinyin(),
42
                $nationality->getPopulation()
43
            ];
44
        }, $nationalities);
45
        $style->table($headers, $rows);
46
    }
47
}