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

eliashaeussler / composer-update-check / 15127653356

19 May 2025 08:30PM UTC coverage: 20.538%. First build
15127653356

Pull #130

github

web-flow
[TASK] Update cuyz/valinor to v1.16.1

| datasource | package      | from   | to     |
| ---------- | ------------ | ------ | ------ |
| packagist  | cuyz/valinor | 1.15.0 | 1.16.1 |
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/EnvironmentVariablesConfigAdapter.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 Generator;
28

29
use function array_filter;
30
use function explode;
31
use function getenv;
32
use function preg_match;
33
use function sprintf;
34
use function str_starts_with;
35
use function trim;
36

37
/**
38
 * EnvironmentVariablesConfigAdapter.
39
 *
40
 * @author Elias Häußler <elias@haeussler.dev>
41
 * @license GPL-3.0-or-later
42
 */
43
final class EnvironmentVariablesConfigAdapter implements ConfigAdapter
44
{
45
    private const ENV_VAR_PREFIX = 'COMPOSER_UPDATE_CHECK_';
46

NEW
47
    public function resolve(): Configuration\ComposerUpdateCheckConfig
×
48
    {
NEW
49
        $config = new Configuration\ComposerUpdateCheckConfig();
×
50

51
        // Exclude patterns
NEW
52
        $excludePatterns = $this->getEnv('EXCLUDE_PATTERNS', true);
×
NEW
53
        foreach ($excludePatterns as $excludePattern) {
×
NEW
54
            $config->excludePackageByPattern(Configuration\Options\PackageExcludePattern::create($excludePattern));
×
55
        }
56

57
        // Include dev packages
NEW
58
        $noDev = $this->getEnv('NO_DEV');
×
NEW
59
        if ($this->isTrue($noDev)) {
×
NEW
60
            $config->excludeDevPackages();
×
61
        }
62

63
        // Perform security scan
NEW
64
        $securityScan = $this->getEnv('SECURITY_SCAN');
×
NEW
65
        if ($this->isTrue($securityScan)) {
×
NEW
66
            $config->performSecurityScan();
×
67
        }
68

69
        // Format
NEW
70
        $format = $this->getEnv('FORMAT');
×
NEW
71
        if (null !== $format) {
×
NEW
72
            $config->setFormat($format);
×
73
        }
74

75
        // Reporters
NEW
76
        foreach ($this->getReporterEnvVariables() as $name => $reporterConfig) {
×
NEW
77
            if ($reporterConfig['enable']) {
×
NEW
78
                $config->enableReporter($name, $reporterConfig['options'] ?? []);
×
79
            } else {
NEW
80
                $config->disableReporter($name);
×
81
            }
82
        }
83

NEW
84
        return $config;
×
85
    }
86

87
    /**
88
     * @phpstan-return ($list is true ? array<string> : string|null)
89
     */
NEW
90
    private function getEnv(string $name, bool $list = false): string|array|null
×
91
    {
NEW
92
        $value = getenv(self::ENV_VAR_PREFIX.$name);
×
93

NEW
94
        if (false === $value || '' === trim($value)) {
×
NEW
95
            return $list ? [] : null;
×
96
        }
97

NEW
98
        if (!$list) {
×
NEW
99
            return $value;
×
100
        }
101

NEW
102
        return explode(',', $value);
×
103
    }
104

105
    /**
106
     * @return Generator<string, array{enable: bool, options?: array<string, mixed>}>
107
     */
NEW
108
    private function getReporterEnvVariables(): Generator
×
109
    {
NEW
110
        $reporterConfig = [];
×
NEW
111
        $envVarPrefix = self::ENV_VAR_PREFIX.'REPORTER_';
×
NEW
112
        $envVarPattern = sprintf('/^%s(?P<name>[^_]+)_(?P<option>.+)$/', $envVarPrefix);
×
113

114
        // Fetch all relevant environment variables
NEW
115
        $envVariables = array_filter(
×
NEW
116
            getenv(),
×
NEW
117
            static fn (string $name) => str_starts_with($name, $envVarPrefix),
×
NEW
118
            ARRAY_FILTER_USE_KEY,
×
NEW
119
        );
×
120

121
        // Resolve reporter config from environment variables
NEW
122
        foreach ($envVariables as $name => $value) {
×
NEW
123
            if (1 !== preg_match($envVarPattern, $name, $matches)) {
×
NEW
124
                continue;
×
125
            }
126

NEW
127
            $reporterName = $matches['name'];
×
NEW
128
            $reporterOption = $matches['option'];
×
129

NEW
130
            $reporterConfig[$reporterName][$reporterOption] ??= $value;
×
131
        }
132

133
        // Yield reporter config
NEW
134
        foreach ($reporterConfig as $name => $config) {
×
NEW
135
            $enabled = $this->isTrue($config['enable'] ?? '1');
×
136

NEW
137
            unset($config['enable']);
×
138

NEW
139
            if ($enabled) {
×
NEW
140
                yield $name => [
×
NEW
141
                    'enable' => true,
×
NEW
142
                    'options' => $config,
×
NEW
143
                ];
×
144
            } else {
NEW
145
                yield $name => [
×
NEW
146
                    'enable' => false,
×
NEW
147
                ];
×
148
            }
149
        }
150
    }
151

NEW
152
    private function isTrue(?string $value): bool
×
153
    {
NEW
154
        if (null === $value) {
×
NEW
155
            return false;
×
156
        }
157

NEW
158
        $value = trim($value);
×
159

NEW
160
        if ('true' === $value || 'yes' === $value) {
×
NEW
161
            return true;
×
162
        }
163

NEW
164
        if ('false' === $value || 'no' === $value) {
×
NEW
165
            return false;
×
166
        }
167

NEW
168
        return (bool) $value;
×
169
    }
170
}
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