Passed
Push — master ( 593336...bc2cf1 )
by Hannes
02:43
created

InitConsole   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 11 2
A configure() 0 5 1
1
<?php
2
/**
3
 * This file is part of byrokrat\giroapp.
4
 *
5
 * byrokrat\giroapp is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as published
7
 * by the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * byrokrat\giroapp is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * Copyright 2016-19 Hannes Forsgård
19
 */
20
21
declare(strict_types = 1);
22
23
namespace byrokrat\giroapp\Console;
24
25
use Symfony\Component\Console\Command\Command;
26
use Symfony\Component\Console\Input\InputInterface;
27
use Symfony\Component\Console\Output\OutputInterface;
28
29
final class InitConsole implements ConsoleInterface
30
{
31
    private const INI_FILE_NAME = 'giroapp.ini';
32
    private const DIST_INI_PATH = __DIR__ . '/../../giroapp.ini.dist';
33
34
    public function configure(Command $command): void
35
    {
36
        $command->setName('init');
37
        $command->setDescription('Initialize installation');
38
        $command->setHelp('Create a default giroapp.ini in the current working directory.');
39
    }
40
41
    public function execute(InputInterface $input, OutputInterface $output): void
42
    {
43
        if (file_exists(self::INI_FILE_NAME)) {
44
            throw new \RuntimeException('Unable to create ' . self::INI_FILE_NAME . ', file already exists.');
45
        }
46
47
        copy(self::DIST_INI_PATH, self::INI_FILE_NAME);
48
49
        $iniPath = realpath(self::INI_FILE_NAME);
0 ignored issues
show
Unused Code introduced by
The assignment to $iniPath is dead and can be removed.
Loading history...
50
51
        $output->writeln(<<<'EOF'
52
Created configurations at <info>$iniPath</info>
53
54
Continue setup by editing configurations using a standard text editor.
55
Specifically the <info>org_name</info>, <info>org_id</info>, <info>org_bgc_nr</info> and <info>org_bg</info> settings
56
must be set.
57
58
To access configurations from other directories specify the location of
59
the configuration file by defining a <info>GIROAPP_INI</info> environment variable.
60
61
Simply run <info>giroapp</info> with no command specified to se the list of
62
avaliable commands.
63
EOF
64
        );
65
    }
66
}
67