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

mimmi20 / browser-detector / 17807132384

17 Sep 2025 06:30PM UTC coverage: 96.087% (-0.09%) from 96.179%
17807132384

push

github

web-flow
Merge pull request #998 from mimmi20/dependabot/composer/master/development-dependencies-d3adbf4c82

composer(deps-dev): bump the development-dependencies group with 4 updates

7637 of 7948 relevant lines covered (96.09%)

11.87 hits per line

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

0.0
/src/Loader/InitData/Device.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
use UaResult\Bits\Bits;
18
use UaResult\Device\Architecture;
19

20
use function array_change_key_case;
21
use function array_key_exists;
22
use function is_array;
23
use function is_bool;
24
use function is_float;
25
use function is_int;
26
use function is_string;
27

28
use const CASE_LOWER;
29

30
/** @phpcs:disable SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion.RequiredConstructorPropertyPromotion */
31
final class Device
32
{
33
    private Architecture $architecture   = Architecture::unknown;
34
    private string | null $deviceName    = null;
35
    private string | null $marketingName = null;
36
    private string | null $manufacturer  = null;
37
    private string | null $brand         = null;
38
    private string | null $type          = null;
39
    private bool | null $dualOrientation = null;
40
    private int | null $simCount         = null;
41
    private string | null $platform      = null;
42
    private Bits $bits                   = Bits::unknown;
43

44
    /** @var array{width: int|null, height: int|null, touch: bool|null, size: float|null} */
45
    private array $display = ['width' => null, 'height' => null, 'touch' => null, 'size' => null];
46

47
    /**
48
     * @param array{width: int|null, height: int|null, touch: bool|null, size: float|null} $display
49
     *
50
     * @throws void
51
     */
52
    public function __construct(
×
53
        Architecture $architecture,
54
        string | null $deviceName,
55
        string | null $marketingName,
56
        string | null $manufacturer,
57
        string | null $brand,
58
        string | null $type,
59
        array $display,
60
        bool | null $dualOrientation,
61
        int | null $simCount,
62
        Bits $bits,
63
        string | null $platform,
64
    ) {
65
        $this->architecture    = $architecture;
×
66
        $this->deviceName      = $deviceName;
×
67
        $this->marketingName   = $marketingName;
×
68
        $this->manufacturer    = $manufacturer;
×
69
        $this->brand           = $brand;
×
70
        $this->type            = $type;
×
71
        $this->display         = $display;
×
72
        $this->dualOrientation = $dualOrientation;
×
73
        $this->simCount        = $simCount;
×
74
        $this->bits            = $bits;
×
75
        $this->platform        = $platform;
×
76
    }
77

78
    /**
79
     * @param stdClass $data
80
     * @phpstan-param array{deviceName: string|null, marketingName: string|null, manufacturer: string|null, brand: string|null, type: string|null, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}, dualOrientation: bool|null, simCount: int|null, platform: string|null} $data
81
     *
82
     * @throws void
83
     */
84
    public function __unserialize(array $data): void
×
85
    {
86
        $this->exchangeArray($data);
×
87
    }
88

89
    /**
90
     * @return array{architecture: Architecture, deviceName: string|null, marketingName: string|null, manufacturer: string|null, brand: string|null, type: string|null, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}, dualOrientation: bool|null, simCount: int|null, bits: Bits, platform: string|null}
91
     *
92
     * @throws void
93
     */
94
    public function __serialize(): array
×
95
    {
96
        return $this->getArrayCopy();
×
97
    }
98

99
    /** @throws void */
100
    public function getArchitecture(): Architecture
×
101
    {
102
        return $this->architecture;
×
103
    }
104

105
    /** @throws void */
106
    public function getDeviceName(): string | null
×
107
    {
108
        return $this->deviceName;
×
109
    }
110

111
    /** @throws void */
112
    public function getMarketingName(): string | null
×
113
    {
114
        return $this->marketingName;
×
115
    }
116

117
    /** @throws void */
118
    public function getManufacturer(): string | null
×
119
    {
120
        return $this->manufacturer;
×
121
    }
122

123
    /** @throws void */
124
    public function getBrand(): string | null
×
125
    {
126
        return $this->brand;
×
127
    }
128

129
    /** @throws void */
130
    public function getType(): string | null
×
131
    {
132
        return $this->type;
×
133
    }
134

135
    /**
136
     * @return array{width: int|null, height: int|null, touch: bool|null, size: float|null}
137
     *
138
     * @throws void
139
     */
140
    public function getDisplay(): array
×
141
    {
142
        return $this->display;
×
143
    }
144

145
    /** @throws void */
146
    public function getDualOrientation(): bool | null
×
147
    {
148
        return $this->dualOrientation;
×
149
    }
150

151
    /** @throws void */
152
    public function getSimCount(): int | null
×
153
    {
154
        return $this->simCount;
×
155
    }
156

157
    /** @throws void */
158
    public function getBits(): Bits
×
159
    {
160
        return $this->bits;
×
161
    }
162

163
    /** @throws void */
164
    public function getPlatform(): string | null
×
165
    {
166
        return $this->platform;
×
167
    }
168

169
    /**
170
     * @return array{architecture: Architecture, deviceName: string|null, marketingName: string|null, manufacturer: string|null, brand: string|null, type: string|null, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}, dualOrientation: bool|null, simCount: int|null, bits: Bits, platform: string|null}
171
     *
172
     * @throws void
173
     *
174
     * @api
175
     */
176
    public function getArrayCopy(): array
×
177
    {
178
        return [
×
179
            'architecture' => $this->architecture,
×
180
            'deviceName' => $this->deviceName,
×
181
            'marketingName' => $this->marketingName,
×
182
            'manufacturer' => $this->manufacturer,
×
183
            'brand' => $this->brand,
×
184
            'type' => $this->type,
×
185
            'display' => $this->display,
×
186
            'dualOrientation' => $this->dualOrientation,
×
187
            'simCount' => $this->simCount,
×
188
            'bits' => $this->bits,
×
189
            'platform' => $this->platform,
×
190
        ];
×
191
    }
192

193
    /**
194
     * @param stdClass $data
195
     * @phpstan-param array{deviceName: string|null, marketingName: string|null, manufacturer: string|null, brand: string|null, type: string|null, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}, dualOrientation: bool|null, simCount: int|null, platform: string|null} $data
196
     *
197
     * @throws void
198
     *
199
     * @api
200
     */
201
    public function exchangeArray(array $data): void
×
202
    {
203
        $data = array_change_key_case($data, CASE_LOWER);
×
204

205
        $deviceName = null;
×
206

207
        if (array_key_exists('devicename', $data) && is_string($data['devicename'])) {
×
208
            $deviceName = $data['devicename'];
×
209
        }
210

211
        $marketingName = null;
×
212

213
        if (array_key_exists('marketingname', $data) && is_string($data['marketingname'])) {
×
214
            $marketingName = $data['marketingname'];
×
215
        }
216

217
        $manufacturer = null;
×
218

219
        if (array_key_exists('manufacturer', $data) && is_string($data['manufacturer'])) {
×
220
            $manufacturer = $data['manufacturer'];
×
221
        }
222

223
        $brand = null;
×
224

225
        if (array_key_exists('brand', $data) && is_string($data['brand'])) {
×
226
            $brand = $data['brand'];
×
227
        }
228

229
        $type = null;
×
230

231
        if (array_key_exists('type', $data) && is_string($data['type'])) {
×
232
            $type = $data['type'];
×
233
        }
234

235
        $dualOrientation = null;
×
236

237
        if (array_key_exists('dualorientation', $data) && is_bool($data['dualorientation'])) {
×
238
            $dualOrientation = $data['dualorientation'];
×
239
        }
240

241
        $simCount = null;
×
242

243
        if (array_key_exists('simcount', $data) && is_int($data['simcount'])) {
×
244
            $simCount = $data['simcount'];
×
245
        }
246

247
        $platform = null;
×
248

249
        if (array_key_exists('platform', $data) && is_string($data['platform'])) {
×
250
            $platform = $data['platform'];
×
251
        }
252

253
        $display = ['width' => null, 'height' => null, 'touch' => null, 'size' => null];
×
254

255
        if (array_key_exists('display', $data) && is_array($data['display'])) {
×
256
            $displayData = array_change_key_case($data['display'], CASE_LOWER);
×
257

258
            if (array_key_exists('width', $displayData) && is_int($displayData['width'])) {
×
259
                $display['width'] = $displayData['width'];
×
260
            }
261

262
            if (array_key_exists('height', $displayData) && is_int($displayData['height'])) {
×
263
                $display['height'] = $displayData['height'];
×
264
            }
265

266
            if (array_key_exists('touch', $displayData) && is_bool($displayData['touch'])) {
×
267
                $display['touch'] = $displayData['touch'];
×
268
            }
269

270
            if (
271
                array_key_exists('size', $displayData)
×
272
                && (
273
                    is_int($displayData['size'])
×
274
                    || is_float($displayData['size'])
×
275
                )
276
            ) {
277
                $display['size'] = (float) $displayData['size'];
×
278
            }
279
        }
280

281
        $this->deviceName      = $deviceName;
×
282
        $this->marketingName   = $marketingName;
×
283
        $this->manufacturer    = $manufacturer;
×
284
        $this->brand           = $brand;
×
285
        $this->type            = $type;
×
286
        $this->display         = $display;
×
287
        $this->dualOrientation = $dualOrientation;
×
288
        $this->simCount        = $simCount;
×
289
        $this->platform        = $platform;
×
290
    }
291
}
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