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

mimmi20 / browser-detector / 12945342151

22 Jan 2025 07:24PM UTC coverage: 89.212% (-10.8%) from 100.0%
12945342151

push

github

web-flow
Merge pull request #872 from mimmi20/updates

rewrite Headers

2983 of 3466 new or added lines in 72 files covered. (86.06%)

9 existing lines in 2 files now uncovered.

4234 of 4746 relevant lines covered (89.21%)

11.89 hits per line

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

0.0
/src/Loader/InitData/Client.php
1
<?php
2

3
/**
4
 * This file is part of the browser-detector package.
5
 *
6
 * Copyright (c) 2012-2025, Thomas Mueller <mimmi20@live.de>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types = 1);
13

14
namespace BrowserDetector\Loader\InitData;
15

16
use stdClass;
17

18
use function array_change_key_case;
19
use function array_key_exists;
20
use function is_array;
21
use function is_string;
22

23
use const CASE_LOWER;
24

25
/** @phpcs:disable SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion.RequiredConstructorPropertyPromotion */
26
final class Client
27
{
28
    private string | null $name               = null;
29
    private string | null $manufacturer       = null;
30
    private string | stdClass | null $version = null;
31
    private string | null $type               = null;
32
    private string | null $engine             = null;
33

34
    /** @throws void */
NEW
35
    public function __construct(
×
36
        string | null $name,
37
        string | null $manufacturer,
38
        string | stdClass | null $version,
39
        string | null $type,
40
        string | null $engine,
41
    ) {
NEW
42
        $this->name         = $name;
×
NEW
43
        $this->manufacturer = $manufacturer;
×
NEW
44
        $this->version      = $version;
×
NEW
45
        $this->type         = $type;
×
NEW
46
        $this->engine       = $engine;
×
47
    }
48

49
    /**
50
     * @param array<string, array<mixed|string>|stdClass|string|null> $data
51
     * @phpstan-param array{name: string|null, manufacturer: string|null, version: string|array<string|mixed>|stdClass|null, type: string|null, engine: string|null} $data
52
     *
53
     * @throws void
54
     */
NEW
55
    public function __unserialize(array $data): void
×
56
    {
NEW
57
        $this->exchangeArray($data);
×
58
    }
59

60
    /**
61
     * @return array{name: string|null, manufacturer: string|null, version: stdClass|string|null, type: string|null, engine: string|null}
62
     *
63
     * @throws void
64
     */
NEW
65
    public function __serialize(): array
×
66
    {
NEW
67
        return $this->getArrayCopy();
×
68
    }
69

70
    /** @throws void */
NEW
71
    public function getName(): string | null
×
72
    {
NEW
73
        return $this->name;
×
74
    }
75

76
    /** @throws void */
NEW
77
    public function getManufacturer(): string | null
×
78
    {
NEW
79
        return $this->manufacturer;
×
80
    }
81

82
    /** @throws void */
NEW
83
    public function getVersion(): string | stdClass | null
×
84
    {
NEW
85
        return $this->version;
×
86
    }
87

88
    /** @throws void */
NEW
89
    public function getType(): string | null
×
90
    {
NEW
91
        return $this->type;
×
92
    }
93

94
    /** @throws void */
NEW
95
    public function getEngine(): string | null
×
96
    {
NEW
97
        return $this->engine;
×
98
    }
99

100
    /**
101
     * @return array{name: string|null, manufacturer: string|null, version: stdClass|string|null, type: string|null, engine: string|null}
102
     *
103
     * @throws void
104
     *
105
     * @api
106
     */
NEW
107
    public function getArrayCopy(): array
×
108
    {
NEW
109
        return [
×
NEW
110
            'name' => $this->name,
×
NEW
111
            'manufacturer' => $this->manufacturer,
×
NEW
112
            'version' => $this->version,
×
NEW
113
            'type' => $this->type,
×
NEW
114
            'engine' => $this->engine,
×
NEW
115
        ];
×
116
    }
117

118
    /**
119
     * @param array<string, array<mixed|string>|stdClass|string|null> $data
120
     * @phpstan-param array{name: string|null, manufacturer: string|null, version: string|array<string|mixed>|stdClass|null, type: string|null, engine: string|null} $data
121
     *
122
     * @throws void
123
     *
124
     * @api
125
     */
NEW
126
    public function exchangeArray(array $data): void
×
127
    {
NEW
128
        $data = array_change_key_case($data, CASE_LOWER);
×
129

NEW
130
        $name = null;
×
131

NEW
132
        if (array_key_exists('name', $data) && is_string($data['name'])) {
×
NEW
133
            $name = $data['name'];
×
134
        }
135

NEW
136
        $manufacturer = null;
×
137

NEW
138
        if (array_key_exists('manufacturer', $data) && is_string($data['manufacturer'])) {
×
NEW
139
            $manufacturer = $data['manufacturer'];
×
140
        }
141

NEW
142
        $type = null;
×
143

NEW
144
        if (array_key_exists('type', $data) && is_string($data['type'])) {
×
NEW
145
            $type = $data['type'];
×
146
        }
147

NEW
148
        $engine = null;
×
149

NEW
150
        if (array_key_exists('engine', $data) && is_string($data['engine'])) {
×
NEW
151
            $engine = $data['engine'];
×
152
        }
153

NEW
154
        $version = null;
×
155

NEW
156
        if (array_key_exists('version', $data)) {
×
NEW
157
            if (is_string($data['version']) || $data['version'] instanceof stdClass) {
×
NEW
158
                $version = $data['version'];
×
NEW
159
            } elseif (is_array($data['version'])) {
×
NEW
160
                $version = (object) $data['version'];
×
161
            }
162
        }
163

NEW
164
        $this->name         = $name;
×
NEW
165
        $this->manufacturer = $manufacturer;
×
NEW
166
        $this->version      = $version;
×
NEW
167
        $this->type         = $type;
×
NEW
168
        $this->engine       = $engine;
×
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

© 2026 Coveralls, Inc