Skip to content

Commit e900a44

Browse files
committed
update some. add before and after on rule settings
1 parent 3994917 commit e900a44

35 files changed

+362
-238
lines changed

.php_cs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,21 @@ $header = <<<'EOF'
55
@license https://github.com/inhere/php-validate/blob/master/LICENSE
66
EOF;
77

8-
return PhpCsFixer\Config::create()
9-
->setRiskyAllowed(true)
10-
->setRules([
11-
'@PSR2' => true,
12-
// 'header_comment' => [
13-
// 'comment_type' => 'PHPDoc',
14-
// 'header' => $header,
15-
// 'separate' => 'none'
16-
// ],
17-
'array_syntax' => [
18-
'syntax' => 'short'
19-
],
20-
'single_quote' => true,
21-
'class_attributes_separation' => true,
22-
'no_unused_imports' => true,
23-
'standardize_not_equals' => true,
24-
'declare_strict_types' => true,
25-
])
26-
->setFinder(
27-
PhpCsFixer\Finder::create()
28-
// ->exclude('test')
29-
->exclude('docs')
30-
->exclude('vendor')
31-
->in(__DIR__)
32-
)
33-
->setUsingCache(false);
8+
return PhpCsFixer\Config::create()->setRiskyAllowed(true)->setRules([
9+
'@PSR2' => true,
10+
// 'header_comment' => [
11+
// 'comment_type' => 'PHPDoc',
12+
// 'header' => $header,
13+
// 'separate' => 'none'
14+
// ],
15+
'array_syntax' => [
16+
'syntax' => 'short'
17+
],
18+
'single_quote' => true,
19+
'class_attributes_separation' => true,
20+
'no_unused_imports' => true,
21+
'standardize_not_equals' => true,
22+
'declare_strict_types' => true,
23+
])->setFinder(PhpCsFixer\Finder::create()
24+
// ->exclude('test')
25+
->exclude('docs')->exclude('vendor')->in(__DIR__))->setUsingCache(false);

phpunit.xml.dist

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
convertWarningsToExceptions="true"
1010
stopOnFailure="false"
1111
>
12-
<testsuites>
13-
<testsuite name="Php Validate-Filter Test Suite">
14-
<directory>test</directory>
15-
</testsuite>
16-
</testsuites>
12+
<testsuites>
13+
<testsuite name="Php Validate-Filter Test Suite">
14+
<directory>test</directory>
15+
</testsuite>
16+
</testsuites>
1717

18-
<filter>
19-
<whitelist>
20-
<directory suffix=".php">src</directory>
21-
</whitelist>
22-
</filter>
18+
<filter>
19+
<whitelist>
20+
<directory suffix=".php">src</directory>
21+
</whitelist>
22+
</filter>
2323
</phpunit>

