public static function createFromArray(array $data)
    {
        $defaults = [
            'providedBy' => 'n/a',
            'latitude' => null,
            'longitude' => null,
            'bounds' => [
                'south' => null,
                'west' => null,
                'north' => null,
                'east' => null,
            ],
            'streetNumber' => null,
            'streetName' => null,
            'locality' => null,
            'postalCode' => null,
            'subLocality' => null,
            'adminLevels' => [],
            'country' => null,
            'countryCode' => null,
            'timezone' => null,
        ];

        $data = array_merge($defaults, $data);

        $adminLevels = [];
        foreach ($data['adminLevels'] as $adminLevel) {
            if (empty($adminLevel['level'])) {
                continue;
            }

            $name = $adminLevel['name'] ?? $adminLevel['code'] ?? null;
            if (empty($name)) {
                continue;
            }

            $adminLevels[] = new AdminLevel($adminLevel['level'], $name, $adminLevel['code'] ?? null);
        }

        return new static(
            $data['providedBy'],
            new AdminLevelCollection($adminLevels),
            self::createCoordinates(
                $data['latitude'],
                $data['longitude']
            ),
            self::createBounds(
                $data['bounds']['south'],
                $data['bounds']['west'],
                $data['bounds']['north'],
                $data['bounds']['east']
            ),
            $data['streetNumber'],
            $data['streetName'],
            $data['postalCode'],
            $data['locality'],
            $data['subLocality'],
            self::createCountry($data['country'], $data['countryCode']),
            $data['timezone']
        );
    }
public static function createFromArray(array $data)
    {
        $defaults = [
            'providedBy' => 'n/a',
            'latitude' => null,
            'longitude' => null,
            'bounds' => [
                'south' => null,
                'west' => null,
                'north' => null,
                'east' => null,
            ],
            'streetNumber' => null,
            'streetName' => null,
            'locality' => null,
            'postalCode' => null,
            'subLocality' => null,
            'adminLevels' => [],
            'country' => null,
            'countryCode' => null,
            'timezone' => null,
        ];

        $data = array_merge($defaults, $data);

        $adminLevels = [];
        foreach ($data['adminLevels'] as $adminLevel) {
            if (empty($adminLevel['level'])) {
                continue;
            }

            $name = $adminLevel['name'] ?? $adminLevel['code'] ?? null;
            if (empty($name)) {
                continue;
            }

            $adminLevels[] = new AdminLevel($adminLevel['level'], $name, $adminLevel['code'] ?? null);
        }

        return new static(
            $data['providedBy'],
            new AdminLevelCollection($adminLevels),
            self::createCoordinates(
                $data['latitude'],
                $data['longitude']
            ),
            self::createBounds(
                $data['bounds']['south'],
                $data['bounds']['west'],
                $data['bounds']['north'],
                $data['bounds']['east']
            ),
            $data['streetNumber'],
            $data['streetName'],
            $data['postalCode'],
            $data['locality'],
            $data['subLocality'],
            self::createCountry($data['country'], $data['countryCode']),
            $data['timezone']
        );
    }
public static function createFromArray ( array $ data ) { $ defaults = [ 'providedBy' => 'n/a' , 'latitude' => null , 'longitude' => null , 'bounds' => [ 'south' => null , 'west' => null , 'north' => null , 'east' => null , ] , 'streetNumber' => null , 'streetName' => null , 'locality' => null , 'postalCode' => null , 'subLocality' => null , 'adminLevels' => [ ] , 'country' => null , 'countryCode' => null , 'timezone' => null , ] ; $ data = array_merge ( $ defaults , $ data ) ; $ adminLevels = [ ] ; foreach ( $ data [ 'adminLevels' ] as $ adminLevel ) { if ( empty ( $ adminLevel [ 'level' ] ) ) { continue ; } $ name = $ adminLevel [ 'name' ] ?? $ adminLevel [ 'code' ] ?? null ; if ( empty ( $ name ) ) { continue ; } $ adminLevels [ ] = new AdminLevel ( $ adminLevel [ 'level' ] , $ name , $ adminLevel [ 'code' ] ?? null ) ; } return new static ( $ data [ 'providedBy' ] , new AdminLevelCollection ( $ adminLevels ) , self :: createCoordinates ( $ data [ 'latitude' ] , $ data [ 'longitude' ] ) , self :: createBounds ( $ data [ 'bounds' ] [ 'south' ] , $ data [ 'bounds' ] [ 'west' ] , $ data [ 'bounds' ] [ 'north' ] , $ data [ 'bounds' ] [ 'east' ] ) , $ data [ 'streetNumber' ] , $ data [ 'streetName' ] , $ data [ 'postalCode' ] , $ data [ 'locality' ] , $ data [ 'subLocality' ] , self :: createCountry ( $ data [ 'country' ] , $ data [ 'countryCode' ] ) , $ data [ 'timezone' ] ) ; }
Create an Address with an array. Useful for testing.

@param array $data

@return static
Create an Address with an array . Useful for testing .