Skip to content

Commit fd3cced

Browse files
vuongxuongminhStyleCIBot
authored andcommitted
Apply fixes from StyleCI
1 parent d384a36 commit fd3cced

17 files changed

+4146
-6181
lines changed

resource/ip-v4-range.php

Lines changed: 3131 additions & 4694 deletions
Large diffs are not rendered by default.

resource/ip-v6-range.php

Lines changed: 955 additions & 1430 deletions
Large diffs are not rendered by default.

src/Exceptions/IdVNException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
@@ -11,11 +12,11 @@
1112

1213
/**
1314
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
*
1416
* @since 1.0.0
1517
*/
1618
class IdVNException extends ValidationException
1719
{
18-
1920
public static $defaultTemplates = [
2021
self::MODE_DEFAULT => [
2122
self::STANDARD => '{{name}} must be a valid Viet Nam id number',
@@ -24,5 +25,4 @@ class IdVNException extends ValidationException
2425
self::STANDARD => '{{name}} must be a valid Viet Nam id number',
2526
],
2627
];
27-
2828
}

src/Exceptions/IpVNException.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
@@ -11,23 +12,23 @@
1112

1213
/**
1314
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
*
1416
* @since 1.0.0
1517
*/
1618
class IpVNException extends ValidationException
1719
{
18-
1920
const STANDARD = 0;
2021

2122
const VERSION = 1;
2223

2324
public static $defaultTemplates = [
2425
self::MODE_DEFAULT => [
2526
self::STANDARD => '{{name}} must be an IP address of Viet Nam',
26-
self::VERSION => '{{name}} must be an IP version {{version}}'
27+
self::VERSION => '{{name}} must be an IP version {{version}}',
2728
],
2829
self::MODE_NEGATIVE => [
2930
self::STANDARD => '{{name}} must be an IP address of Viet Nam',
30-
self::VERSION => '{{name}} must be an IP version {{version}}'
31+
self::VERSION => '{{name}} must be an IP version {{version}}',
3132
],
3233
];
3334

src/Exceptions/LandLineVNException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
@@ -11,11 +12,11 @@
1112

1213
/**
1314
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
*
1416
* @since 1.0.0
1517
*/
1618
class LandLineVNException extends ValidationException
1719
{
18-
1920
public static $defaultTemplates = [
2021
self::MODE_DEFAULT => [
2122
self::STANDARD => '{{name}} must be a valid Viet Nam land line phone number',
@@ -24,5 +25,4 @@ class LandLineVNException extends ValidationException
2425
self::STANDARD => '{{name}} must be a valid Viet Nam land line phone number',
2526
],
2627
];
27-
2828
}

src/Exceptions/MobileVNException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
@@ -11,11 +12,11 @@
1112

1213
/**
1314
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
*
1416
* @since 1.0.0
1517
*/
1618
class MobileVNException extends ValidationException
1719
{
18-
1920
public static $defaultTemplates = [
2021
self::MODE_DEFAULT => [
2122
self::STANDARD => '{{name}} must be a valid Viet Nam mobile phone number',
@@ -24,5 +25,4 @@ class MobileVNException extends ValidationException
2425
self::STANDARD => '{{name}} must be a valid Viet Nam mobile phone number',
2526
],
2627
];
27-
2828
}

src/Rules/AbstractStaticRegexRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
@@ -11,16 +12,15 @@
1112

1213
/**
1314
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
*
1416
* @since 1.0.0
1517
*/
1618
abstract class AbstractStaticRegexRule extends AbstractRegexRule
1719
{
18-
1920
protected function getPregFormat()
2021
{
2122
return static::pregFormat();
2223
}
2324

2425
abstract public static function pregFormat(): string;
25-
2626
}

src/Rules/IdVN.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
@@ -9,18 +10,18 @@
910

1011
/**
1112
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
*
1214
* @since 1.0.0
1315
*/
1416
class IdVN extends AbstractStaticRegexRule
1517
{
16-
1718
public static function pregFormat(): string
1819
{
1920
$id = self::idPregFormatPart(false);
2021
$oldId = self::idPregFormatPart(true);
2122
$cId = self::cIdPregFormatPart();
2223

23-
return '~^((' . implode(')|(', [$id, $oldId, $cId]) . '))$~';
24+
return '~^(('.implode(')|(', [$id, $oldId, $cId]).'))$~';
2425
}
2526

2627
private static function idPregFormatPart(bool $old): string
@@ -36,16 +37,16 @@ private static function idPregFormatPart(bool $old): string
3637
'0[0-8]',
3738
'1[0-9]',
3839
'2[0-9]',
39-
'3[0-8]'
40+
'3[0-8]',
4041
]),
4142
'::head2::' => implode('|', [
4243
'09[015]',
4344
'23[01]',
4445
'245',
45-
'28[015]'
46+
'28[015]',
4647
]),
4748
'::range1::' => $range1,
48-
'::range2::' => $range2
49+
'::range2::' => $range2,
4950
]);
5051
}
5152

@@ -62,8 +63,8 @@ private static function cIdPregFormatPart(): string
6263
'6[024678]',
6364
'7[024579]',
6465
'8[0234679]',
65-
'9[1-6]'
66-
])
66+
'9[1-6]',
67+
]),
6768
]);
6869
}
6970
}

