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

acdh-oeaw / arche-diss-cache / #57

24 Oct 2024 10:11PM UTC coverage: 80.841%. Remained the same
#57

push

php-coveralls

zozlak
Service::setCallback() introduced

6 of 6 new or added lines in 1 file covered. (100.0%)

173 of 214 relevant lines covered (80.84%)

3.22 hits per line

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

66.67
/src/acdhOeaw/arche/lib/dissCache/ResponseCacheItem.php
1
<?php
2

3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2024 zozlak.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26

27
namespace acdhOeaw\arche\lib\dissCache;
28

29
/**
30
 * Description of ResponseCacheItem
31
 *
32
 * @author zozlak
33
 */
34
class ResponseCacheItem {
35

36
    static public function deserialize(string $data): self {
37
        $data            = json_decode($data);
2✔
38
        $d               = new ResponseCacheItem();
2✔
39
        $d->body         = $data->body;
2✔
40
        $d->responseCode = $data->responseCode;
2✔
41
        $d->headers      = (array) $data->headers;
2✔
42
        $d->hit          = true;
2✔
43
        return $d;
2✔
44
    }
45

46
    public string $body;
47
    public int $responseCode;
48

49
    /**
50
     * 
51
     * @var array<string, string|array<string>>
52
     */
53
    public array $headers;
54
    public bool $hit;
55

56
    /**
57
     * 
58
     * @param array<string, string|array<string>> $headers
59
     */
60
    public function __construct(string $body = '', int $responseCode = 0,
61
                                array $headers = [], bool $hit = false) {
62
        $this->body         = $body;
5✔
63
        $this->responseCode = $responseCode;
5✔
64
        $this->headers      = $headers;
5✔
65
        $this->hit          = $hit;
5✔
66
    }
67

68
    public function serialize(): string {
69
        return (string) json_encode($this, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
5✔
70
    }
71

72
    public function send(): void {
73
        http_response_code($this->responseCode);
×
74
        foreach ($this->headers as $header => $values) {
×
75
            $values = is_array($values) ? $values : [$values];
×
76
            foreach ($values as $i) {
×
77
                header("$header: $i");
×
78
            }
79
        }
80
        echo $this->body;
×
81
    }
82
}
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