Skip to content

Commit 7ab2014

Browse files
Merge pull request #1 from phpviet/analysis-XNVGOe
Apply fixes from StyleCI
2 parents f3c2ae5 + ee351ab commit 7ab2014

12 files changed

+75
-88
lines changed

src/Bootstrap.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@
88

99
namespace phpviet\yii\validation;
1010

11+
use phpviet\yii\validation\validators\IdVNValidator;
12+
use phpviet\yii\validation\validators\IpVNValidator;
13+
use phpviet\yii\validation\validators\LandLineVNValidator;
14+
use phpviet\yii\validation\validators\MobileVNValidator;
1115
use yii\base\BootstrapInterface;
1216
use yii\i18n\I18N;
1317
use yii\validators\Validator;
1418

15-
use phpviet\yii\validation\validators\LandLineVNValidator;
16-
use phpviet\yii\validation\validators\MobileVNValidator;
17-
use phpviet\yii\validation\validators\IdVNValidator;
18-
use phpviet\yii\validation\validators\IpVNValidator;
19-
2019
/**
2120
* @author Vuong Minh <[email protected]>
21+
*
2222
* @since 1.0.0
2323
*/
2424
class Bootstrap implements BootstrapInterface
2525
{
26-
2726
/**
28-
* @inheritDoc
27+
* {@inheritdoc}
2928
*/
3029
public function bootstrap($app): void
3130
{
@@ -41,11 +40,11 @@ public function bootstrap($app): void
4140
protected function loadTrans(I18N $i18n): void
4241
{
4342
$i18n->translations['phpviet/validation'] = array_merge([
44-
'class' => 'yii\i18n\PhpMessageSource',
43+
'class' => 'yii\i18n\PhpMessageSource',
4544
'basePath' => '@phpviet/yii/validation/messages',
46-
'fileMap' => [
47-
'phpviet/validation' => 'validation.php'
48-
]
45+
'fileMap' => [
46+
'phpviet/validation' => 'validation.php',
47+
],
4948
], $i18n->translations['phpviet/validation'] ?? []);
5049
}
5150

@@ -56,17 +55,17 @@ protected function loadShortValidators(): void
5655
{
5756
Validator::$builtInValidators = array_merge(Validator::$builtInValidators, [
5857
'land_line_vn' => LandLineVNValidator::class,
59-
'mobile_vn' => MobileVNValidator::class,
60-
'id_vn' => IdVNValidator::class,
61-
'ip_vn' => IpVNValidator::class,
62-
'ipv4_vn' => [
63-
'class' => IpVNValidator::class,
64-
'version' => IpVNValidator::IPV4
58+
'mobile_vn' => MobileVNValidator::class,
59+
'id_vn' => IdVNValidator::class,
60+
'ip_vn' => IpVNValidator::class,
61+
'ipv4_vn' => [
62+
'class' => IpVNValidator::class,
63+
'version' => IpVNValidator::IPV4,
6564
],
6665
'ipv6_vn' => [
67-
'class' => IpVNValidator::class,
68-
'version' => IpVNValidator::IPV6
69-
]
66+
'class' => IpVNValidator::class,
67+
'version' => IpVNValidator::IPV6,
68+
],
7069
]);
7170
}
7271
}

src/messages/vi/validation.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88

99
return [
10-
'{attribute} must be an id number of Vietnam.' => '{attribute} phải là số chứng minh thư hoặc thẻ căn cước tại Việt Nam.',
11-
'{attribute} must be a mobile phone number of Vietnam.' => '{attribute} phải là số di động tại Việt Nam.',
10+
'{attribute} must be an id number of Vietnam.' => '{attribute} phải là số chứng minh thư hoặc thẻ căn cước tại Việt Nam.',
11+
'{attribute} must be a mobile phone number of Vietnam.' => '{attribute} phải là số di động tại Việt Nam.',
1212
'{attribute} must be a land line phone number of Vietnam.' => '{attribute} phải là số điện thoại bàn tại Việt Nam.',
13-
'{attribute} must be Vietnam ip.' => '{attribute} phải là ip Việt Nam.',
14-
'{attribute} must be Vietnam ipv4.' => '{attribute} phải là ipv4 tại Việt Nam.',
15-
'{attribute} must be Vietnam ipv6.' => '{attribute} phải là ipv6 tại Việt Nam.',
13+
'{attribute} must be Vietnam ip.' => '{attribute} phải là ip Việt Nam.',
14+
'{attribute} must be Vietnam ipv4.' => '{attribute} phải là ipv4 tại Việt Nam.',
15+
'{attribute} must be Vietnam ipv6.' => '{attribute} phải là ipv6 tại Việt Nam.',
1616
];

src/validators/IdVNValidator.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88

99
namespace phpviet\yii\validation\validators;
1010

11+
use PHPViet\Validation\Rules\IdVN as PatternProvider;
1112
use Yii;
12-
1313
use yii\validators\RegularExpressionValidator;
1414

15-
use PHPViet\Validation\Rules\IdVN as PatternProvider;
16-
1715
/**
1816
* @author Vuong Minh <[email protected]>
17+
*
1918
* @since 1.0.0
2019
*/
2120
class IdVNValidator extends RegularExpressionValidator
2221
{
23-
2422
/**
25-
* @inheritDoc
23+
* {@inheritdoc}
2624
*/
2725
public function init()
2826
{
@@ -31,5 +29,4 @@ public function init()
3129

3230
parent::init();
3331
}
34-
3532
}

src/validators/IpVNValidator.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88

99
namespace phpviet\yii\validation\validators;
1010

11+
use PHPViet\Validation\Rules\IpVN as ConcreteIpVN;
12+
use PHPViet\Validation\Validator as ConcreteValidator;
1113
use Yii;
12-
13-
use yii\validators\Validator;
1414
use yii\validators\IpValidator;
15-
16-
use PHPViet\Validation\Validator as ConcreteValidator;
17-
use PHPViet\Validation\Rules\IpVN as ConcreteIpVN;
15+
use yii\validators\Validator;
1816

1917
/**
2018
* @author Vuong Minh <[email protected]>
19+
*
2120
* @since 1.0.0
2221
*/
2322
class IpVNValidator extends Validator
2423
{
25-
2624
const IPV4 = ConcreteIpVN::IPV4;
2725

2826
const IPV6 = ConcreteIpVN::IPV6;
@@ -33,7 +31,7 @@ class IpVNValidator extends Validator
3331
public $version;
3432

3533
/**
36-
* @inheritDoc
34+
* {@inheritdoc}
3735
*/
3836
public function init()
3937
{
@@ -43,20 +41,20 @@ public function init()
4341
}
4442

4543
/**
46-
* @inheritDoc
44+
* {@inheritdoc}
4745
*/
4846
public function validateValue($value)
4947
{
5048
if (ConcreteValidator::ipVN($this->version)->validate($value)) {
51-
52-
return null;
49+
return;
5350
}
5451

5552
return [$this->message, []];
5653
}
5754

5855
/**
59-
* @inheritDoc
56+
* {@inheritdoc}
57+
*
6058
* @throws \yii\base\InvalidConfigException
6159
*/
6260
public function clientValidateAttribute($model, $attribute, $view)
@@ -65,7 +63,8 @@ public function clientValidateAttribute($model, $attribute, $view)
6563
}
6664

6765
/**
68-
* @inheritDoc
66+
* {@inheritdoc}
67+
*
6968
* @throws \yii\base\InvalidConfigException
7069
*/
7170
public function getClientOptions($model, $attribute)
@@ -74,7 +73,7 @@ public function getClientOptions($model, $attribute)
7473
}
7574