src/Rules/IpVN.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
78

89
namespace PHPViet\Validation\Rules;
910

10-
use IPLib\Factory as IpFactory;
11-
use IPLib\Address\Type as IpType;
1211
use IPLib\Address\AddressInterface as IpInterface;
12+
use IPLib\Address\Type as IpType;
13+
use IPLib\Factory as IpFactory;
1314
use Respect\Validation\Rules\AbstractRule;
1415

1516
/**
1617
* @author Vuong Minh <vuongxuongminh@gmail.com>
18+
*
1719
* @since 1.0.0
1820
*/
1921
class IpVN extends AbstractRule
@@ -32,17 +34,14 @@ public function __construct($version = null)
3234
public function validate($input)
3335
{
3436
if (!$ip = IpFactory::addressFromString($input)) {
35-
3637
return false;
3738
}
3839

3940
if (($version = $ip->getAddressType()) !== $this->version && null !== $this->version) {
40-
4141
return false;
4242
}
4343

4444
if (!$ranges = $this->getIpRanges($input, $version)) {
45-
4645
return false;
4746
}
4847

@@ -60,15 +59,13 @@ protected function getIpRanges(string $ip, int $version): ?array
6059
}
6160

6261
while (!is_null($key = array_shift($keys))) {
63-
6462
if (isset($map[$key])) {
6563
$map = $map[$key];
6664

6765
continue;
6866
}
6967

7068
if (isset($map['range'])) {
71-
7269
return $map['range'];
7370
}
7471

@@ -79,11 +76,9 @@ protected function getIpRanges(string $ip, int $version): ?array
7976
protected function validateIpInRange(IpInterface $ip, array $ranges)
8077
{
8178
foreach ($ranges as $range) {
82-
8379
[$begin, $end] = $range;
8480

8581
if (($subnet = IpFactory::rangeFromBoundaries($begin, $end)) && $subnet->contains($ip)) {
86-
8782
return true;
8883
}
8984
}
@@ -96,7 +91,7 @@ protected static function getIpV4Range(): array
9691
static $range = null;
9792

9893
if (null === $range) {
99-
$range = require(__DIR__ . '/../../resource/ip-v4-range.php');
94+
$range = require __DIR__.'/../../resource/ip-v4-range.php';
10095
}
10196

10297
return $range;
@@ -107,10 +102,9 @@ protected static function getIpV6Range(): array
107102
static $range = null;
108103

109104
if (null === $range) {
110-
$range = require(__DIR__ . '/../../resource/ip-v6-range.php');
105+
$range = require __DIR__.'/../../resource/ip-v6-range.php';
111106
}
112107

113108
return $range;
114109
}
115-
116110
}

src/Rules/LandLineVN.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
@@ -9,11 +10,11 @@
910

1011
/**
1112
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
*
1214
* @since 1.0.0
1315
*/
1416
class LandLineVN extends AbstractStaticRegexRule
1517
{
16-
1718
public static function pregFormat(): string
1819
{
1920
return strtr('~^(\+?84|0)(::head::)\d{7}$~', [
@@ -27,8 +28,8 @@ public static function pregFormat(): string
2728
'26[0-39]',
2829
'27[0-7]',
2930
'28[0-9]',
30-
'29[0-4679]'
31-
])
31+
'29[0-4679]',
32+
]),
3233
]);
3334
}
3435
}

src/Rules/MobileVN.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
@@ -9,11 +10,11 @@
910

1011
/**
1112
* @author Vuong Minh <vuongxuongminh@gmail.com>
13+
*
1214
* @since 1.0.0
1315
*/
1416
class MobileVN extends AbstractStaticRegexRule
1517
{
16-
1718
public static function pregFormat(): string
1819
{
1920
return strtr('~^(\+?84|0)(::head::)\d{7}$~', [
@@ -23,8 +24,7 @@ public static function pregFormat(): string
2324
'7(0|[6-9])',
2425
'8[1-9]',
2526
'9[0-9]',
26-
])
27+
]),
2728
]);
2829
}
29-
3030
}

src/Validator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
22
/**
33
* @link https://github.com/phpviet/validation
4+
*
45
* @copyright (c) PHP Viet
56
* @license [MIT](https://opensource.org/licenses/MIT)
67
*/
78

89
namespace PHPViet\Validation;
910

10-
use Respect\Validation\Validator as BaseValidator;
1111
use Respect\Validation\Factory;
12+
use Respect\Validation\Validator as BaseValidator;
1213

1314
/**
1415
* @method static Validator landLineVN()
@@ -17,11 +18,11 @@
1718
* @method static Validator idVN()
1819
*
1920
* @author Vuong Minh <vuongxuongminh@gmail.com>
21+
*
2022
* @since 1.0.0
2123
*/
2224
class Validator extends BaseValidator
2325
{
24-
2526
/**
2627
* @return Factory
2728
*/
@@ -44,5 +45,4 @@ public static function setFactory($factory)
4445

4546
static::$factory = $factory;
4647
}
47-
4848
}

0 commit comments

Comments
 (0)