Passed
Push — master ( b262da...c4f2e2 )
by 世昌
02:19
created

Parameter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setIndexName() 0 5 1
A getValue() 0 2 1
A getCommonDefault() 0 2 1
A getIndexName() 0 3 1
A __construct() 0 1 1
A build() 0 4 1
A getDefaultValue() 0 2 2
A name() 0 2 1
1
<?php
2
namespace nebula\route\uri\parameter;
3
4
/**
5
 * 匹配参数
6
 */
7
abstract class Parameter   {
8
9
    protected static $name;
10
    /**
11
     * 索引名
12
     *
13
     * @var string
14
     */
15
    protected $indexName;
16
    /**
17
     * 默认值
18
     *
19
     * @var mixed
20
     */
21
    protected $default;
22
    
23
    public function __construct(string $extra) {
24
    }
25
26
    public static function name():string {
27
        return static::$name;
28
    }
29
30
    public static function build(string $indexName, string $extra):Parameter {
31
        $parameter =  new static($extra);
32
        $parameter->setIndexName($indexName);
33
        return $parameter;
34
    }
35
    
36
    public function getValue(string $matched) {
37
        return $matched;
38
    }
39
40
    public function getDefaultValue() {
41
        return isset($this->default) ? $this->default : null;
42
    }
43
44
    /**
45
     * 获取匹配字符串
46
     *
47
     * @return string
48
     */
49
    public abstract function getMatch():string;
50
51
    public function getCommonDefault(string $extra):string {
52
        return $extra;
53
    }
54
55
    /**
56
     * Get 索引名
57
     *
58
     * @return  string
59
     */ 
60
    public function getIndexName()
61
    {
62
        return $this->indexName;
63
    }
64
65
    /**
66
     * Set 索引名
67
     *
68
     * @param  string  $indexName  索引名
69
     *
70
     * @return  self
71
     */ 
72
    public function setIndexName(string $indexName)
73
    {
74
        $this->indexName = $indexName;
75
76
        return $this;
77
    }
78
}