Completed
Push — master ( 2a510c...5bfa5e )
by Richard
03:56
created

ReportCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 88.57%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 60
ccs 31
cts 35
cp 0.8857
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pull_deps_from() 0 4 1
A configure() 0 20 1
A execute() 0 12 3
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 Lechimp\Dicto\Report;
14
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Command to create a report.
21
 */
22
class ReportCommand extends Command {
23
    /**
24
     * @var Config|null
25
     */
26
    protected $config = null;
27
28
    /**
29
     * @var Report\Generator|null
30
     */
31
    protected $report_generator = null;
32
33
    /**
34
     * @inheritdoc
35
     */
36 1
    public function pull_deps_from($dic) {
37 1
        $this->config = $dic["config"];
38 1
        $this->report_generator = $dic["report_generator"];
39 1
    }
40
41
42
    /**
43
     * @inheritdoc
44
     */
45 1
    public function configure() {
46 1
        $this
47 1
            ->setName("report")
48
            ->setDescription
49 1
                ("Create a report."
50 1
                )
51
            ->setHelp
52 1
                ("This command will create a named report from the given configs."
53 1
                )
54
            ->addArgument
55 1
                ( "name"
56 1
                , InputArgument::REQUIRED
57 1
                , "Give the name of the report you want to create."
58 1
                )
59
            ->addArgument
60 1
                ( "configs"
61 1
                , InputArgument::IS_ARRAY
62 1
                , "Give paths to config files, separated by spaces."
63 1
                );
64 1
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69 1
    public function execute(InputInterface $input, OutputInterface $output) {
70 1
        assert('!is_null($this->config)');
71 1
        assert('!is_null($this->report_generator)');
72
73 1
        $name = $input->getArgument("name");
74 1
        foreach ($this->config->reports() as $report) {
75 1
            if ($report->name() == $name) {
76 1
                $report = $report->with_target("php://stdout");
77 1
                $this->report_generator->generate($report);
78 1
            }
79 1
        }
80 1
    }
81
}
82