GeoipTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 19 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Statistics\Transformers\Adminarea;
6
7
use Rinvex\Support\Traits\Escaper;
8
use Rinvex\Statistics\Models\Geoip;
9
use League\Fractal\TransformerAbstract;
10
11
class GeoipTransformer extends TransformerAbstract
12
{
13
    use Escaper;
14
15
    /**
16
     * @return array
17
     */
18
    public function transform(Geoip $geoip): array
19
    {
20
        $country = $geoip->country_code ? country($geoip->country_code) : null;
21
22
        return $this->escape([
23
            'client_ip' => (string) $geoip->client_ip,
24
            'latitude' => (string) $geoip->latitude,
25
            'longitude' => (string) $geoip->longitude,
26
            'country_code' => (string) optional($country)->getName(),
27
            'country_emoji' => (string) optional($country)->getEmoji(),
28
            'client_ips' => (string) $geoip->client_ips,
29
            'is_from_trusted_proxy' => (bool) $geoip->is_from_trusted_proxy,
30
            'division_code' => (string) $geoip->division_code,
31
            'postal_code' => (string) $geoip->postal_code,
32
            'timezone' => (string) $geoip->timezone,
33
            'city' => (string) $geoip->city,
34
            'count' => (int) $geoip->count,
35
        ]);
36
    }
37
}
38