Passed
Push — master ( 0ee5ba...9ecbd5 )
by Alex
06:47
created

RouteTypes::addType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Mezon\Router;
3
4
/**
5
 * Default types for router - integer, string, command, list if ids
6
 *
7
 * @author gdever
8
 */
9
trait RouteTypes
10
{
11
12
    /**
13
     * Supported types of URL parameters
14
     *
15
     * @var array
16
     */
17
    private $types = [];
18
19
    /**
20
     * Init types
21
     */
22
    private function initDefaultTypes(): void
23
    {
24
        $this->types['i'] = '\Mezon\Router\Types\IntegerRouterType';
25
        $this->types['a'] = '\Mezon\Router\Types\CommandRouterType';
26
        $this->types['il'] = '\Mezon\Router\Types\IntegerListRouterType';
27
        $this->types['s'] = '\Mezon\Router\Types\StringRouterType';
28
        $this->types['fp'] = '\Mezon\Router\Types\FixPointNumberRouterType';
29
    }
30
31
    /**
32
     * Method adds custom type
33
     *
34
     * @param string $typeName
35
     *            type name
36
     * @param string $className
37
     *            name of the class wich represents custom type
38
     */
39
    public function addType(string $typeName, string $className): void
40
    {
41
        $this->types = array_merge([
42
            $typeName => $className
43
        ], $this->types);
44
    }
45
}
46