1 | <?php |
||
48 | class UserAgentParser |
||
49 | { |
||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | private $userAgent = null; |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | private $operatingSystems = array(); |
||
59 | |||
60 | /** |
||
61 | * @var array |
||
62 | */ |
||
63 | private $webClients = array(); |
||
64 | |||
65 | /** |
||
66 | * @var OperatingSystem |
||
67 | */ |
||
68 | private $undefinedOperatingSystem; |
||
69 | |||
70 | /** |
||
71 | * @var OperatingSystem |
||
72 | */ |
||
73 | private $undefinedWebClient; |
||
74 | |||
75 | 14 | public function __construct() |
|
76 | { |
||
77 | 14 | $this->undefinedOperatingSystem = new UndefinedOperatingSystem(); |
|
78 | 14 | $this->undefinedWebClient = new UndefinedWebClient(); |
|
|
|||
79 | 14 | } |
|
80 | |||
81 | 2 | public static function createInstance(): self |
|
89 | |||
90 | 2 | private function initializeCommonOperatingSystems(): void |
|
96 | |||
97 | 2 | private function initializeCommonWebClients(): void |
|
104 | |||
105 | 4 | public function parseUserAgent(string $userAgent): UserAgent |
|
106 | { |
||
107 | 4 | $this->userAgent = $userAgent; |
|
108 | |||
109 | 4 | return new UserAgent($this->parseOs(), $this->parseWebClient()); |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * @return OperatingSystem |
||
114 | */ |
||
115 | 4 | private function parseOs(): OperatingSystem |
|
116 | { |
||
117 | 4 | foreach ($this->operatingSystems as $currentOs) { |
|
118 | 2 | if ($currentOs->match($this->userAgent)) { |
|
119 | 2 | return $currentOs; |
|
120 | } |
||
121 | } |
||
122 | |||
123 | 3 | return $this->undefinedOperatingSystem; |
|
124 | } |
||
125 | |||
126 | 4 | private function parseWebClient(): WebClient |
|
127 | { |
||
128 | 4 | foreach ($this->webClients as $currentWebClient) { |
|
129 | 1 | if ($currentWebClient->match($this->userAgent)) { |
|
130 | 1 | return $currentWebClient; |
|
131 | } |
||
132 | } |
||
133 | |||
134 | 3 | return $this->undefinedWebClient; |
|
135 | } |
||
136 | |||
137 | 7 | public function addOperatingSystem(OperatingSystem $operatingSystem) |
|
141 | |||
142 | 1 | public function removeOperatingSystem(OperatingSystem $operatingSystem) |
|
146 | |||
147 | 2 | public function removeOperatingSystemByClassName(string $operatingSystem) |
|
151 | |||
152 | 4 | public function getOperatingSystems(): array |
|
156 | |||
157 | 1 | public function getUndefinedOperatingSystem(): OperatingSystem |
|
161 | |||
162 | 2 | public function setUndefinedOperatingSystem(OperatingSystem $operatingSystem) |
|
166 | |||
167 | 6 | public function addWebClient(WebClient $webClient): void |
|
171 | |||
172 | 1 | public function removeWebClient(WebClient $webClient): void |
|
176 | |||
177 | 2 | public function removeWebClientByClassName(string $webClient) |
|
181 | |||
182 | 4 | public function getWebClients(): array |
|
186 | |||
187 | 1 | public function getUndefinedWebClient(): WebClient |
|
191 | |||
192 | 2 | public function setUndefinedWebClient(WebClient $webClient): void |
|
196 | } |
||
197 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..