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

eliashaeussler / typo3-warming / 15509771334

07 Jun 2025 04:43PM UTC coverage: 86.535% (-4.1%) from 90.617%
15509771334

Pull #871

github

eliashaeussler
[FEATURE] Collect url metadata during cache warmup
Pull Request #871: [FEATURE] Collect url metadata during cache warmup

104 of 188 new or added lines in 9 files covered. (55.32%)

1 existing line in 1 file now uncovered.

1446 of 1671 relevant lines covered (86.54%)

9.25 hits per line

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

73.68
/Classes/Http/Client/Handler/HandlerStackBuilder.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "warming".
7
 *
8
 * Copyright (C) 2021-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 2 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\Typo3Warming\Http\Client\Handler;
25

26
use GuzzleHttp\Client;
27
use GuzzleHttp\ClientInterface;
28
use GuzzleHttp\HandlerStack;
29
use GuzzleHttp\Promise;
30
use Psr\Http\Message;
31

32
/**
33
 * HandlerStackBuilder
34
 *
35
 * @author Elias Häußler <elias@haeussler.dev>
36
 * @license GPL-2.0-or-later
37
 * @internal
38
 */
39
final class HandlerStackBuilder
40
{
41
    /**
42
     * @param array<string, mixed> $options
43
     * @param (callable(Message\RequestInterface, array<string, mixed>): Promise\PromiseInterface)|null $handler
44
     */
45
    public function buildFromClientOrRequestOptions(
4✔
46
        ClientInterface $client,
47
        array $options,
48
        ?callable $handler = null,
49
    ): HandlerStack {
50
        $registeredHandler = null;
4✔
51

52
        // Resolve currently registered handler from request options (high priority) or client (low priority)
53
        if (is_callable($options['handler'] ?? null)) {
4✔
NEW
54
            $registeredHandler = $options['handler'];
×
55
        } elseif ($client instanceof Client) {
4✔
56
            $registeredHandler = $this->getHandlerFromClient($client);
4✔
57
        }
58

59
        // Early return with new handler stack and given handler, if no handler is currently registered
60
        if ($registeredHandler === null) {
4✔
NEW
61
            return HandlerStack::create($handler);
×
62
        }
63

64
        // Early return with new handler stack and given handler (high priority) or currently registered
65
        // handler (low priority), if currently registered handler is not a handler stack
66
        if (!($registeredHandler instanceof HandlerStack)) {
4✔
NEW
67
            return HandlerStack::create($handler ?? $registeredHandler);
×
68
        }
69

70
        // Overwrite handler for currently registered handler stack
71
        if ($handler !== null) {
4✔
NEW
72
            $registeredHandler->setHandler($handler);
×
73
        }
74

75
        return $registeredHandler;
4✔
76
    }
77

78
    private function getHandlerFromClient(Client $client): ?callable
4✔
79
    {
80
        $clientReflection = new \ReflectionObject($client);
4✔
81
        $clientConfig = $clientReflection->getProperty('config')->getValue($client);
4✔
82

83
        if (is_callable($clientConfig['handler'] ?? null)) {
4✔
84
            return $clientConfig['handler'];
4✔
85
        }
86

NEW
87
        return null;
×
88
    }
89
}
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