Skip to content

Commit 46a379e

Browse files
committed
add strict_types on file head
1 parent f267dd3 commit 46a379e

27 files changed

+173
-115
lines changed

.php_cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
$header = <<<'EOF'
4+
5+
@license https://github.com/inhere/php-validate/blob/master/LICENSE
6+
EOF;
7+
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);

.travis.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
language: php
22

33
php:
4-
- '7.1'
5-
- '7.2'
6-
- '7.3'
4+
- '7.1'
5+
- '7.2'
6+
- '7.3'
7+
- '7.4'
78

89
#matrix:
910
# include:
1011
# - php: 7.2
1112
# env: ANALYSIS='true'
1213

14+
install:
15+
- |
16+
wget -O bin/php-cs-fixer "https://cs.symfony.com/download/php-cs-fixer-v2.phar"
17+
chmod +x bin/php-cs-fixer
18+
1319
before_script:
14-
- php -m
15-
- composer require php-coveralls/php-coveralls:^2.1.0
20+
- php -m
21+
- composer require php-coveralls/php-coveralls:^2.1.0
1622

1723
script:
18-
# - phpunit --coverage-clover clover.xml
19-
- php vendor/bin/phpunit --coverage-clover clover.xml
24+
# check code style
25+
# - composer check-cs
26+
# - phpunit --coverage-clover clover.xml
27+
- php vendor/bin/phpunit --coverage-clover clover.xml
2028

2129
after_success:
22-
- vendor/bin/php-coveralls --coverage_clover=clover.xml --json_path=coveralls-upload.json -v
30+
- vendor/bin/php-coveralls --coverage_clover=clover.xml --json_path=coveralls-upload.json -v

composer.json

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
{
2-
"name": "inhere/php-validate",
3-
"type": "library",
4-
"description": "an simple validate, filter library of the php",
5-
"keywords": [
6-
"php-library",
7-
"library",
8-
"validate",
9-
"form-validate",
10-
"validation"
11-
],
12-
"homepage": "https://github.com/inhere/php-validate",
13-
"license": "MIT",
14-
"authors": [
15-
{
16-
"name": "inhere",
17-
"email": "in.798@qq.com",
18-
"homepage": "http://www.yzone.net/"
19-
}
20-
],
21-
"require": {
22-
"php": ">7.1.0"
23-
},
24-
"require-dev": {
25-
"phpunit/phpunit": "^7.5"
26-
},
27-
"autoload": {
28-
"psr-4": {
29-
"Inhere\\Validate\\": "src/"
30-
}
31-
},
32-
"autoload-dev": {
33-
"psr-4": {
34-
"Inhere\\ValidateTest\\": "test/"
35-
}
2+
"name": "inhere/php-validate",
3+
"type": "library",
4+
"description": "an simple validate, filter library of the php",
5+
"keywords": [
6+
"php-library",
7+
"library",
8+
"validate",
9+
"form-validate",
10+
"validation"
11+
],
12+
"homepage": "https://github.com/inhere/php-validate",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "inhere",
17+
"email": "in.798@qq.com",
18+
"homepage": "http://www.yzone.net/"
3619
}
20+
],
21+
"require": {
22+
"php": ">7.1.0"
23+
},
24+
"require-dev": {
25+
"phpunit/phpunit": "^7.5"
26+
},
27+
"autoload": {
28+
"psr-4": {
29+
"Inhere\\Validate\\": "src/"
30+
}
31+
},
32+
"autoload-dev": {
33+
"psr-4": {
34+
"Inhere\\ValidateTest\\": "test/"
35+
}
36+
},
37+
"scripts": {
38+
"check-cs": "./bin/php-cs-fixer fix --dry-run --diff --diff-format=udiff",
39+
"cs-fix": "./bin/php-cs-fixer fix"
40+
}
3741
}

docs/Valid.php

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,74 @@
22

33
namespace Inhere\Validate;
44

