Passed
Push — master ( 3c6b22...0af44e )
by Roberto
45s
created
src/Fields/GoogleMapsResponseFields.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@
 block discarded – undo
16 16
  */
17 17
 class GoogleMapsResponseFields {
18 18
 
19
-	/**
20
-	 * string: results
21
-	 */
22
-	const RESULTS = 'results';
19
+    /**
20
+     * string: results
21
+     */
22
+    const RESULTS = 'results';
23 23
 
24
-	/**
25
-	 * string: status
26
-	 */
27
-	const STATUS = 'status';
24
+    /**
25
+     * string: status
26
+     */
27
+    const STATUS = 'status';
28 28
 
29
-	/**
30
-	 * string: error_message
31
-	 */
32
-	const ERROR_MESSAGE = 'error_message';
29
+    /**
30
+     * string: error_message
31
+     */
32
+    const ERROR_MESSAGE = 'error_message';
33 33
 
34 34
 }
35 35
\ No newline at end of file
Please login to merge, or discard this patch.
src/Fields/LatLngFields.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@
 block discarded – undo
16 16
  */
17 17
 class LatLngFields {
18 18
 
19
-	/**
20
-	 * string - latitude
21
-	 */
22
-	const LAT = 'lat';
19
+    /**
20
+     * string - latitude
21
+     */
22
+    const LAT = 'lat';
23 23
 
24
-	/**
25
-	 * string - longitude
26
-	 */
27
-	const LNG = 'lng';
24
+    /**
25
+     * string - longitude
26
+     */
27
+    const LNG = 'lng';
28 28
 }
29 29
\ No newline at end of file
Please login to merge, or discard this patch.
src/Abstracts/AbstractObject.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -19,158 +19,158 @@
 block discarded – undo
19 19
  */
