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

eliashaeussler / cache-warmup / 10495565513

21 Aug 2024 06:38PM UTC coverage: 94.463%. Remained the same
10495565513

Pull #389

github

web-flow
[TASK] Update paambaati/codeclimate-action action to v9

| datasource  | package                      | from   | to     |
| ----------- | ---------------------------- | ------ | ------ |
| github-tags | paambaati/codeclimate-action | v8.0.0 | v9.0.0 |
Pull Request #389: [TASK] Update paambaati/codeclimate-action action to v9

1433 of 1517 relevant lines covered (94.46%)

9.11 hits per line

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

95.45
/src/Config/Option/ExcludePattern.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/cache-warmup".
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\CacheWarmup\Config\Option;
25

26
use EliasHaeussler\CacheWarmup\Exception;
27
use Stringable;
28

29
use function fnmatch;
30
use function preg_match;
31
use function str_ends_with;
32
use function str_starts_with;
33

34
/**
35
 * ExcludePattern.
36
 *
37
 * @author Elias Häußler <elias@haeussler.dev>
38
 * @license GPL-3.0-or-later
39
 */
40
final class ExcludePattern
41
{
42
    /**
43
     * @var callable(string): bool
44
     */
45
    private $matchFunction;
46

47
    /**
48
     * @pure
49
     *
50
     * @param callable(string): bool $matchFunction
51
     */
52
    private function __construct(callable $matchFunction)
6✔
53
    {
54
        $this->matchFunction = $matchFunction;
6✔
55
    }
56

57
    /**
58
     * @pure
59
     *
60
     * @throws Exception\RegularExpressionIsInvalid
61
     */
62
    public static function create(string $pattern): self
6✔
63
    {
64
        if (self::isRegularExpression($pattern)) {
6✔
65
            return self::createFromRegularExpression($pattern);
×
66
        }
67

68
        return self::createFromPattern($pattern);
6✔
69
    }
70

71
    /**
72
     * @pure
73
     */
74
    public static function createFromPattern(string $pattern): self
6✔
75
    {
76
        return new self(
6✔
77
            static fn (string $url) => fnmatch($pattern, $url),
6✔
78
        );
6✔
79
    }
80

81
    /**
82
     * @pure
83
     *
84
     * @throws Exception\RegularExpressionIsInvalid
85
     */
86
    public static function createFromRegularExpression(string $regex): self
3✔
87
    {
88
        if (!self::isRegularExpression($regex)) {
3✔
89
            throw new Exception\RegularExpressionIsInvalid($regex);
1✔
90
        }
91

92
        /* @phpstan-ignore possiblyImpure.functionCall */
93
        if (false === @preg_match($regex, '')) {
2✔
94
            throw new Exception\RegularExpressionIsInvalid($regex);
1✔
95
        }
96

97
        return new self(
1✔
98
            static fn (string $url) => 1 === preg_match($regex, $url),
1✔
99
        );
1✔
100
    }
101

102
    public function matches(string|Stringable $url): bool
4✔
103
    {
104
        return ($this->matchFunction)((string) $url);
4✔
105
    }
106

107
    /**
108
     * @pure
109
     */
110
    private static function isRegularExpression(string $pattern): bool
6✔
111
    {
112
        return str_starts_with($pattern, '#') && str_ends_with($pattern, '#');
6✔
113
    }
114
}
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