5+
use function array_merge;
6+
57
/**
68
* Class Valid - Simple Data Validator
9+
*
710
* @package Inhere\Validate
811
*/
912
class Valid
1013
{
1114
/**
1215
* @var array
1316
*/
14-
protected $data = [];
17+
protected static $data = [];
1518

1619
/**
1720
* @param array $data
18-
*
19-
* @return Valid
2021
*/
21-
public static function create(array $data): self
22+
public static function load(array $data): void
2223
{
23-
return new static($data);
24+
self::$data = $data;
2425
}
2526

2627
/**
27-
* Validator constructor.
28-
*
2928
* @param array $data
3029
*/
31-
public function __construct(array $data)
32-
{
33-
$this->data = $data;
34-
}
35-
36-
public function getInt(string $field, $min = null, $max = null, $default = 0): int
30+
public static function append(array $data): void
3731
{
38-
return 0;
32+
self::$data = array_merge(self::$data, $data);
3933
}
4034

4135
/**
4236
* @return array
4337
*/
4438
public function getData(): array
4539
{
46-
return $this->data;
40+
return self::$data;
4741
}
4842

43+
/**********************************************************************************************
44+
* =========== validate data field value and return
45+
*********************************************************************************************/
46+
4947
/**
50-
* @param array $data
48+
* @param string $field
49+
* @param null|int $min
50+
* @param null|int $max
51+
* @param null|int $default
52+
*
53+
* @return int
5154
*/
52-
public function setData(array $data): void
55+
public static function getInt(string $field, int $min = null, int $max = null, int $default = null): int
56+
{
57+
return 0;
58+
}
59+
60+
public static function getInts(string $field, int $min = null, int $max = null, int $default = 0): int
61+
{
62+
return 0;
63+
}
64+
65+
public static function getString(string $field, int $minLen = null, int $maxLen = null, string $default = null): int
5366
{
54-
$this->data = $data;
67+
return 0;
68+
}
69+
70+
public static function getStrings(string $field, int $min = null, int $max = null, array $default = null): int
71+
{
72+
return 0;
5573
}
74+
5675
}

src/AbstractValidation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Created by PhpStorm.
44
* User: inhere

src/ArrayValueNotExists.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Inhere\Validate;
44

src/FV.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Inhere\Validate;
44

@@ -8,5 +8,4 @@
88
*/
99
final class FV extends FieldValidation
1010
{
11-
1211
}

src/FieldValidation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Created by PhpStorm.
44
* User: inhere

src/Filter/FilteringTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Created by PhpStorm.
44
* User: Inhere
@@ -63,14 +63,14 @@ protected function valueFiltering($value, $filters)
6363
$args = (array)$filter;
6464
$value = $this->callStringCallback($key, $value, ...$args);
6565

66-
// closure
66+
// closure
6767
} elseif (is_object($filter) && method_exists($filter, '__invoke')) {
6868
$value = $filter($value);
69-
// string, trim, ....
69+
// string, trim, ....
7070
} elseif (is_string($filter)) {
7171
$value = $this->callStringCallback($filter, $value);
7272

73-
// e.g ['Class', 'method'],
73+
// e.g ['Class', 'method'],
7474
} else {
7575
$value = Helper::call($filter, $value);
7676
}
@@ -94,21 +94,21 @@ protected function callStringCallback(string $filter, ...$args)
9494
// if $filter is a custom by addFiler()
9595
if ($callback = $this->getFilter($filter)) {
9696
$value = $callback(...$args);
97-
// if $filter is a custom method of the subclass.
97+
// if $filter is a custom method of the subclass.
9898
} elseif (method_exists($this, $filter . 'Filter')) {
9999
$filter .= 'Filter';
100100
$value = $this->$filter(...$args);
101101

102-
// if $filter is a custom add callback in the property {@see $_filters}.
102+
// if $filter is a custom add callback in the property {@see $_filters}.
103103
} elseif ($callback = UserFilters::get($filter)) {
104104
$value = $callback(...$args);
105105

106-
// if $filter is a custom add callback in the property {@see $_filters}.
106+
// if $filter is a custom add callback in the property {@see $_filters}.
107107
// $filter is a method of the class 'FilterList'
108108
} elseif (method_exists(Filters::class, $filterName)) {
109109
$value = Filters::$filterName(...$args);
110110

111-
// it is function name
111+
// it is function name
112112
} elseif (function_exists($filter)) {
113113
$value = $filter(...$args);
114114
} else {

src/Filter/Filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* @date 2015.08.05 sanitize
44
* 过滤器(strainer/filter): 过滤数据,去除不合要求的数据,返回过滤后的数据(始终返回字符串, 全部不符合返回空字符串)

0 commit comments

Comments
 (0)