20 20
 abstract class AbstractObject {
21 21
 
22
-	/**
23
-	 * @var array
24
-	 */
25
-	protected $typeCheck = [];
26
-
27
-	/**
28
-	 * @var array
29
-	 */
30
-	protected $required = [];
31
-
32
-	/**
33
-	 * @var array
34
-	 */
35
-	protected $errors = [];
36
-
37
-	/**
38
-	 * AbstractObject constructor.
39
-	 *
40
-	 * @param array $args
41
-	 */
42
-	public function __construct(?array $args = []) {
43
-
44
-		$this->setArgs($args);
45
-	}
46
-
47
-	/**
48
-	 * @param array $args
49
-	 *
50
-	 * @throws Exception
51
-	 */
52
-	protected function setArgs(array $args) {
53
-
54
-		foreach ($this->typeCheck as $field_name => $field_type) {
55
-			if (empty($args[$field_name]) || is_null($args[$field_name])) {
56
-				if ($this->isFieldRequired($field_name)) {
57
-					$this->addError('Missing "' . $field_name . '" in ' . static::class);
58
-				}
59
-			} else {
60
-				$this->$field_name = $this->parseFieldValue($field_type, $args[$field_name]);
61
-			}
62
-		}
63
-		$this->throwErrors();
64
-	}
65
-
66
-	/**
67
-	 * @param string $field_name
68
-	 *
69
-	 * @return bool
70
-	 */
71
-	protected function isFieldRequired(string $field_name): bool {
72
-
73
-		return in_array($field_name, $this->required);
74
-	}
75
-
76
-	/**
77
-	 * @param string $error
78
-	 *
79
-	 * @return array
80
-	 */
81
-	protected function addError(string $error): array {
82
-
83
-		array_push($this->errors, $error);
84
-
85
-		return $this->errors;
86
-	}
87
-
88
-	/**
89
-	 * @param string $field_type
90
-	 * @param string $field_value
91
-	 *
92
-	 * @return mixed
93
-	 */
94
-	protected function parseFieldValue(string $field_type, $field_value) {
95
-
96
-		switch ($field_type) {
97
-			case 'string':
98
-			case 'int':
99
-			case 'float':
100
-			case 'array':
101
-				return $field_value;
102
-			default:
103
-				return ($field_value instanceof $field_type) ? $field_value : new $field_type($field_value);
104
-		}
105
-	}
106
-
107
-	/**
108
-	 * @throws Exception
109
-	 */
110
-	protected function throwErrors() {
111
-
112
-		if (count($this->errors)) {
113
-			throw new Exception(implode(', ', $this->errors));
114
-		}
115
-	}
116
-
117
-	/**
118
-	 * @return string
119
-	 */
120
-	public function toJson(): string {
121
-
122
-		return json_encode($this->toArray());
123
-	}
124
-
125
-	/**
126
-	 * @return array
127
-	 */
128
-	public function toArray(): array {
129
-
130
-		$fields = get_object_vars($this);
131
-
132
-		foreach ($fields as $field_name => $field_value) {
133
-
134
-			if (!is_scalar($field_value) && method_exists($field_value, 'toJson')) {
135
-				$fields[$field_name] = $field_value->toArray();
136
-			}
137
-		}
138
-
139
-		return $fields;
140
-	}
141
-
142
-	/**
143
-	 * @return string
144
-	 */
145
-	public function __toString(): string {
146
-
147
-		return implode(',', $this->toArray());
148
-	}
149
-
150
-	/**
151
-	 * @param $name
152
-	 * @param $arguments
153
-	 *
154
-	 * @return mixed
155
-	 */
156
-	public function __call($name, $arguments) {
157
-
158
-		preg_match('/(?<=(g|s)et)([A-Za-z0-9])\w+/', $name, $match);
159
-
160
-		$camel_field = (empty($match[0])) ? '' : $match[0];
161
-
162
-		$snake_field = camel2Snake($camel_field);
163
-
164
-		$field_type = (empty($this->typeCheck[$snake_field])) ? null : $this->typeCheck[$snake_field];
165
-
166
-		if (!empty($match[1]) && $field_type) {
167
-			switch ($match[1]) {
168
-				case 's':
169
-					return $this->$snake_field = $this->parseFieldValue($field_type, current($arguments));
170
-				case 'g':
171
-					return $this->$snake_field;
172
-			}
173
-		}
174
-	}
22
+    /**
23
+     * @var array
24
+     */
25
+    protected $typeCheck = [];
26
+
27
+    /**
28
+     * @var array
29
+     */
30
+    protected $required = [];
31
+
32
+    /**
33
+     * @var array
34
+     */
35
+    protected $errors = [];
36
+
37
+    /**
38
+     * AbstractObject constructor.
39
+     *
40
+     * @param array $args
41
+     */
42
+    public function __construct(?array $args = []) {
43
+
44
+        $this->setArgs($args);
45
+    }
46
+
47
+    /**
48
+     * @param array $args
49
+     *
50
+     * @throws Exception
51
+     */
52
+    protected function setArgs(array $args) {
53
+
54
+        foreach ($this->typeCheck as $field_name => $field_type) {
55
+            if (empty($args[$field_name]) || is_null($args[$field_name])) {
56
+                if ($this->isFieldRequired($field_name)) {
57
+                    $this->addError('Missing "' . $field_name . '" in ' . static::class);
58
+                }
59
+            } else {
60
+                $this->$field_name = $this->parseFieldValue($field_type, $args[$field_name]);
61
+            }
62
+        }
63
+        $this->throwErrors();
64
+    }
65
+
66
+    /**
67
+     * @param string $field_name
68
+     *
69
+     * @return bool
70
+     */
71
+    protected function isFieldRequired(string $field_name): bool {
72
+
73
+        return in_array($field_name, $this->required);
74
+    }
75
+
76
+    /**
77
+     * @param string $error
78
+     *
79
+     * @return array
80
+     */
81
+    protected function addError(string $error): array {
82
+
83
+        array_push($this->errors, $error);
84
+
85
+        return $this->errors;
86
+    }
87
+
88
+    /**
89
+     * @param string $field_type
90
+     * @param string $field_value
91
+     *
92
+     * @return mixed
93
+     */
94
+    protected function parseFieldValue(string $field_type, $field_value) {
95
+
96
+        switch ($field_type) {
97
+            case 'string':
98
+            case 'int':
99
+            case 'float':
100
+            case 'array':
101
+                return $field_value;
102
+            default:
103
+                return ($field_value instanceof $field_type) ? $field_value : new $field_type($field_value);
104
+        }
105
+    }
106
+
107
+    /**
108
+     * @throws Exception
109
+     */
110
+    protected function throwErrors() {
111
+
112
+        if (count($this->errors)) {
113
+            throw new Exception(implode(', ', $this->errors));
114
+        }
115
+    }
116
+
117
+    /**
118
+     * @return string
119
+     */
120
+    public function toJson(): string {
121
+
122
+        return json_encode($this->toArray());
123
+    }
124
+
125
+    /**
126
+     * @return array
127
+     */
128
+    public function toArray(): array {
129
+
130
+        $fields = get_object_vars($this);
131
+
132
+        foreach ($fields as $field_name => $field_value) {
133
+
134
+            if (!is_scalar($field_value) && method_exists($field_value, 'toJson')) {
135
+                $fields[$field_name] = $field_value->toArray();
136
+            }
137
+        }
138
+
139
+        return $fields;
140
+    }
141
+
142
+    /**
143
+     * @return string
144
+     */
145
+    public function __toString(): string {
146
+
147
+        return implode(',', $this->toArray());
148
+    }
149
+
150
+    /**
151
+     * @param $name
152
+     * @param $arguments
153
+     *
154
+     * @return mixed
155
+     */
156
+    public function __call($name, $arguments) {
157
+
158
+        preg_match('/(?<=(g|s)et)([A-Za-z0-9])\w+/', $name, $match);
159
+
160
+        $camel_field = (empty($match[0])) ? '' : $match[0];
161
+
162
+        $snake_field = camel2Snake($camel_field);
163
+
164
+        $field_type = (empty($this->typeCheck[$snake_field])) ? null : $this->typeCheck[$snake_field];
165
+
166
+        if (!empty($match[1]) && $field_type) {
167
+            switch ($match[1]) {
168
+                case 's':
169
+                    return $this->$snake_field = $this->parseFieldValue($field_type, current($arguments));
170
+                case 'g':
171
+                    return $this->$snake_field;
172
+            }
173
+        }
174
+    }
175 175
 
176 176
 }
