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

mimmi20 / browser-detector / 12915563542

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

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/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

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

26
use const CASE_LOWER;
27

28
/** @phpcs:disable SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion.RequiredConstructorPropertyPromotion */
29
final class Device
30
{
31
    private string | null $deviceName    = null;
32
    private string | null $marketingName = null;
33
    private string | null $manufacturer  = null;
34
    private string | null $brand         = null;
35
    private string | null $type          = null;
36
    private bool | null $dualOrientation = null;
37
    private int | null $simCount         = null;
38
    private string | null $platform      = null;
39

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

43
    /**
44
     * @param array{width: int|null, height: int|null, touch: bool|null, size: float|null} $display
45
     *
46
     * @throws void
47
     */
NEW
48
    public function __construct(
×
49
        string | null $deviceName,
50
        string | null $marketingName,
51
        string | null $manufacturer,
52
        string | null $brand,
53
        string | null $type,
54
        array $display,
55
        bool | null $dualOrientation,
56
        int | null $simCount,
57
        string | null $platform,
58
    ) {
NEW
59
        $this->deviceName      = $deviceName;
×
NEW
60
        $this->marketingName   = $marketingName;
×
NEW
61
        $this->manufacturer    = $manufacturer;
×
NEW
62
        $this->brand           = $brand;
×
NEW
63
        $this->type            = $type;
×
NEW
64
        $this->display         = $display;
×
NEW
65
        $this->dualOrientation = $dualOrientation;
×
NEW
66
        $this->simCount        = $simCount;
×
NEW
67
        $this->platform        = $platform;
×
68
    }
69

70
    /**
71
     * @param stdClass $data
72
     * @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
73
     *
74
     * @throws void
75
     */
NEW
76
    public function __unserialize(array $data): void
×
77
    {
NEW
78
        $this->exchangeArray($data);
×
79
    }
80

81
    /**
82
     * @return 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}
83
     *
84
     * @throws void
85
     */
NEW
86
    public function __serialize(): array
×
87
    {
NEW
88
        return $this->getArrayCopy();
×
89
    }
90

91
    /** @throws void */
NEW
92
    public function getDeviceName(): string | null
×
93
    {
NEW
94
        return $this->deviceName;
×
95
    }
96

97
    /** @throws void */
NEW
98
    public function getMarketingName(): string | null
×
99
    {
NEW
100
        return $this->marketingName;
×
101
    }
102

103
    /** @throws void */
NEW
104
    public function getManufacturer(): string | null
×
105
    {
NEW
106
        return $this->manufacturer;
×
107
    }
108

109
    /** @throws void */
NEW
110
    public function getBrand(): string | null
×
111
    {
NEW
112
        return $this->brand;
×
113
    }
114

115
    /** @throws void */
NEW
116
    public function getType(): string | null
×
117
    {
NEW
118
        return $this->type;
×
119
    }
120

121
    /**
122
     * @return array{width: int|null, height: int|null, touch: bool|null, size: float|null}
123
     *
124
     * @throws void
125
     */
NEW
126
    public function getDisplay(): array
×
127
    {
NEW
128
        return $this->display;
×
129
    }
130

131
    /** @throws void */
NEW
132
    public function getDualOrientation(): bool | null
×
133
    {
NEW
134
        return $this->dualOrientation;
×
135
    }
136

137
    /** @throws void */
NEW
138
    public function getSimCount(): int | null
×
139
    {
NEW
140
        return $this->simCount;
×
141
    }
142

143
    /** @throws void */
NEW
144
    public function getPlatform(): string | null
×
145
    {
NEW
146
        return $this->platform;
×
147
    }
148

149
    /**
150
     * @return 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}
151
     *
152
     * @throws void
153
     *
154
     * @api
155
     */
NEW
156
    public function getArrayCopy(): array
×
157
    {
NEW
158
        return [
×
NEW
159
            'deviceName' => $this->deviceName,
×
NEW
160
            'marketingName' => $this->marketingName,
×
NEW
161
            'manufacturer' => $this->manufacturer,
×
NEW
162
            'brand' => $this->brand,
×
NEW
163
            'type' => $this->type,
×
NEW
164
            'display' => $this->display,
×
NEW
165
            'dualOrientation' => $this->dualOrientation,
×
NEW
166
            'simCount' => $this->simCount,
×
NEW
167
            'platform' => $this->platform,
×
NEW
168
        ];
×
169
    }
170

171
    /**
172
     * @param stdClass $data
173
     * @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
174
     *
175
     * @throws void
176
     *
177
     * @api
178
     */
NEW
179
    public function exchangeArray(array $data): void
×
180
    {
NEW
181
        $data = array_change_key_case($data, CASE_LOWER);
×
182

NEW
183
        $deviceName = null;
×
184

NEW
185
        if (array_key_exists('devicename', $data) && is_string($data['devicename'])) {
×
NEW
186
            $deviceName = $data['devicename'];
×
187
        }
188

NEW
189
        $marketingName = null;
×
190

NEW
191
        if (array_key_exists('marketingname', $data) && is_string($data['marketingname'])) {
×
NEW
192
            $marketingName = $data['marketingname'];
×
193
        }
194

NEW
195
        $manufacturer = null;
×
196

NEW
197
        if (array_key_exists('manufacturer', $data) && is_string($data['manufacturer'])) {
×
NEW
198
            $manufacturer = $data['manufacturer'];
×
199
        }
200

NEW
201
        $brand = null;
×
202

NEW
203
        if (array_key_exists('brand', $data) && is_string($data['brand'])) {
×
NEW
204
            $brand = $data['brand'];
×
205
        }
206

NEW
207
        $type = null;
×
208

NEW
209
        if (array_key_exists('type', $data) && is_string($data['type'])) {
×
NEW
210
            $type = $data['type'];
×
211
        }
212

NEW
213
        $dualOrientation = null;
×
214

NEW
215
        if (array_key_exists('dualorientation', $data) && is_bool($data['dualorientation'])) {
×
NEW
216
            $dualOrientation = $data['dualorientation'];
×
217
        }
218

NEW
219
        $simCount = null;
×
220

NEW
221
        if (array_key_exists('simcount', $data) && is_int($data['simcount'])) {
×
NEW
222
            $simCount = $data['simcount'];
×
223
        }
224

NEW
225
        $platform = null;
×
226

NEW
227
        if (array_key_exists('platform', $data) && is_string($data['platform'])) {
×
NEW
228
            $platform = $data['platform'];
×
229
        }
230

NEW
231
        $display = ['width' => null, 'height' => null, 'touch' => null, 'size' => null];
×
232

NEW
233
        if (array_key_exists('display', $data) && is_array($data['display'])) {
×
NEW
234
            $displayData = array_change_key_case($data['display'], CASE_LOWER);
×
235

NEW
236
            if (array_key_exists('width', $displayData) && is_int($displayData['width'])) {
×
NEW
237
                $display['width'] = $displayData['width'];
×
238
            }
239

NEW
240
            if (array_key_exists('height', $displayData) && is_int($displayData['height'])) {
×
NEW
241
                $display['height'] = $displayData['height'];
×
242
            }
243

NEW
244
            if (array_key_exists('touch', $displayData) && is_bool($displayData['touch'])) {
×
NEW
245
                $display['touch'] = $displayData['touch'];
×
246
            }
247

248
            if (
NEW
249
                array_key_exists('size', $displayData)
×
250
                && (
NEW
251
                    is_int($displayData['size'])
×
NEW
252
                    || is_float($displayData['size'])
×
253
                )
254
            ) {
NEW
255
                $display['size'] = (float) $displayData['size'];
×
256
            }
257
        }
258

NEW
259
        $this->deviceName      = $deviceName;
×
NEW
260
        $this->marketingName   = $marketingName;
×
NEW
261
        $this->manufacturer    = $manufacturer;
×
NEW
262
        $this->brand           = $brand;
×
NEW
263
        $this->type            = $type;
×
NEW
264
        $this->display         = $display;
×
NEW
265
        $this->dualOrientation = $dualOrientation;
×
NEW
266
        $this->simCount        = $simCount;
×
NEW
267
        $this->platform        = $platform;
×
268
    }
269
}
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