src/AbstractValidation.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/**
1414
* Class AbstractValidation
15+
*
1516
* @package Inhere\Validate
1617
*/
1718
abstract class AbstractValidation implements ValidationInterface
@@ -44,10 +45,7 @@ public function __construct(
4445
bool $startValidate = false
4546
) {
4647
$this->data = $data;
47-
$this
48-
->atScene($scene)
49-
->setRules($rules)
50-
->setTranslates($translates);
48+
$this->atScene($scene)->setRules($rules)->setTranslates($translates);
5149

5250
if ($startValidate) {
5351
$this->validate();

src/FV.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* Class FV - the short name of the field validation
7+
*
78
* @package Inhere\Validate
89
*/
910
final class FV extends FieldValidation

src/Filter/FilteringTrait.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/**
2121
* Trait FilteringTrait
22+
*
2223
* @package Inhere\Validate\Filter
2324
*/
2425
trait FilteringTrait
@@ -31,19 +32,19 @@ trait FilteringTrait
3132
*
3233
* @param mixed $value
3334
* @param string|array $filters
34-
* string:
35-
* 'string|trim|upper'
36-
* array:
37-
* [
38-
* 'string',
39-
* 'trim',
40-
* ['Class', 'method'],
41-
* // 追加额外参数. 传入时,第一个参数总是要过滤的字段值,其余的依次追加
42-
* 'myFilter' => ['arg1', 'arg2'],
43-
* function($val) {
35+
* string:
36+
* 'string|trim|upper'
37+
* array:
38+
* [
39+
* 'string',
40+
* 'trim',
41+
* ['Class', 'method'],
42+
* // 追加额外参数. 传入时,第一个参数总是要过滤的字段值,其余的依次追加
43+
* 'myFilter' => ['arg1', 'arg2'],
44+
* function($val) {
4445
* return str_replace(' ', '', $val);
45-
* },
46-
* ]
46+
* },
47+
* ]
4748
*
4849
* @return mixed
4950
* @throws InvalidArgumentException

src/Filter/Filters.php

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@
4848
use const FILTER_UNSAFE_RAW;
4949
use const FILTER_VALIDATE_BOOLEAN;
5050
use const MB_CASE_TITLE;
51+
use const PHP_VERSION_ID;
5152

5253
/**
5354
* Class Filters
55+
*
5456
* @package Inhere\Validate\Filter
5557
*/
5658
final class Filters
@@ -109,6 +111,7 @@ public static function bool($val, $nullAsFalse = false): bool
109111

110112
/**
111113
* 过滤器删除数字中所有非法的字符。
114+
*
112115
* @note 该过滤器允许所有数字以及 . + -
113116
*
114117
* @param mixed $val 要过滤的变量
@@ -145,14 +148,15 @@ public static function abs($val): int
145148

146149
/**
147150
* 过滤器删除浮点数中所有非法的字符。
151+
*
148152
* @note 该过滤器默认允许所有数字以及 + -
149153
*
150-
* @param mixed $val 要过滤的变量
154+
* @param mixed $val 要过滤的变量
151155
* @param null|int $decimal
152156
* @param int $flags 标志
153-
* FILTER_FLAG_ALLOW_FRACTION - 允许小数分隔符 (比如 .)
154-
* FILTER_FLAG_ALLOW_THOUSAND - 允许千位分隔符(比如 ,)
155-
* FILTER_FLAG_ALLOW_SCIENTIFIC - 允许科学记数法(比如 e 和 E)
157+
* FILTER_FLAG_ALLOW_FRACTION - 允许小数分隔符 (比如 .)
158+
* FILTER_FLAG_ALLOW_THOUSAND - 允许千位分隔符(比如 ,)
159+
* FILTER_FLAG_ALLOW_SCIENTIFIC - 允许科学记数法(比如 e 和 E)
156160
*
157161
* @return mixed
158162
*/
@@ -175,12 +179,12 @@ public static function float($val, $decimal = null, $flags = FILTER_FLAG_ALLOW_F
175179
*
176180
* @param string|array $val
177181
* @param int $flags 标志
178-
* FILTER_FLAG_NO_ENCODE_QUOTES - 该标志不编码引号
179-
* FILTER_FLAG_STRIP_LOW - 去除 ASCII 值在 32 以下的字符
180-
* FILTER_FLAG_STRIP_HIGH - 去除 ASCII 值在 127 以上的字符
181-
* FILTER_FLAG_ENCODE_LOW - 编码 ASCII 值在 32 以下的字符
182-
* FILTER_FLAG_ENCODE_HIGH - 编码 ASCII 值在 127 以上的字符
183-
* FILTER_FLAG_ENCODE_AMP - 把 & 字符编码为 &amp;
182+
* FILTER_FLAG_NO_ENCODE_QUOTES - 该标志不编码引号
183+
* FILTER_FLAG_STRIP_LOW - 去除 ASCII 值在 32 以下的字符
184+
* FILTER_FLAG_STRIP_HIGH - 去除 ASCII 值在 127 以上的字符
185+
* FILTER_FLAG_ENCODE_LOW - 编码 ASCII 值在 32 以下的字符
186+
* FILTER_FLAG_ENCODE_HIGH - 编码 ASCII 值在 127 以上的字符
187+
* FILTER_FLAG_ENCODE_AMP - 把 & 字符编码为 &amp;
184188
*
185189
* @return string|array
186190
*/
@@ -276,7 +280,7 @@ public static function lower($val): string
276280
public static function lowercase($val): string
277281
{
278282
if (!$val || !is_string($val)) {
279-
return is_int($val) ? (string)$val: '';
283+
return is_int($val) ? (string)$val : '';
280284
}
281285

282286
if (function_exists('mb_strtolower')) {
@@ -533,14 +537,15 @@ public static function stripTags($val, $allowedTags = null): string
533537

534538
/**
535539
* 去除 URL 编码不需要的字符。
540+
*
536541
* @note 与 urlencode() 函数很类似。
537542
*
538-
* @param string $val 要过滤的数据
543+
* @param string $val 要过滤的数据
539544
* @param int $flags 标志
540-
* FILTER_FLAG_STRIP_LOW - 去除 ASCII 值在 32 以下的字符
541-
* FILTER_FLAG_STRIP_HIGH - 去除 ASCII 值在 32 以上的字符
542-
* FILTER_FLAG_ENCODE_LOW - 编码 ASCII 值在 32 以下的字符
543-
* FILTER_FLAG_ENCODE_HIGH - 编码 ASCII 值在 32 以上的字符
545+
* FILTER_FLAG_STRIP_LOW - 去除 ASCII 值在 32 以下的字符
546+
* FILTER_FLAG_STRIP_HIGH - 去除 ASCII 值在 32 以上的字符
547+
* FILTER_FLAG_ENCODE_LOW - 编码 ASCII 值在 32 以下的字符
548+
* FILTER_FLAG_ENCODE_HIGH - 编码 ASCII 值在 32 以上的字符
544549
*
545550
* @return string
546551
*/
@@ -560,17 +565,23 @@ public static function encoded(string $val, int $flags = 0): string
560565
*/
561566
public static function quotes(string $val): string
562567
{
563-
return (string)filter_var($val, FILTER_SANITIZE_MAGIC_QUOTES);
568+
$flag = FILTER_SANITIZE_MAGIC_QUOTES;
569+
if (PHP_VERSION_ID > 70300) {
570+
/** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */
571+
$flag = FILTER_SANITIZE_ADD_SLASHES;
572+
}
573+
574+
return (string)filter_var($val, $flag);
564575
}
565576

566577
/**
567578
* like htmlspecialchars(), HTML 转义字符 '"<>& 以及 ASCII 值小于 32 的字符。
568579
*
569580
* @param string $val
570581
* @param int $flags 标志
571-
* FILTER_FLAG_STRIP_LOW - 去除 ASCII 值在 32 以下的字符
572-
* FILTER_FLAG_STRIP_HIGH - 去除 ASCII 值在 32 以上的字符
573-
* FILTER_FLAG_ENCODE_HIGH - 编码 ASCII 值在 32 以上的字符
582+
* FILTER_FLAG_STRIP_LOW - 去除 ASCII 值在 32 以下的字符
583+
* FILTER_FLAG_STRIP_HIGH - 去除 ASCII 值在 32 以上的字符
584+
* FILTER_FLAG_ENCODE_HIGH - 编码 ASCII 值在 32 以上的字符
574585
*
575586
* @return string
576587
*/
@@ -639,6 +650,7 @@ public static function cut($string, $start = 0, $length = 0): string
639650

640651
/**
641652
* url地址过滤 移除所有不符合 url 的字符
653+
*
642654
* @note 该过滤器允许所有的字母、数字以及 $-_.+!*'(),{}|\^~[]`"><#%;/?:@&=
643655
*
644656
* @param string $val 要过滤的数据
@@ -677,11 +689,11 @@ public static function email($val): string
677689
*
678690
* @param string $string
679691
* @param int $flags 标志
680-
* FILTER_FLAG_STRIP_LOW - 去除 ASCII 值在 32 以下的字符
681-
* FILTER_FLAG_STRIP_HIGH - 去除 ASCII 值在 32 以上的字符
682-
* FILTER_FLAG_ENCODE_LOW - 编码 ASCII 值在 32 以下的字符
683-
* FILTER_FLAG_ENCODE_HIGH - 编码 ASCII 值在 32 以上的字符
684-
* FILTER_FLAG_ENCODE_AMP - 把 & 字符编码为 &amp;
692+
* FILTER_FLAG_STRIP_LOW - 去除 ASCII 值在 32 以下的字符
693+
* FILTER_FLAG_STRIP_HIGH - 去除 ASCII 值在 32 以上的字符
694+
* FILTER_FLAG_ENCODE_LOW - 编码 ASCII 值在 32 以下的字符
695+
* FILTER_FLAG_ENCODE_HIGH - 编码 ASCII 值在 32 以上的字符
696+
* FILTER_FLAG_ENCODE_AMP - 把 & 字符编码为 &amp;
685697
*
686698
* @return string|mixed
687699
*/

src/Filter/Filtration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
/**
1616
* Class Filtration
17+
*
1718
* @package Inhere\Validate\Filter
1819
* usage:
1920
*

src/Filter/UserFilters.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
/**
1212
* Class UserFilters - user custom add global filters
13+
*
1314
* @package Inhere\Validate\Filter
1415
*/
1516
final class UserFilters

src/Helper.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@
3838

3939
/**
4040
* Class Helper
41+
*
4142
* @package Inhere\Validate\Utils
4243
*/
4344
class Helper
4445
{
45-
public const IS_TRUE = '|yes|on|1|true|';
46+
public const IS_TRUE = '|yes|on|1|true|';
4647

4748
public const IS_FALSE = '|no|off|0|false|';
4849

49-
public const IS_BOOL = '|yes|on|1|true|no|off|0|false|';
50+
public const IS_BOOL = '|yes|on|1|true|no|off|0|false|';
5051

5152
/**
5253
* known image mime types
54+
*
5355
* @link https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
5456
*/
5557
public static $imgMimeTypes = [
@@ -318,7 +320,7 @@ public static function compareSize($val, string $operator, $expected): bool
318320
}
319321

320322
/**
321-
* @param mixed $val
323+
* @param mixed $val
322324
* @param array $list
323325
*
324326
* @return bool

src/RV.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* Class RV - the short name of the rule validation
7+
*
78
* @package Inhere\Validate
89
*/
910
final class RV extends Validation

src/RuleValidation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* ['field1, field3, ... ', 'validator', ...]
1919
* ]
2020
* ```
21+
*
2122
* @package Inhere\Validate
2223
*/
2324
class RuleValidation extends Validation

0 commit comments

Comments
 (0)