5555use Platine \UserAgent \Util \Helper ;
5656
5757/**
58- * Class AbstractDetector
58+ * @class AbstractDetector
5959 * @package Platine\UserAgent\Detector
6060 */
6161abstract class AbstractDetector
@@ -92,7 +92,7 @@ abstract class AbstractDetector
9292 * The current entity
9393 * @var Browser|Cpu|Os|Device|Engine
9494 */
95- protected $ entity ;
95+ protected Browser | Cpu | Os | Device | Engine $ entity ;
9696
9797 /**
9898 * Create new instance
@@ -113,7 +113,7 @@ public function detect(string $userAgent): void
113113 $ regex = $ this ->regex ();
114114 $ regexLength = count ($ regex );
115115 $ i = 0 ;
116- $ match = null ;
116+ $ match = '' ;
117117 $ matches = [];
118118
119119 while ($ i < $ regexLength && ! $ matches ) {
@@ -155,26 +155,25 @@ public function detect(string $userAgent): void
155155 $ functionName = Helper::replaceFirst ('__ ' , '' , $ q [1 ]);
156156 $ args = explode ('. ' , $ q [2 ]);
157157 $ argument = $ this ->maps ();
158- if (is_array ($ args )) {
159- foreach ($ args as $ key ) {
160- $ argument = $ argument [$ key ];
161- }
158+ foreach ($ args as $ key ) {
159+ $ argument = $ argument [$ key ];
162160 }
161+
163162 $ result = null ;
164163 if (method_exists ($ this , $ functionName )) {
165164 $ result = $ this ->{$ functionName }($ match , $ argument );
166165 }
167166 $ this ->fillEntity ([$ q [0 ] => $ result ]);
168167 } else {
169- $ replacedMatch = preg_replace ($ q [1 ], $ q [2 ], $ match );
168+ $ replacedMatch = preg_replace ($ q [1 ], $ q [2 ], ( string ) $ match );
170169 if ($ replacedMatch !== null ) {
171170 $ this ->fillEntity ([$ q [0 ] => $ replacedMatch ]);
172171 }
173172 }
174173 } elseif (count ($ q ) === 4 ) {
175174 if (Helper::startsWith ($ q [3 ], '__ ' )) {
176175 $ functionName = Helper::replaceFirst ('__ ' , '' , $ q [3 ]);
177- $ result = preg_replace ($ q [1 ], $ q [2 ], $ match );
176+ $ result = preg_replace ($ q [1 ], $ q [2 ], ( string ) $ match );
178177 if (method_exists ($ this , $ functionName )) {
179178 $ result = $ this ->{$ functionName }($ result );
180179 }
@@ -197,7 +196,7 @@ public function detect(string $userAgent): void
197196 * Return the entity instance
198197 * @return Browser|Cpu|Os|Device|Engine
199198 */
200- public function entity ()
199+ public function entity (): Browser | Cpu | Os | Device | Engine
201200 {
202201 return $ this ->entity ;
203202 }
@@ -243,7 +242,7 @@ protected function lowerize(string $value): string
243242 * @param string $str
244243 * @return string|string[]|null
245244 */
246- protected function trim (string $ str )
245+ protected function trim (string $ str ): string | array | null
247246 {
248247 return preg_replace (
249248 '/^[\s\xA0]+|[\s\xA0]+$/ ' ,
0 commit comments