InitConsole   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

2 Methods

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