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

eliashaeussler / cache-warmup / 8473145765

28 Mar 2024 08:13PM UTC coverage: 93.917%. Remained the same
8473145765

push

github

web-flow
[TASK] Update PHPStan packages

| datasource | package                       | from   | to     |
| ---------- | ----------------------------- | ------ | ------ |
| packagist  | eliashaeussler/phpstan-config | 2.4.0  | 2.5.0  |
| packagist  | phpstan/phpstan-phpunit       | 1.3.15 | 1.3.16 |
| packagist  | phpstan/phpstan-symfony       | 1.3.7  | 1.3.9  |

1405 of 1496 relevant lines covered (93.92%)

9.15 hits per line

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

95.0
/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
     * @param callable(string): bool $matchFunction
49
     */
50
    private function __construct(callable $matchFunction)
6✔
51
    {
52
        $this->matchFunction = $matchFunction;
6✔
53
    }
54

55
    /**
56
     * @throws Exception\RegularExpressionIsInvalid
57
     */
58
    public static function create(string $pattern): self
6✔
59
    {
60
        if (str_starts_with($pattern, '#') && str_ends_with($pattern, '#')) {
6✔
61
            return self::createFromRegularExpression($pattern);
×
62
        }
63

64
        return self::createFromPattern($pattern);
6✔
65
    }
66

67
    public static function createFromPattern(string $pattern): self
6✔
68
    {
69
        return new self(
6✔
70
            static fn (string $url) => fnmatch($pattern, $url),
6✔
71
        );
6✔
72
    }
73

74
    /**
75
     * @throws Exception\RegularExpressionIsInvalid
76
     */
77
    public static function createFromRegularExpression(string $regex): self
3✔
78
    {
79
        if (!str_starts_with($regex, '#') || !str_ends_with($regex, '#')) {
3✔
80
            throw new Exception\RegularExpressionIsInvalid($regex);
1✔
81
        }
82

83
        if (false === @preg_match($regex, '')) {
2✔
84
            throw new Exception\RegularExpressionIsInvalid($regex);
1✔
85
        }
86

87
        return new self(
1✔
88
            static fn (string $url) => 1 === preg_match($regex, $url),
1✔
89
        );
1✔
90
    }
91

92
    public function matches(string|Stringable $url): bool
4✔
93
    {
94
        return ($this->matchFunction)((string) $url);
4✔
95
    }
96
}
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