177 177
\ No newline at end of file
Please login to merge, or discard this patch.
src/Abstracts/Api.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -21,93 +21,93 @@
 block discarded – undo
21 21
  */
22 22
 abstract class Api {
23 23
 
24
-	/**
25
-	 * @var string
26
-	 */
27
-	const SERVICE_ENDPOINT = null;
28
-
29
-	/**
30
-	 * @var GoogleMapsApi
31
-	 */
32
-	protected $google_maps_api = null;
33
-
34
-	/**
35
-	 * @var string
36
-	 */
37
-	protected $result_collection = '';
38
-
39
-	/**
40
-	 * Api constructor.
41
-	 *
42
-	 * @param array $config
43
-	 */
44
-	public function __construct(array $config = []) {
45
-
46
-		$service_config = $this->getServiceConfig($config);
47
-		$this->setGoogleMapsApi(new GoogleMapsApi($service_config));
48
-	}
49
-
50
-	/**
51
-	 * @param array $config
52
-	 *
53
-	 * @return array
54
-	 */
55
-	protected function getServiceConfig(array $config = []): array {
56
-
57
-		return array_merge($config, [
58
-			GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint()
59
-		]);
60
-	}
61
-
62
-	/**
63
-	 * @return string
64
-	 */
65
-	public function getServiceEndpoint(): string {
66
-
67
-		return static::SERVICE_ENDPOINT;
68
-	}
69
-
70
-	/**
71
-	 * @return GoogleMapsApi
72
-	 */
73
-	public function getGoogleMapsApi(): GoogleMapsApi {
74
-
75
-		return $this->google_maps_api;
76
-	}
77
-
78
-	/**
79
-	 * @param GoogleMapsApi $google_maps_api
80
-	 *
81
-	 * @return Api
82
-	 */
83
-	public function setGoogleMapsApi(GoogleMapsApi $google_maps_api): Api {
84
-
85
-		$this->google_maps_api = $google_maps_api;
86
-
87
-		return $this;
88
-	}
89
-
90
-	/**
91
-	 * @param array $params
92
-	 *
93
-	 * @return mixed
94
-	 */
95
-	public function createRequest(array $params): GoogleMapsRequest {
96
-
97
-		return new GoogleMapsRequest($params);
98
-	}
99
-
100
-	/**
101
-	 * @param GoogleMapsRequest $request
102
-	 *
103
-	 * @return GoogleMapsResultsCollection
104
-	 */
105
-	public function getResultsCollections(GoogleMapsRequest $request): GoogleMapsResultsCollection {
106
-
107
-		$results = $this->getGoogleMapsApi()->get($request)->getResults();
108
-
109
-		$result_collection_class = $this->result_collection;
110
-
111
-		return new $result_collection_class($results);
112
-	}
24
+    /**
25
+     * @var string
26
+     */
27
+    const SERVICE_ENDPOINT = null;
28
+
29
+    /**
30
+     * @var GoogleMapsApi
31
+     */
32
+    protected $google_maps_api = null;
33
+
34
+    /**
35
+     * @var string
36
+     */
37
+    protected $result_collection = '';
38
+
39
+    /**
40
+     * Api constructor.
41
+     *
42
+     * @param array $config
43
+     */
44
+    public function __construct(array $config = []) {
45
+
46
+        $service_config = $this->getServiceConfig($config);
47
+        $this->setGoogleMapsApi(new GoogleMapsApi($service_config));
48
+    }
49
+
50
+    /**
51
+     * @param array $config
52
+     *
53
+     * @return array
54
+     */
55
+    protected function getServiceConfig(array $config = []): array {
56
+
57
+        return array_merge($config, [
58
+            GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint()
59
+        ]);
60
+    }
61
+
62
+    /**
63
+     * @return string
64
+     */
65
+    public function getServiceEndpoint(): string {
66
+
67
+        return static::SERVICE_ENDPOINT;
68
+    }
69
+
70
+    /**
71
+     * @return GoogleMapsApi
72
+     */
73
+    public function getGoogleMapsApi(): GoogleMapsApi {
74
+
75
+        return $this->google_maps_api;
76
+    }
77
+
78
+    /**
79
+     * @param GoogleMapsApi $google_maps_api
80
+     *
81
+     * @return Api
82
+     */
83
+    public function setGoogleMapsApi(GoogleMapsApi $google_maps_api): Api {
84
+
85
+        $this->google_maps_api = $google_maps_api;
86
+
87
+        return $this;
88
+    }
89
+
90
+    /**
91
+     * @param array $params
92
+     *
93
+     * @return mixed
94
+     */
95
+    public function createRequest(array $params): GoogleMapsRequest {
96
+
97
+        return new GoogleMapsRequest($params);
98
+    }
99
+
100
+    /**
101
+     * @param GoogleMapsRequest $request
102
+     *
103
+     * @return GoogleMapsResultsCollection
104
+     */
105
+    public function getResultsCollections(GoogleMapsRequest $request): GoogleMapsResultsCollection {
106
+
107
+        $results = $this->getGoogleMapsApi()->get($request)->getResults();
108
+
109
+        $result_collection_class = $this->result_collection;
110
+
111
+        return new $result_collection_class($results);
112
+    }
113 113
 }
