• 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/Engine.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 Engine
27
{
28
    private string | null $name               = null;
29
    private string | null $manufacturer       = null;
30
    private string | stdClass | null $version = null;
31

32
    /** @throws void */
NEW
33
    public function __construct(string | null $name, string | null $manufacturer, string | stdClass | null $version)
×
34
    {
NEW
35
        $this->name         = $name;
×
NEW
36
        $this->manufacturer = $manufacturer;
×
NEW
37
        $this->version      = $version;
×
38
    }
39

40
    /**
41
     * @param stdClass $data
42
     * @phpstan-param array{name: string|null, manufacturer: string|null, version: string|array<string|mixed>|stdClass|null} $data
43
     *
44
     * @throws void
45
     */
NEW
46
    public function __unserialize(array $data): void
×
47
    {
NEW
48
        $this->exchangeArray($data);
×
49
    }
50

51
    /**
52
     * @return array{name: string|null, manufacturer: string|null, version: stdClass|string|null}
53
     *
54
     * @throws void
55
     */
NEW
56
    public function __serialize(): array
×
57
    {
NEW
58
        return $this->getArrayCopy();
×
59
    }
60

61
    /** @throws void */
NEW
62
    public function getName(): string | null
×
63
    {
NEW
64
        return $this->name;
×
65
    }
66

67
    /** @throws void */
NEW
68
    public function getManufacturer(): string | null
×
69
    {
NEW
70
        return $this->manufacturer;
×
71
    }
72

73
    /** @throws void */
NEW
74
    public function getVersion(): string | stdClass | null
×
75
    {
NEW
76
        return $this->version;
×
77
    }
78

79
    /**
80
     * @return array{name: string|null, manufacturer: string|null, version: stdClass|string|null}
81
     *
82
     * @throws void
83
     *
84
     * @api
85
     */
NEW
86
    public function getArrayCopy(): array
×
87
    {
NEW
88
        return [
×
NEW
89
            'name' => $this->name,
×
NEW
90
            'manufacturer' => $this->manufacturer,
×
NEW
91
            'version' => $this->version,
×
NEW
92
        ];
×
93
    }
94

95
    /**
96
     * @param stdClass $data
97
     * @phpstan-param array{name: string|null, manufacturer: string|null, version: string|array<string|mixed>|stdClass|null} $data
98
     *
99
     * @throws void
100
     *
101
     * @api
102
     */
NEW
103
    public function exchangeArray(array $data): void
×
104
    {
NEW
105
        $data = array_change_key_case($data, CASE_LOWER);
×
106

NEW
107
        $name = null;
×
108

NEW
109
        if (array_key_exists('name', $data) && is_string($data['name'])) {
×
NEW
110
            $name = $data['name'];
×
111
        }
112

NEW
113
        $manufacturer = null;
×
114

NEW
115
        if (array_key_exists('manufacturer', $data) && is_string($data['manufacturer'])) {
×
NEW
116
            $manufacturer = $data['manufacturer'];
×
117
        }
118

NEW
119
        $version = null;
×
120

NEW
121
        if (array_key_exists('version', $data)) {
×
NEW
122
            if (is_string($data['version']) || $data['version'] instanceof stdClass) {
×
NEW
123
                $version = $data['version'];
×
NEW
124
            } elseif (is_array($data['version'])) {
×
NEW
125
                $version = (object) $data['version'];
×
126
            }
127
        }
128

NEW
129
        $this->name         = $name;
×
NEW
130
        $this->manufacturer = $manufacturer;
×
NEW
131
        $this->version      = $version;
×
132
    }
133
}
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