Issues (2560)

app/Cli/Commands/TreeCreate.php (4 issues)

1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2025 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program 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
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Cli\Commands;
21
22
use Fisharebest\Webtrees\Contracts\TreeInterface;
0 ignored issues
show
The type Fisharebest\Webtrees\Contracts\TreeInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Fisharebest\Webtrees\DB;
0 ignored issues
show
The type Fisharebest\Webtrees\DB was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Fisharebest\Webtrees\Services\TreeService;
0 ignored issues
show
The type Fisharebest\Webtrees\Services\TreeService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Symfony\Component\Console\Command\Command;
26
use Symfony\Component\Console\Input\InputInterface;
27
use Symfony\Component\Console\Input\InputOption;
28
use Symfony\Component\Console\Output\OutputInterface;
29
use Symfony\Component\Console\Style\SymfonyStyle;
30
31
final class TreeCreate extends AbstractCommand
32
{
33
    public function __construct(private readonly TreeService $tree_service)
34
    {
35
        parent::__construct();
36
    }
37
38
    protected function configure(): void
39
    {
40
        $this
41
            ->setName(name: 'tree-create')
42
            ->setDescription(description: 'Create a new tree')
43
            ->addOption(name: 'name', shortcut: null, mode: InputOption::VALUE_REQUIRED, description: 'The name of the new tree')
44
            ->addOption(name: 'title', shortcut: null, mode: InputOption::VALUE_REQUIRED, description: 'The title of the new tree');
45
    }
46
47
    protected function execute(InputInterface $input, OutputInterface $output): int
48
    {
49
        $io = new SymfonyStyle(input: $input, output: $output);
50
51
        $name  = $this->stringOption(input: $input, name: 'name');
52
        $title = $this->stringOption(input: $input, name: 'title');
53
54
        $missing = false;
55
56
        if ($name === '') {
57
            $io->error(message: 'Missing required option: --name');
58
            $missing = true;
59
        }
60
61
        if ($title === '') {
62
            $io->error(message: 'Missing required option: --title');
63
            $missing = true;
64
        }
65
66
        if ($missing) {
67
            return Command::INVALID;
68
        }
69
70
        $tree = $this->tree_service->all()[$name] ?? null;
71
72
        if ($tree !== null) {
73
            $io->error(message: 'A tree with the name "' . $name . '" already exists.');
74
75
            return self::FAILURE;
76
        }
77
78
        $tree = $this->tree_service->create(name: $name, title: $title);
0 ignored issues
show
The assignment to $tree is dead and can be removed.
Loading history...
79
80
        DB::exec(sql: 'COMMIT');
81
82
        return self::SUCCESS;
83
    }
84
}
85