@@ -96,31 +96,31 @@ protected function anonymizeIp(string $ip): string
9696 // For IPv4, zero out the last octet
9797 $ parts = explode ('. ' , $ ip );
9898 $ parts [3 ] = '0 ' ;
99-
10099 return implode ('. ' , $ parts );
101- } elseif (filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 )) {
100+ }
101+ if (filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 )) {
102102 // For IPv6, zero out the last 80 bits
103103 $ parts = explode (': ' , $ ip );
104- for ($ i = 3 ; $ i < count ($ parts ); $ i ++) {
104+ $ counter = count ($ parts );
105+ for ($ i = 3 ; $ i < $ counter ; $ i ++) {
105106 $ parts [$ i ] = '0 ' ;
106107 }
107-
108108 return implode (': ' , $ parts );
109109 }
110110
111111 return $ ip ;
112112 }
113113
114- protected function parseUserAgent ($ userAgent )
114+ protected function parseUserAgent ($ userAgent ): array
115115 {
116116 $ operating_system = $ this ->getOperatingSystem ($ userAgent );
117117 $ browser = $ this ->getBrowser ($ userAgent );
118118 $ device = $ this ->getDevice ($ userAgent );
119119
120- return compact ( 'operating_system ' , 'browser ' , 'device ' ) ;
120+ return [ 'operating_system ' => $ operating_system , 'browser ' => $ browser , 'device ' => $ device ] ;
121121 }
122122
123- protected function getOperatingSystem ($ userAgent )
123+ protected function getOperatingSystem ($ userAgent ): string
124124 {
125125 $ operatingSystem = 'Unknown ' ;
126126 $ osRegexes = [
@@ -150,7 +150,7 @@ protected function getOperatingSystem($userAgent)
150150 ];
151151
152152 foreach ($ osRegexes as $ regex => $ os ) {
153- if (preg_match ($ regex , $ userAgent )) {
153+ if (preg_match ($ regex , ( string ) $ userAgent )) {
154154 $ operatingSystem = $ os ;
155155 break ;
156156 }
@@ -159,7 +159,7 @@ protected function getOperatingSystem($userAgent)
159159 return $ operatingSystem ;
160160 }
161161
162- protected function getBrowser ($ userAgent )
162+ protected function getBrowser ($ userAgent ): string
163163 {
164164 $ browser = 'Unknown ' ;
165165 $ browserRegexes = [
@@ -174,7 +174,7 @@ protected function getBrowser($userAgent)
174174 ];
175175
176176 foreach ($ browserRegexes as $ regex => $ br ) {
177- if (preg_match ($ regex , $ userAgent )) {
177+ if (preg_match ($ regex , ( string ) $ userAgent )) {
178178 $ browser = $ br ;
179179 break ;
180180 }
@@ -183,7 +183,7 @@ protected function getBrowser($userAgent)
183183 return $ browser ;
184184 }
185185
186- protected function getDevice ($ userAgent )
186+ protected function getDevice ($ userAgent ): string
187187 {
188188 $ device = 'Unknown ' ;
189189 $ deviceRegexes = [
@@ -198,7 +198,7 @@ protected function getDevice($userAgent)
198198 ];
199199
200200 foreach ($ deviceRegexes as $ regex => $ dev ) {
201- if (preg_match ($ regex , $ userAgent )) {
201+ if (preg_match ($ regex , ( string ) $ userAgent )) {
202202 $ device = $ dev ;
203203 break ;
204204 }
0 commit comments