AddressFinderField   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getAddressArray() 0 12 7
A validate() 0 14 2
1
<?php
2
/**
3
 * Enter an address and check that it is correct ...
4
 * @package forms
5
 * @subpackage fields-formattedinput
6
 */
7
class AddressFinderField extends TextField
8
{
9
    private static $_address_array = null;
10
11
    /**
12
     * returns false if the address can not be found and TRUE
13
     * if the address can be found...
14
     * @param array $params params for the Google Server
15
     *
16
     * @return false|array
17
     */
18
    public function getAddressArray($params = [])
19
    {
20
        if (!isset(self::$_address_array) && $this->value) {
21
            self::$_address_array = GetLatLngFromGoogleUsingAddress::get_placemark_as_array($this->value, false, $params);
22
        }
23
        if (isset(self::$_address_array["Longitude"]) && isset(self::$_address_array["Latitude"])) {
24
            if (floatval(self::$_address_array["Longitude"]) && floatval(self::$_address_array["Latitude"])) {
25
                return self::$_address_array;
26
            }
27
        }
28
        return false;
29
    }
30
31
    public function validate($validator)
32
    {
33
        $this->value = trim($this->value);
34
        if (!$this->getAddressArray()) {
35
            $validator->validationError(
36
                $this->name,
37
                _t('AddressFinderField.VALIDATION', "Please enter a valid address."),
38
                "validation"
39
            );
40
            return false;
41
        } else {
42
            return true;
43
        }
44
    }
45
}
46