114 114
\ No newline at end of file
Please login to merge, or discard this patch.
src/Http/GoogleMapsResultsCollection.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -18,20 +18,20 @@
 block discarded – undo
18 18
  */
19 19
 class GoogleMapsResultsCollection extends AbstractCollection {
20 20
 
21
-	/**
22
-	 * @var string
23
-	 */
24
-	protected $item_class = GoogleMapsResult::class;
21
+    /**
22
+     * @var string
23
+     */
24
+    protected $item_class = GoogleMapsResult::class;
25 25
 
26
-	/**
27
-	 * @param $item
28
-	 *
29
-	 * @return GeocodingResult
30
-	 */
31
-	protected function parseItem($item) {
26
+    /**
27
+     * @param $item
28
+     *
29
+     * @return GeocodingResult
30
+     */
31
+    protected function parseItem($item) {
32 32
 
33
-		$item_class = $this->item_class;
33
+        $item_class = $this->item_class;
34 34
 
35
-		return new $item_class($item);
36
-	}
35
+        return new $item_class($item);
36
+    }
37 37
 }
38 38
\ No newline at end of file
Please login to merge, or discard this patch.
src/Http/Result/ElevationResult.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -29,28 +29,28 @@
 block discarded – undo
29 29
  */
30 30
 class ElevationResult extends GoogleMapsResult {
31 31
 
32
-	/**
33
-	 * @var float
34
-	 */
35
-	protected $elevation = null;
36
-
37
-	/**
38
-	 * @var Location
39
-	 */
40
-	protected $location = null;
41
-
42
-	/**
43
-	 * @var float
44
-	 */
45
-	protected $resolution = null;
46
-
47
-	/**
48
-	 * @var array
49
-	 */
50
-	protected $typeCheck = [
51
-		GoogleMapsResultFields::LOCATION   => Location::class,
52
-		GoogleMapsResultFields::ELEVATION  => 'float',
53
-		GoogleMapsResultFields::RESOLUTION => 'float',
54
-	];
32
+    /**
33
+     * @var float
34
+     */
35
+    protected $elevation = null;
36
+
37
+    /**
38
+     * @var Location
39
+     */
40
+    protected $location = null;
41
+
42
+    /**
43
+     * @var float
44
+     */
45
+    protected $resolution = null;
46
+
47
+    /**
48
+     * @var array
49
+     */
50
+    protected $typeCheck = [
51
+        GoogleMapsResultFields::LOCATION   => Location::class,
52
+        GoogleMapsResultFields::ELEVATION  => 'float',
53
+        GoogleMapsResultFields::RESOLUTION => 'float',
54
+    ];
55 55
 
56 56
 }
