Route_Collection   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A map_construct() 0 8 1
A add_route() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Holds all routes to be dispatched.
7
 *
8
 * @package PinkCrab\Route\Route
9
 * @author Glynn Quelch [email protected]
10
 * @since 0.0.1
11
 */
12
13
namespace PinkCrab\Route;
14
15
use PinkCrab\Route\Route\Route;
16
use PinkCrab\Collection\Collection;
17
use PinkCrab\Route\Route\Route_Group;
18
19
class Route_Collection extends Collection {
20
21
	protected const ALLOWED_ROUTE_TYPES = array( Route::class, Route_Group::class );
22
23
	/**
24
	 * Overwrite this method in any extended classes, to modify the inital data.
25
	 *
26
	 * @param array<int|string, mixed> $data
27
	 * @return array<int|string, mixed>
28
	 */
29
	protected function map_construct( array $data ): array {
30
		return array_filter(
31
			$data,
32
			function( $datum ): bool {
33
				return in_array(
34
					get_class( $datum ),
35
					self::ALLOWED_ROUTE_TYPES,
36
					true
37
				);
38
			}
39
		);
40
	}
41
42
	/**
43
	 * Adds a route to the collection
44
	 *
45
	 * @param Route|Route_Group $route
46
	 * @return static
47
	 */
48
	public function add_route( $route ) {
49
		$this->push( $route );
50
		return $this;
51
	}
52
}
53