| Conditions | 2 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 48 | public function testRule() |
||
| 49 | { |
||
| 50 | $rule = [ |
||
| 51 | 'name' => 'require|method:get|alphaNum|max:25|expire:2016-1-1,2026-1-1', |
||
| 52 | 'account' => 'requireIf:name,thinkphp|alphaDash|min:4|length:4,30', |
||
| 53 | 'age' => 'number|between:1,120', |
||
| 54 | 'email' => 'requireWith:name|email', |
||
| 55 | 'host' => 'activeUrl|activeUrl:A', |
||
| 56 | 'url' => 'url', |
||
| 57 | 'ip' => 'ip|ip:ipv4', |
||
| 58 | 'score' => 'float|gt:60|notBetween:90,100|notIn:70,80|lt:100|elt:100|egt:60', |
||
| 59 | 'status' => 'integer|in:0,1,2', |
||
| 60 | 'begin_time' => 'after:2016-3-18', |
||
| 61 | 'end_time' => 'before:2016-10-01', |
||
| 62 | 'info' => 'require|array|length:4|max:5|min:2', |
||
| 63 | 'info.name' => 'require|length:8|alpha|same:thinkphp', |
||
| 64 | 'value' => 'same:100|different:status', |
||
| 65 | 'bool' => 'boolean', |
||
| 66 | 'title' => 'chsAlpha', |
||
| 67 | 'city' => 'chs', |
||
| 68 | 'nickname' => 'chsDash', |
||
| 69 | 'aliasname' => 'chsAlphaNum', |
||
| 70 | 'file' => 'file|fileSize:20480', |
||
| 71 | 'image' => 'image|fileMime:image/png|image:80,80,png', |
||
| 72 | 'test' => 'test', |
||
| 73 | ]; |
||
| 74 | $data = [ |
||
| 75 | 'name' => 'thinkphp', |
||
| 76 | 'account' => 'liuchen', |
||
| 77 | 'age' => 10, |
||
| 78 | 'email' => '[email protected]', |
||
| 79 | 'host' => 'thinkphp.cn', |
||
| 80 | 'url' => 'http://thinkphp.cn/topic', |
||
| 81 | 'ip' => '114.34.54.5', |
||
| 82 | 'score' => '89.15', |
||
| 83 | 'status' => 1, |
||
| 84 | 'begin_time' => '2016-3-20', |
||
| 85 | 'end_time' => '2016-5-1', |
||
| 86 | 'info' => [1, 2, 3, 'name' => 'thinkphp'], |
||
| 87 | 'zip' => '200000', |
||
| 88 | 'date' => '16-3-8', |
||
| 89 | 'ok' => 'yes', |
||
| 90 | 'value' => 100, |
||
| 91 | 'bool' => true, |
||
| 92 | 'title' => '流年ThinkPHP', |
||
| 93 | 'city' => '上海', |
||
| 94 | 'nickname' => '流年ThinkPHP_2016', |
||
| 95 | 'aliasname' => '流年Think2016', |
||
| 96 | 'file' => new File(THINK_PATH . 'base.php'), |
||
| 97 | 'image' => new File(THINK_PATH . 'logo.png'), |
||
| 98 | 'test' => 'test', |
||
| 99 | ]; |
||
| 100 | $validate = new Validate($rule); |
||
| 101 | $validate->extend('test', function ($value) {return 'test' == $value ? true : false;}); |
||
| 102 | $validate->rule('zip', '/^\d{6}$/'); |
||
| 103 | $validate->rule([ |
||
| 104 | 'ok' => 'require|accepted', |
||
| 105 | 'date' => 'date|dateFormat:y-m-d', |
||
| 106 | ]); |
||
| 107 | $result = $validate->batch()->check($data); |
||
| 108 | $this->assertEquals(true, $result); |
||
| 109 | } |
||
| 201 |