7675
/**
77-
* @inheritDoc
76+
* {@inheritdoc}
7877
*/
7978
protected function getDefaultMessage(): string
8079
{
@@ -90,30 +89,31 @@ protected function getDefaultMessage(): string
9089

9190
/**
9291
* @var IpValidator
92+
*
9393
* @see getClientIpValidator()
9494
*/
9595
private $_clientIpValidator;
9696

9797
/**
9898
* Trả về [[IpValidator]] hổ trợ cho việc tạo js validator tại client.
9999
*
100-
* @return IpValidator
101100
* @throws \yii\base\InvalidConfigException
101+
*
102+
* @return IpValidator
102103
*/
103104
protected function getClientIpValidator(): IpValidator
104105
{
105106
if (null === $this->_clientIpValidator) {
106107
return $this->_clientIpValidator = Yii::createObject([
107-
'class' => IpValidator::class,
108-
'message' => $this->message,
108+
'class' => IpValidator::class,
109+
'message' => $this->message,
109110
'ipv4NotAllowed' => $this->message,
110111
'ipv6NotAllowed' => $this->message,
111-
'ipv4' => null === $this->version || self::IPV4 === $this->version,
112-
'ipv6' => null === $this->version || self::IPV6 === $this->version
112+
'ipv4' => null === $this->version || self::IPV4 === $this->version,
113+
'ipv6' => null === $this->version || self::IPV6 === $this->version,
113114
]);
114115
}
115116

116117
return $this->_clientIpValidator;
117118
}
118-
119119
}

src/validators/LandLineVNValidator.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88

99
namespace phpviet\yii\validation\validators;
1010

