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

eliashaeussler / composer-update-check / 11496630734

24 Oct 2024 09:35AM UTC coverage: 20.327%. Remained the same
11496630734

Pull #157

github

web-flow
Merge 204d43876 into ef041e694
Pull Request #157: [TASK] Update peaceiris/actions-gh-pages action to v4

373 of 1835 relevant lines covered (20.33%)

1.09 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-2024 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
{
45
    public function __construct(
×
46
        private readonly Console\Input\InputInterface $input,
47
    ) {}
×
48

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

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

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

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

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

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

78
        if ($this->input->hasOption('reporter') && is_array($this->input->getOption('reporter'))) {
×
79
            $this->enableReporters($config, $this->input->getOption('reporter'));
×
80
        }
81

82
        if ($this->input->hasOption('disable-reporter') && is_array($this->input->getOption('disable-reporter'))) {
×
83
            foreach ($this->input->getOption('disable-reporter') as $name) {
×
84
                $config->disableReporter($name);
×
85
            }
86
        }
87

88
        return $config;
×
89
    }
90

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

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

109
            $config->enableReporter($name, $options);
×
110
        }
111
    }
112

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

123
            if (!is_array($options)) {
×
124
                throw new Exception\ReporterOptionsAreInvalid($name);
×
125
            }
126

127
            return $options;
×
128
        } catch (JsonException) {
×
129
            throw new Exception\ReporterOptionsAreInvalid($name);
×
130
        }
131
    }
132
}
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