Completed
Push — master ( f451ed...7bd00e )
by Marco
02:07
created

Name::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace MJanssen\Route;
4
5
class Name
6
{
7
    /**
8
     * @var string
9
     */
10
    private $name;
11
12
    /**
13
     * @param string $name
14
     */
15
    public function __construct($name = '')
16
    {
17
        if (empty($name)) {
18
            //If no routeName is specified,
19
            //we set an empty route name to force the default route name e.g. "GET_myRouteName"
20
            $name = '';
21
        }
22
23
        if (is_numeric($name)) {
24
            $name = '';
25
        }
26
27
        $name = str_replace(['/', ':', '|', '-'], '_', $name);
28
        $name = preg_replace('/[^a-z0-9A-Z_.]+/', '', $name);
29
30
        $this->name = $name;
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getName()
37
    {
38
        return $this->name;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function __toString()
45
    {
46
        return $this->getName();
47
    }
48
}