• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / composer-update-check / 15182034191

22 May 2025 03:06AM UTC coverage: 20.538%. First build
15182034191

Pull #130

github

web-flow
[TASK] Update all dependencies
Pull Request #130: [!!!][FEATURE] Modernize plugin

356 of 1832 new or added lines in 57 files covered. (19.43%)

382 of 1860 relevant lines covered (20.54%)

1.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Configuration/Adapter/CommandInputConfigAdapter.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/composer-update-check".
7
 *
8
 * Copyright (C) 2020-2025 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\ComposerUpdateCheck\Configuration\Adapter;
25

26
use EliasHaeussler\ComposerUpdateCheck\Configuration;
27
use EliasHaeussler\ComposerUpdateCheck\Exception;
28
use JsonException;
29
use Symfony\Component\Console;
30

31
use function explode;
32
use function is_array;
33
use function is_string;
34
use function json_decode;
35
use function trim;
36

37
/**
38
 * CommandInputConfigAdapter.
39
 *
40
 * @author Elias Häußler <elias@haeussler.dev>
41
 * @license GPL-3.0-or-later
42
 */
43
final class CommandInputConfigAdapter implements ConfigAdapter
44
{
NEW
45
    public function __construct(
×
46
        private readonly Console\Input\InputInterface $input,
NEW
47
    ) {}
×
48

49
    /**
50
     * @throws Exception\ReporterOptionsAreInvalid
51
     */
NEW
52
    public function resolve(): Configuration\ComposerUpdateCheckConfig
×
53
    {
NEW
54
        $config = new Configuration\ComposerUpdateCheckConfig();
×
55

NEW
56
        if ($this->input->hasOption('exclude-packages')) {
×
57
            /** @var array<string> $excludePatterns */
NEW
58
            $excludePatterns = $this->input->getOption('exclude-packages');
×
59

NEW
60
            foreach ($excludePatterns as $pattern) {
×
NEW
61
                $excludePattern = Configuration\Options\PackageExcludePattern::create($pattern);
×
NEW
62
                $config->excludePackageByPattern($excludePattern);
×
63
            }
64
        }
65

NEW
66
        if ($this->input->hasOption('no-dev') && true === $this->input->getOption('no-dev')) {
×
NEW
67
            $config->excludeDevPackages();
×
68
        }
69

NEW
70
        if ($this->input->hasOption('security-scan') && true === $this->input->getOption('security-scan')) {
×
NEW
71
            $config->performSecurityScan();
×
72
        }
73

NEW
74
        if ($this->input->hasOption('format') && is_string($this->input->getOption('format'))) {
×
NEW
75
            $config->setFormat($this->input->getOption('format'));
×
76
        }
77

NEW
78
        if ($this->input->hasOption('reporter') && is_array($this->input->getOption('reporter'))) {
×
79
            /* @phpstan-ignore argument.type */
NEW
80
            $this->enableReporters($config, $this->input->getOption('reporter'));
×
81
        }
82

NEW
83
        if ($this->input->hasOption('disable-reporter') && is_array($this->input->getOption('disable-reporter'))) {
×
NEW
84
            foreach ($this->input->getOption('disable-reporter') as $name) {
×
85
                /* @phpstan-ignore argument.type */
NEW
86
                $config->disableReporter($name);
×
87
            }
88
        }
89

NEW
90
        return $config;
×
91
    }
92

93
    /**
94
     * @param array<string> $reporters
95
     *
96
     * @throws Exception\ReporterOptionsAreInvalid
97
     */
NEW
98
    private function enableReporters(Configuration\ComposerUpdateCheckConfig $config, array $reporters): void
×
99
    {
NEW
100
        foreach ($reporters as $reporterConfig) {
×
NEW
101
            $configParts = explode(':', $reporterConfig, 2);
×
NEW
102
            $name = $configParts[0];
×
NEW
103
            $options = $configParts[1] ?? [];
×
104

NEW
105
            if (is_string($options)) {
×
NEW
106
                $options = $this->parseReporterOptions($name, trim($options));
×
107
            } else {
NEW
108
                $options = [];
×
109
            }
110

NEW
111
            $config->enableReporter($name, $options);
×
112
        }
113
    }
114

115
    /**
116
     * @return array<string, mixed>
117
     *
118
     * @throws Exception\ReporterOptionsAreInvalid
119
     */
NEW
120
    private function parseReporterOptions(string $name, string $json): array
×
121
    {
122
        try {
NEW
123
            $options = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
×
124

NEW
125
            if (!is_array($options)) {
×
NEW
126
                throw new Exception\ReporterOptionsAreInvalid($name);
×
127
            }
128

129
            /* @phpstan-ignore return.type */
NEW
130
            return $options;
×
NEW
131
        } catch (JsonException) {
×
NEW
132
            throw new Exception\ReporterOptionsAreInvalid($name);
×
133
        }
134
    }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc