Skip to content

Apply fixes from StyleCI #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@

namespace phpviet\yii\validation;

use phpviet\yii\validation\validators\IdVNValidator;
use phpviet\yii\validation\validators\IpVNValidator;
use phpviet\yii\validation\validators\LandLineVNValidator;
use phpviet\yii\validation\validators\MobileVNValidator;
use yii\base\BootstrapInterface;
use yii\i18n\I18N;
use yii\validators\Validator;

use phpviet\yii\validation\validators\LandLineVNValidator;
use phpviet\yii\validation\validators\MobileVNValidator;
use phpviet\yii\validation\validators\IdVNValidator;
use phpviet\yii\validation\validators\IpVNValidator;

/**
* @author Vuong Minh <[email protected]>
*
* @since 1.0.0
*/
class Bootstrap implements BootstrapInterface
{

/**
* @inheritDoc
* {@inheritdoc}
*/
public function bootstrap($app): void
{
Expand All @@ -41,11 +40,11 @@ public function bootstrap($app): void
protected function loadTrans(I18N $i18n): void
{
$i18n->translations['phpviet/validation'] = array_merge([
'class' => 'yii\i18n\PhpMessageSource',
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@phpviet/yii/validation/messages',
'fileMap' => [
'phpviet/validation' => 'validation.php'
]
'fileMap' => [
'phpviet/validation' => 'validation.php',
],
], $i18n->translations['phpviet/validation'] ?? []);
}

Expand All @@ -56,17 +55,17 @@ protected function loadShortValidators(): void
{
Validator::$builtInValidators = array_merge(Validator::$builtInValidators, [
'land_line_vn' => LandLineVNValidator::class,
'mobile_vn' => MobileVNValidator::class,
'id_vn' => IdVNValidator::class,
'ip_vn' => IpVNValidator::class,
'ipv4_vn' => [
'class' => IpVNValidator::class,
'version' => IpVNValidator::IPV4
'mobile_vn' => MobileVNValidator::class,
'id_vn' => IdVNValidator::class,
'ip_vn' => IpVNValidator::class,
'ipv4_vn' => [
'class' => IpVNValidator::class,
'version' => IpVNValidator::IPV4,
],
'ipv6_vn' => [
'class' => IpVNValidator::class,
'version' => IpVNValidator::IPV6
]
'class' => IpVNValidator::class,
'version' => IpVNValidator::IPV6,
],
]);
}
}
10 changes: 5 additions & 5 deletions src/messages/vi/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*/

return [
'{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.',
'{attribute} must be a mobile phone number of Vietnam.' => '{attribute} phải là số di động tại Việt Nam.',
'{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.',
'{attribute} must be a mobile phone number of Vietnam.' => '{attribute} phải là số di động tại Việt Nam.',
'{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.',
'{attribute} must be Vietnam ip.' => '{attribute} phải là ip Việt Nam.',
'{attribute} must be Vietnam ipv4.' => '{attribute} phải là ipv4 tại Việt Nam.',
'{attribute} must be Vietnam ipv6.' => '{attribute} phải là ipv6 tại Việt Nam.',
'{attribute} must be Vietnam ip.' => '{attribute} phải là ip Việt Nam.',
'{attribute} must be Vietnam ipv4.' => '{attribute} phải là ipv4 tại Việt Nam.',
'{attribute} must be Vietnam ipv6.' => '{attribute} phải là ipv6 tại Việt Nam.',
];
9 changes: 3 additions & 6 deletions src/validators/IdVNValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@

namespace phpviet\yii\validation\validators;

use PHPViet\Validation\Rules\IdVN as PatternProvider;
use Yii;

use yii\validators\RegularExpressionValidator;

use PHPViet\Validation\Rules\IdVN as PatternProvider;

/**
* @author Vuong Minh <[email protected]>
*
* @since 1.0.0
*/
class IdVNValidator extends RegularExpressionValidator
{

/**
* @inheritDoc
* {@inheritdoc}
*/
public function init()
{
Expand All @@ -31,5 +29,4 @@ public function init()

parent::init();
}

}
38 changes: 19 additions & 19 deletions src/validators/IpVNValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@

namespace phpviet\yii\validation\validators;

use PHPViet\Validation\Rules\IpVN as ConcreteIpVN;
use PHPViet\Validation\Validator as ConcreteValidator;
use Yii;

use yii\validators\Validator;
use yii\validators\IpValidator;

use PHPViet\Validation\Validator as ConcreteValidator;
use PHPViet\Validation\Rules\IpVN as ConcreteIpVN;
use yii\validators\Validator;

/**
* @author Vuong Minh <[email protected]>
*
* @since 1.0.0
*/
class IpVNValidator extends Validator
{

const IPV4 = ConcreteIpVN::IPV4;

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

/**
* @inheritDoc
* {@inheritdoc}
*/
public function init()
{
Expand All @@ -43,20 +41,20 @@ public function init()
}

/**
* @inheritDoc
* {@inheritdoc}
*/
public function validateValue($value)
{
if (ConcreteValidator::ipVN($this->version)->validate($value)) {

return null;
return;
}

return [$this->message, []];
}

/**
* @inheritDoc
* {@inheritdoc}
*
* @throws \yii\base\InvalidConfigException
*/
public function clientValidateAttribute($model, $attribute, $view)
Expand All @@ -65,7 +63,8 @@ public function clientValidateAttribute($model, $attribute, $view)
}

/**
* @inheritDoc
* {@inheritdoc}
*
* @throws \yii\base\InvalidConfigException
*/
public function getClientOptions($model, $attribute)
Expand All @@ -74,7 +73,7 @@ public function getClientOptions($model, $attribute)
}

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function getDefaultMessage(): string
{
Expand All @@ -90,30 +89,31 @@ protected function getDefaultMessage(): string

/**
* @var IpValidator
*
* @see getClientIpValidator()
*/
private $_clientIpValidator;

/**
* Trả về [[IpValidator]] hổ trợ cho việc tạo js validator tại client.
*
* @return IpValidator
* @throws \yii\base\InvalidConfigException
*
* @return IpValidator
*/
protected function getClientIpValidator(): IpValidator
{
if (null === $this->_clientIpValidator) {
return $this->_clientIpValidator = Yii::createObject([
'class' => IpValidator::class,
'message' => $this->message,
'class' => IpValidator::class,
'message' => $this->message,
'ipv4NotAllowed' => $this->message,
'ipv6NotAllowed' => $this->message,
'ipv4' => null === $this->version || self::IPV4 === $this->version,
'ipv6' => null === $this->version || self::IPV6 === $this->version
'ipv4' => null === $this->version || self::IPV4 === $this->version,
'ipv6' => null === $this->version || self::IPV6 === $this->version,
]);
}

return $this->_clientIpValidator;
}

}
9 changes: 3 additions & 6 deletions src/validators/LandLineVNValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@