57 57
\ No newline at end of file
Please login to merge, or discard this patch.
src/Http/Result/ElevationResultsCollection.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@
 block discarded – undo
20 20
  */
21 21
 class ElevationResultsCollection extends GoogleMapsResultsCollection {
22 22
 
23
-	/**
24
-	 * @var string
25
-	 */
26
-	protected $item_class = ElevationResult::class;
23
+    /**
24
+     * @var string
25
+     */
26
+    protected $item_class = ElevationResult::class;
27 27
 }
28 28
\ No newline at end of file
Please login to merge, or discard this patch.
src/Http/Result/GeocodingResultsCollection.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
18 18
  */
19 19
 class GeocodingResultsCollection extends GoogleMapsResultsCollection {
20 20
 
21
-	/**
22
-	 * @var string
23
-	 */
24
-	protected $item_class = GeocodingResult::class;
21
+    /**
22
+     * @var string
23
+     */
24
+    protected $item_class = GeocodingResult::class;
25 25
 }
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Elevation.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -25,54 +25,54 @@
 block discarded – undo
25 25
  */
26 26
 class Elevation extends Api {
27 27
 
28
-	/**
29
-	 * @var string
30
-	 */
31
-	const SERVICE_ENDPOINT = 'elevation';
28
+    /**
29
+     * @var string
30
+     */
31
+    const SERVICE_ENDPOINT = 'elevation';
32 32
 
33
-	/**
34
-	 * @var string
35
-	 */
36
-	protected $result_collection = ElevationResultsCollection::class;
33
+    /**
34
+     * @var string
35
+     */
36
+    protected $result_collection = ElevationResultsCollection::class;
37 37
 
38
-	/**
39
-	 * Positional Requests
40
-	 *
41
-	 * @param LatLng|string|array $locations
42
-	 * This parameter takes either a single location or multiple locations passed as an array or as an encoded polyline
43
-	 *
44
-	 * @since 0.3.0
45
-	 *
46
-	 * @return GoogleMapsResultsCollection
47
-	 */
48
-	public function getByLocations($locations): GoogleMapsResultsCollection {
38
+    /**
39
+     * Positional Requests
40
+     *
41
+     * @param LatLng|string|array $locations
42
+     * This parameter takes either a single location or multiple locations passed as an array or as an encoded polyline
43
+     *
44
+     * @since 0.3.0
45
+     *
46
+     * @return GoogleMapsResultsCollection
47
+     */
48
+    public function getByLocations($locations): GoogleMapsResultsCollection {
49 49
 
50
-		$locations = $this->parseLocations($locations);
50
+        $locations = $this->parseLocations($locations);
51 51
 
52
-		$request = $this->createRequest([
53
-			GoogleMapsRequestFields::LOCATIONS => $locations
54
-		]);
52
+        $request = $this->createRequest([
53
+            GoogleMapsRequestFields::LOCATIONS => $locations
54
+        ]);
55 55
 
56
-		return $this->getResultsCollections($request);
57
-	}
56
+        return $this->getResultsCollections($request);
57
+    }
58 58
 
59
-	/**
60
-	 * @param $locations
61
-	 *
62
-	 * @since   0.3.0
63
-	 *
64
-	 * @return string
65
-	 */
66
-	public function parseLocations($locations): string {
59
+    /**
60
+     * @param $locations
61
+     *
62
+     * @since   0.3.0
63
+     *
64
+     * @return string
65
+     */
66
+    public function parseLocations($locations): string {
67 67
 
68
-		if (is_array($locations)) {
69
-			$locations = implode('|', array_map(function ($item) {
68
+        if (is_array($locations)) {
69
+            $locations = implode('|', array_map(function ($item) {
70 70
 
71
-				return (string)$item;
72
-			}, $locations));
73
-		}
71
+                return (string)$item;
72
+            }, $locations));
73
+        }
74 74
 
75
-		return (string)$locations;
76
-	}
75
+        return (string)$locations;
76
+    }
77 77
 
78 78
 }
79 79
\ No newline at end of file
Please login to merge, or discard this patch.