Completed
Push — master ( 86b2cd...b16d12 )
by Richard
03:26
created

ReportCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/******************************************************************************
3
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 * 
5
 * Copyright (c) 2016 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received 
8
 * a copy of the license along with the code.
9
 */
10
11
namespace Lechimp\Dicto\App;
12
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * Command to create a report.
19
 */
20
class ReportCommand extends Command {
21
    /**
22
     * @inheritdoc
23
     */
24
    public function configure() {
25
        $this
26
            ->setName("report")
27
            ->setDescription
28
                ("Create a report."
29
                )
30
            ->setHelp
31
                ("This command will create a named report from the given configs."
32
                )
33
            ->addArgument
34
                ( "name"
35
                , InputArgument::REQUIRED
36
                , "Give the name of the report you want to create."
37
                )
38
            ->addArgument
39
                ( "configs"
40
                , InputArgument::IS_ARRAY
41
                , "Give paths to config files, separated by spaces."
42
                );
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function execute(InputInterface $input, OutputInterface $output) {
49
        $config_paths = $input->getArgument("configs");
50
        if (count($config_paths) == 0) {
51
            $output->writeLn("<error>You need to give the path to at least one config.</error>");
52
            return;
53
        }
54
        $config = $this->load_config($config_paths);
55
        $dic = $this->build_dic($config);
56
        $this->configure_runtime($config);
57
58
        $generator = $dic["report_generator"];
59
        $name = $input->getArgument("name");
60
        foreach ($config->reports() as $report) {
61
            if ($report->name() == $name) {
62
                $report = $report->with_target("php://stdout");
63
                $generator->generate($report);
64
            }
65
        }
66
    }
67
}
68