Passed
Push — master ( 79ca65...aa6b0d )
by 世昌
03:39
created

Parameter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A build() 0 4 1
A name() 0 2 1
A setIndexName() 0 5 1
A getCommonDefault() 0 2 1
A getIndexName() 0 3 1
A unpackValue() 0 2 1
A getDefaultValue() 0 2 2
A packValue() 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 unpackValue(string $value) {
37
        return $value;
38
    }
39
40
    public function packValue(string $value) {
41
        return $value;
42
    }
43
44
    public function getDefaultValue() {
45
        return isset($this->default) ? $this->default : null;
46
    }
47
48
    /**
49
     * 获取匹配字符串
50
     *
51
     * @return string
52
     */
53
    public abstract function getMatch():string;
54
55
    public function getCommonDefault(string $extra):string {
56
        return $extra;
57
    }
58
59
    /**
60
     * Get 索引名
61
     *
62
     * @return  string
63
     */ 
64
    public function getIndexName()
65
    {
66
        return $this->indexName;
67
    }
68
69
    /**
70
     * Set 索引名
71
     *
72
     * @param  string  $indexName  索引名
73
     *
74
     * @return  self
75
     */ 
76
    public function setIndexName(string $indexName)
77
    {
78
        $this->indexName = $indexName;
79
80
        return $this;
81
    }
82
}