Completed
Push — master ( 4a905b...82874d )
by Michael
02:55
created

YapealAutoMagic::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
ccs 0
cts 15
cp 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * Contains class YapealAutoMagic.
5
 *
6
 * PHP version 7.0+
7
 *
8
 * LICENSE:
9
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
10
 * which can be used to access the Eve Online API data and place it into a
11
 * database.
12
 * Copyright (C) 2016 Michael Cummings
13
 *
14
 * This program is free software: you can redistribute it and/or modify it
15
 * under the terms of the GNU Lesser General Public License as published by the
16
 * Free Software Foundation, either version 3 of the License, or (at your
17
 * option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful, but WITHOUT
20
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
22
 * for more details.
23
 *
24
 * You should have received a copy of the GNU Lesser General Public License
25
 * along with this program. If not, see
26
 * <http://spdx.org/licenses/LGPL-3.0.html>.
27
 *
28
 * You should be able to find a copy of this license in the COPYING-LESSER.md
29
 * file. A copy of the GNU GPL should also be available in the COPYING.md file.
30
 *
31
 * @copyright 2016 Michael Cummings
32
 * @license   LGPL-3.0+
33
 * @author    Michael Cummings <[email protected]>
34
 */
35
namespace Yapeal\Cli\Yapeal;
36
37
use Symfony\Component\Console\Command\Command;
38
use Symfony\Component\Console\Input\InputInterface;
39
use Symfony\Component\Console\Output\OutputInterface;
40
use Yapeal\Cli\ConfigFileTrait;
41
use Yapeal\Cli\VerbosityToStrategyTrait;
42
use Yapeal\CommonToolsTrait;
43
use Yapeal\Container\ContainerInterface;
44
use Yapeal\Event\EveApiEventEmitterTrait;
45
use Yapeal\Event\YEMAwareInterface;
46
use Yapeal\Log\Logger;
47
use Yapeal\Yapeal;
48
49
/**
50
 * Class YapealAutoMagic.
51
 */
52
class YapealAutoMagic extends Command implements YEMAwareInterface
53
{
54
    use CommonToolsTrait, ConfigFileTrait, EveApiEventEmitterTrait, VerbosityToStrategyTrait;
55
    /**
56
     * @param string|null        $name
57
     * @param ContainerInterface $dic
58
     *
59
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
60
     * @throws \Symfony\Component\Console\Exception\LogicException
61
     */
62
    public function __construct($name, ContainerInterface $dic)
63
    {
64
        $this->setDescription('Auto-magically process all Eve APIs');
65
        $this->setName($name);
66
        $this->setDic($dic);
67
        parent::__construct($name);
68
    }
69
    /**
70
     * Configures the current command.
71
     */
72
    protected function configure()
73
    {
74
        $help = <<<'EOF'
75
The <info>%command.full_name%</info> command executes the main autoMagic method
76
of the Yapeal class. This is meant as a replace for the now deprecated
77
bin/yapeal.php script used to start Yapeal from earlier versions.
78
79
    <info>php %command.full_name%</info>
80
81
EXAMPLES:
82
Using with optional --configFile option to override matching existing settings
83
from other normally processed configuration files.
84
    <info>%command.name% -c "path/to/my/special/config.yaml"</info>
85
86
EOF;
87
        $this->addConfigFileOption();
88
        $this->setHelp($help);
89
    }
90
    /** @noinspection PhpMissingParentCallCommonInspection */
91
    /**
92
     * Executes the current command.
93
     *
94
     * This method is not abstract because you can use this class
95
     * as a concrete class. In this case, instead of defining the
96
     * execute() method, you set the code to execute by passing
97
     * a Closure to the setCode() method.
98
     *
99
     * @param InputInterface  $input  An InputInterface instance
100
     * @param OutputInterface $output An OutputInterface instance
101
     *
102
     * @return int|null null or 0 if everything went fine, or an error code
103
     * @throws \DomainException
104
     * @throws \InvalidArgumentException
105
     * @throws \LogicException
106
     * @throws \Yapeal\Exception\YapealDatabaseException
107
     * @throws \Yapeal\Exception\YapealException
108
     *
109
     * @see    setCode()
110
     */
111
    protected function execute(InputInterface $input, OutputInterface $output)
112
    {
113
        $dic = $this->getDic();
114
        if (!$this->hasYem()) {
115
            $this->setYem($dic['Yapeal.Event.Mediator']);
116
        }
117
        $this->setLogThresholdFromVerbosity($output);
118
        if ($output::VERBOSITY_QUIET !== $output->getVerbosity()) {
119
            $mess = sprintf('<info>Starting %1$s</info>', $this->getName());
120
            $output->writeln($mess);
121
            $this->getYem()
122
                ->triggerLogEvent('Yapeal.Log.log', Logger::INFO, strip_tags($mess));
123
        }
124
        $options = $input->getOptions();
125
        if (!empty($options['configFile'])) {
126
            $this->processConfigFile($options['configFile'], $dic);
127
        }
128
        return (new Yapeal($dic))->autoMagic();
129
    }
130
}
131