Passed
Push — master ( 516163...07b934 )
by 世昌
02:15
created

StringParameter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getMatch() 0 2 1
A packValue() 0 2 1
A unpackValue() 0 2 1
1
<?php
2
namespace nebula\component\route\uri\parameter;
3
4
use nebula\component\route\uri\parameter\Parameter;
5
6
/**
7
 * 匹配 string 参数
8
 */
9
class StringParameter extends Parameter {
10
11
    protected static $name = 'string';
12
    
13
    public function __construct(string $extra) {
14
        $this->default = $this->getCommonDefault($extra);
15
    }
16
 
17
    public function unpackValue(string $matched) {
18
        return urldecode($matched);
19
    }
20
21
    public function packValue(string $matched) {
22
        return urlencode($matched);
23
    }
24
    
25
    /**
26
     * 获取匹配字符串
27
     *
28
     * @return string
29
     */
30
    public function getMatch():string {
31
        return '([^\/]+)';
32
    }
33
}