Passed
Push — master ( a4f803...3d4b77 )
by smiley
12:11
created

GeoJSONAbstract::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Class GeoJSONAbstract
4
 *
5
 * @created      14.02.2019
6
 * @author       smiley <[email protected]>
7
 * @copyright    2019 smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\GeoJSON;
12
13
use JsonSerializable;
14
use function count;
15
use function in_array;
16
use function json_encode;
17
18
abstract class GeoJSONAbstract implements JsonSerializable{
19
20
	protected array $bbox;
21
22
	/**
23
	 * @throws \chillerlan\GeoJSON\GeoJSONException
24
	 */
25
	public function setBbox(array $bbox):GeoJSONAbstract{
26
27
		if(!in_array(count($bbox), [4, 6], true)){
28
			throw new GeoJSONException('invalid bounding box array');
29
		}
30
31
		$this->bbox = $bbox;
32
33
		return $this;
34
	}
35
36
	/**
37
	 *
38
	 */
39
	abstract public function toArray():array;
40
41
	/**
42
	 *
43
	 */
44
	public function toJSON(int $options = null):string{
45
		return json_encode($this->toArray(), $options ?? 0);
46
	}
47
48
	/**
49
	 * @inheritDoc
50
	 */
51
	public function jsonSerialize():array{
52
		return $this->toArray();
53
	}
54
55
}
56