ShowNationalityCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 6
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 16 1
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
11
namespace China\Command\Dashboard;
12
13
use China\Nationality\NationalityInterface;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Console\Style\SymfonyStyle;
17
18
class ShowNationalityCommand extends DashboardCommand
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function configure()
24
    {
25
        $this->setName('dashboard:nationality');
26
        $this->setDescription('展示民族数据信息');
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $nationalityService = $this->getChina()->getNationality();
35
        $style = new SymfonyStyle($input, $output);
36
        $headers = ['名称', '拼音', '人口'];
37
38
        $nationalities = $nationalityService->findAll()->toArray();
39
        $rows = array_map(function(NationalityInterface $nationality){
40
            return [
41
                "<info>{$nationality->getName()}</info>",
42
                $nationality->getPinyin(),
43
                $nationality->getPopulation(),
44
            ];
45
        }, $nationalities);
46
        $style->table($headers, $rows);
47
    }
48
}