namespace phpviet\yii\validation\validators;

use PHPViet\Validation\Rules\LandLineVN as PatternProvider;
use Yii;

use yii\validators\RegularExpressionValidator;

use PHPViet\Validation\Rules\LandLineVN as PatternProvider;

/**
* @author Vuong Minh <[email protected]>
*
* @since 1.0.0
*/
class LandLineVNValidator extends RegularExpressionValidator
{

/**
* @inheritDoc
* {@inheritdoc}
*/
public function init()
{
Expand All @@ -31,5 +29,4 @@ public function init()

parent::init();
}

}
9 changes: 3 additions & 6 deletions src/validators/MobileVNValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@

namespace phpviet\yii\validation\validators;

use PHPViet\Validation\Rules\MobileVN as PatternProvider;
use Yii;

use yii\validators\RegularExpressionValidator;

use PHPViet\Validation\Rules\MobileVN as PatternProvider;

/**
* @author Vuong Minh <[email protected]>
*
* @since 1.0.0
*/
class MobileVNValidator extends RegularExpressionValidator
{

/**
* @inheritDoc
* {@inheritdoc}
*/
public function init()
{
Expand All @@ -31,5 +29,4 @@ public function init()

parent::init();
}

}
2 changes: 1 addition & 1 deletion tests/IdVNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

/**
* @author Vuong Minh <[email protected]>
*
* @since 1.0.0
*/
class IdVNTest extends TestCase
Expand Down Expand Up @@ -45,5 +46,4 @@ public function testCanTranslateErrorMessage()
]);
$this->assertContains('Việt Nam', current($model->getErrors('id')));
}

}
15 changes: 7 additions & 8 deletions tests/IpVNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@

/**
* @author Vuong Minh <[email protected]>
*
* @since 1.0.0
*/
class IpVNTest extends TestCase
{

public function testValid()
{
$model = DynamicModel::validateData([
'ipv4' => '113.173.134.203',
'ipv6' => '2405:4800:102:1::3'
'ipv6' => '2405:4800:102:1::3',
], [
[['ipv4', 'ipv6'], 'ip_vn'],
[['ipv4'], 'ipv4_vn'],
[['ipv6'], 'ipv6_vn']
[['ipv6'], 'ipv6_vn'],
]);
$this->assertFalse($model->hasErrors());
}
Expand All @@ -34,11 +34,11 @@ public function testInvalid()
{
$model = DynamicModel::validateData([
'ipv4' => '113.173.134.203@',
'ipv6' => '2405:4800:102:1::3!'
'ipv6' => '2405:4800:102:1::3!',
], [
[['ipv4', 'ipv6'], 'ip_vn'],
[['ipv4'], 'ipv4_vn'],
[['ipv6'], 'ipv6_vn']
[['ipv6'], 'ipv6_vn'],
]);
$this->assertTrue($model->hasErrors());
}
Expand All @@ -47,14 +47,13 @@ public function testCanTranslateErrorMessage()
{
$model = DynamicModel::validateData([
'ipv4' => '113.173.134.203@',
'ipv6' => '2405:4800:102:1::3!'
'ipv6' => '2405:4800:102:1::3!',
], [
[['ipv4', 'ipv6'], 'ip_vn'],
[['ipv4'], 'ipv4_vn'],
[['ipv6'], 'ipv6_vn']
[['ipv6'], 'ipv6_vn'],
]);
$this->assertContains('Việt Nam', current($model->getErrors('ipv4')));
$this->assertContains('Việt Nam', current($model->getErrors('ipv6')));
}

}
1 change: 1 addition & 0 deletions tests/LandLineVNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

/**
* @author Vuong Minh <[email protected]>
*
* @since 1.0.0
*/
class LandLineVNTest extends TestCase
Expand Down
1 change: 1 addition & 0 deletions tests/MobileVNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

/**
* @author Vuong Minh <[email protected]>
*
* @since 1.0.0
*/
class MobileVNTest extends TestCase
Expand Down
Loading