Passed
Pull Request — master (#71)
by Adeniyi
05:43
created

AddressTransformable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A transformAddress() 0 31 3
1
<?php
2
3
namespace App\Shop\Addresses\Transformations;
4
5
use App\Shop\Addresses\Address;
6
use App\Shop\Cities\Repositories\CityRepository;
7
use App\Shop\Countries\Repositories\CountryRepository;
8
use App\Shop\Customers\Customer;
9
use App\Shop\Customers\Repositories\CustomerRepository;
10
use App\Shop\Provinces\Province;
11
use App\Shop\Provinces\Repositories\ProvinceRepository;
12
use App\Shop\Cities\City;
13
use App\Shop\Countries\Country;
14
15
trait AddressTransformable
16
{
17
    /**
18
     * Transform the address
19
     *
20
     * @param Address $address
21
     * @return Address
22
     */
23
    public function transformAddress(Address $address)
24
    {
25
        $obj = new Address;
26
        $obj->id = $address->id;
27
        $obj->alias = $address->alias;
28
        $obj->address_1 = $address->address_1;
29
        $obj->address_2 = $address->address_2;
30
        $obj->zip = $address->zip;
31
32
        if (isset($address->city_id)) {
33
            $cityRepo = new CityRepository(new City);
34
            $city = $cityRepo->findCityById($address->city_id);
35
            $obj->city = $city->name;
36
        }
37
38
        if (isset($address->province_id)) {
39
            $provinceRepo = new ProvinceRepository(new Province);
40
            $province = $provinceRepo->findProvinceById($address->province_id);
41
            $obj->province = $province->name;
42
        }
43
44
        $countryRepo = new CountryRepository(new Country);
45
        $country = $countryRepo->findCountryById($address->country_id);
46
        $obj->country = $country->name;
47
48
        $customerRepo = new CustomerRepository(new Customer);
49
        $customer = $customerRepo->findCustomerById($address->customer_id);
50
        $obj->customer = $customer->name;
51
        $obj->status = $address->status;
52
53
        return $obj;
54
    }
55
}
56