11+
use PHPViet\Validation\Rules\LandLineVN as PatternProvider;
1112
use Yii;
12-
1313
use yii\validators\RegularExpressionValidator;
1414

15-
use PHPViet\Validation\Rules\LandLineVN as PatternProvider;
16-
1715
/**
1816
* @author Vuong Minh <[email protected]>
17+
*
1918
* @since 1.0.0
2019
*/
2120
class LandLineVNValidator extends RegularExpressionValidator
2221
{
23-
2422
/**
25-
* @inheritDoc
23+
* {@inheritdoc}
2624
*/
2725
public function init()
2826
{
@@ -31,5 +29,4 @@ public function init()
3129

3230
parent::init();
3331
}
34-
3532
}

src/validators/MobileVNValidator.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88

99
namespace phpviet\yii\validation\validators;
1010

11+
use PHPViet\Validation\Rules\MobileVN as PatternProvider;
1112
use Yii;
12-
1313
use yii\validators\RegularExpressionValidator;
1414

15-
use PHPViet\Validation\Rules\MobileVN as PatternProvider;
16-
1715
/**
1816
* @author Vuong Minh <[email protected]>
17+
*
1918
* @since 1.0.0
2019
*/
2120
class MobileVNValidator extends RegularExpressionValidator
2221
{
23-
2422
/**
25-
* @inheritDoc
23+
* {@inheritdoc}
2624
*/
2725
public function init()
2826
{
@@ -31,5 +29,4 @@ public function init()
3129

3230
parent::init();
3331
}
34-
3532
}

tests/IdVNTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/**
1414
* @author Vuong Minh <[email protected]>
15+
*
1516
* @since 1.0.0
1617
*/
1718
class IdVNTest extends TestCase
@@ -45,5 +46,4 @@ public function testCanTranslateErrorMessage()
4546
]);
4647
$this->assertContains('Việt Nam', current($model->getErrors('id')));
4748
}
48-
4949
}

tests/IpVNTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212

1313
/**
1414
* @author Vuong Minh <[email protected]>
15+
*
1516
* @since 1.0.0
1617
*/
1718
class IpVNTest extends TestCase
1819
{
19-
2020
public function testValid()
2121
{
2222
$model = DynamicModel::validateData([
2323
'ipv4' => '113.173.134.203',
24-
'ipv6' => '2405:4800:102:1::3'
24+
'ipv6' => '2405:4800:102:1::3',
2525
], [
2626
[['ipv4', 'ipv6'], 'ip_vn'],
2727
[['ipv4'], 'ipv4_vn'],
28-
[['ipv6'], 'ipv6_vn']
28+
[['ipv6'], 'ipv6_vn'],
2929
]);
3030
$this->assertFalse($model->hasErrors());
3131
}
@@ -34,11 +34,11 @@ public function testInvalid()
3434
{
3535
$model = DynamicModel::validateData([
3636
'ipv4' => '113.173.134.203@',
37-
'ipv6' => '2405:4800:102:1::3!'
37+
'ipv6' => '2405:4800:102:1::3!',
3838
], [
3939
[['ipv4', 'ipv6'], 'ip_vn'],
4040
[['ipv4'], 'ipv4_vn'],
41-
[['ipv6'], 'ipv6_vn']
41+
[['ipv6'], 'ipv6_vn'],
4242
]);
4343
$this->assertTrue($model->hasErrors());
4444
}
@@ -47,14 +47,13 @@ public function testCanTranslateErrorMessage()
4747
{
4848
$model = DynamicModel::validateData([
4949
'ipv4' => '113.173.134.203@',
50-
'ipv6' => '2405:4800:102:1::3!'
50+
'ipv6' => '2405:4800:102:1::3!',
5151
], [
5252
[['ipv4', 'ipv6'], 'ip_vn'],
5353
[['ipv4'], 'ipv4_vn'],
54-
[['ipv6'], 'ipv6_vn']
54+
[['ipv6'], 'ipv6_vn'],
5555
]);
5656
$this->assertContains('Việt Nam', current($model->getErrors('ipv4')));
5757
$this->assertContains('Việt Nam', current($model->getErrors('ipv6')));
5858
}
59-
6059
}

tests/LandLineVNTest.php

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

1313
/**
1414
* @author Vuong Minh <[email protected]>
15+
*
1516
* @since 1.0.0
1617
*/
1718
class LandLineVNTest extends TestCase

tests/MobileVNTest.php

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

1313
/**
1414
* @author Vuong Minh <[email protected]>
15+
*
1516
* @since 1.0.0
1617
*/
1718
class MobileVNTest extends TestCase

0 commit comments

Comments
 (0)