From ee351abed305dbba69882eca61be3e3d54aee762 Mon Sep 17 00:00:00 2001 From: Vuong Minh Date: Sun, 26 May 2019 11:02:12 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Bootstrap.php | 39 +++++++++++++------------- src/messages/vi/validation.php | 10 +++---- src/validators/IdVNValidator.php | 9 ++---- src/validators/IpVNValidator.php | 38 ++++++++++++------------- src/validators/LandLineVNValidator.php | 9 ++---- src/validators/MobileVNValidator.php | 9 ++---- tests/IdVNTest.php | 2 +- tests/IpVNTest.php | 15 +++++----- tests/LandLineVNTest.php | 1 + tests/MobileVNTest.php | 1 + tests/TestCase.php | 23 +++++++-------- tests/bootstrap.php | 7 ++--- 12 files changed, 75 insertions(+), 88 deletions(-) diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 316df55..b7d8192 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -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 + * * @since 1.0.0 */ class Bootstrap implements BootstrapInterface { - /** - * @inheritDoc + * {@inheritdoc} */ public function bootstrap($app): void { @@ -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'] ?? []); } @@ -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, + ], ]); } } diff --git a/src/messages/vi/validation.php b/src/messages/vi/validation.php index 7b1f37a..fecb0a4 100644 --- a/src/messages/vi/validation.php +++ b/src/messages/vi/validation.php @@ -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.', ]; diff --git a/src/validators/IdVNValidator.php b/src/validators/IdVNValidator.php index 3178770..7489490 100644 --- a/src/validators/IdVNValidator.php +++ b/src/validators/IdVNValidator.php @@ -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 + * * @since 1.0.0 */ class IdVNValidator extends RegularExpressionValidator { - /** - * @inheritDoc + * {@inheritdoc} */ public function init() { @@ -31,5 +29,4 @@ public function init() parent::init(); } - } diff --git a/src/validators/IpVNValidator.php b/src/validators/IpVNValidator.php index cd5025a..d69e354 100644 --- a/src/validators/IpVNValidator.php +++ b/src/validators/IpVNValidator.php @@ -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 + * * @since 1.0.0 */ class IpVNValidator extends Validator { - const IPV4 = ConcreteIpVN::IPV4; const IPV6 = ConcreteIpVN::IPV6; @@ -33,7 +31,7 @@ class IpVNValidator extends Validator public $version; /** - * @inheritDoc + * {@inheritdoc} */ public function init() { @@ -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) @@ -65,7 +63,8 @@ public function clientValidateAttribute($model, $attribute, $view) } /** - * @inheritDoc + * {@inheritdoc} + * * @throws \yii\base\InvalidConfigException */ public function getClientOptions($model, $attribute) @@ -74,7 +73,7 @@ public function getClientOptions($model, $attribute) } /** - * @inheritDoc + * {@inheritdoc} */ protected function getDefaultMessage(): string { @@ -90,6 +89,7 @@ protected function getDefaultMessage(): string /** * @var IpValidator + * * @see getClientIpValidator() */ private $_clientIpValidator; @@ -97,23 +97,23 @@ protected function getDefaultMessage(): string /** * 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; } - } diff --git a/src/validators/LandLineVNValidator.php b/src/validators/LandLineVNValidator.php index 02c57d2..d9d2d9c 100644 --- a/src/validators/LandLineVNValidator.php +++ b/src/validators/LandLineVNValidator.php @@ -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 + * * @since 1.0.0 */ class LandLineVNValidator extends RegularExpressionValidator { - /** - * @inheritDoc + * {@inheritdoc} */ public function init() { @@ -31,5 +29,4 @@ public function init() parent::init(); } - } diff --git a/src/validators/MobileVNValidator.php b/src/validators/MobileVNValidator.php index 772a7f4..87283c2 100644 --- a/src/validators/MobileVNValidator.php +++ b/src/validators/MobileVNValidator.php @@ -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 + * * @since 1.0.0 */ class MobileVNValidator extends RegularExpressionValidator { - /** - * @inheritDoc + * {@inheritdoc} */ public function init() { @@ -31,5 +29,4 @@ public function init() parent::init(); } - } diff --git a/tests/IdVNTest.php b/tests/IdVNTest.php index 482c04e..5e209e3 100644 --- a/tests/IdVNTest.php +++ b/tests/IdVNTest.php @@ -12,6 +12,7 @@ /** * @author Vuong Minh + * * @since 1.0.0 */ class IdVNTest extends TestCase @@ -45,5 +46,4 @@ public function testCanTranslateErrorMessage() ]); $this->assertContains('Việt Nam', current($model->getErrors('id'))); } - } diff --git a/tests/IpVNTest.php b/tests/IpVNTest.php index d2bb815..ef402ff 100644 --- a/tests/IpVNTest.php +++ b/tests/IpVNTest.php @@ -12,20 +12,20 @@ /** * @author Vuong Minh + * * @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()); } @@ -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()); } @@ -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'))); } - } diff --git a/tests/LandLineVNTest.php b/tests/LandLineVNTest.php index 295d394..7df35f5 100644 --- a/tests/LandLineVNTest.php +++ b/tests/LandLineVNTest.php @@ -12,6 +12,7 @@ /** * @author Vuong Minh + * * @since 1.0.0 */ class LandLineVNTest extends TestCase diff --git a/tests/MobileVNTest.php b/tests/MobileVNTest.php index d6e29de..13b8792 100644 --- a/tests/MobileVNTest.php +++ b/tests/MobileVNTest.php @@ -12,6 +12,7 @@ /** * @author Vuong Minh + * * @since 1.0.0 */ class MobileVNTest extends TestCase diff --git a/tests/TestCase.php b/tests/TestCase.php index 19929c4..1559457 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,19 +8,17 @@ namespace phpviet\yii\validation\tests; -use Yii; - use PHPUnit\Framework\TestCase as BaseTestCase; - +use Yii; use yii\helpers\ArrayHelper; /** * @author Vuong Minh + * * @since 1.0.0 */ class TestCase extends BaseTestCase { - public function setUp(): void { $this->mockApplication(); @@ -34,20 +32,21 @@ public function tearDown(): void /** * Populates Yii::$app with a new application * The application will be destroyed on tearDown() automatically. - * @param array $config The application configuration, if needed + * + * @param array $config The application configuration, if needed * @param string $appClass name of the application class to create */ protected function mockApplication($config = [], $appClass = '\yii\console\Application'): void { new $appClass(ArrayHelper::merge([ - 'id' => 'test', - 'language' => 'vi', - 'bootstrap' => ['phpviet\yii\validation\Bootstrap'], - 'basePath' => __DIR__, - 'vendorPath' => dirname(__DIR__) . '/vendor', + 'id' => 'test', + 'language' => 'vi', + 'bootstrap' => ['phpviet\yii\validation\Bootstrap'], + 'basePath' => __DIR__, + 'vendorPath' => dirname(__DIR__).'/vendor', 'components' => [ - ] + ], ], $config)); } @@ -58,6 +57,4 @@ protected function destroyApplication(): void { Yii::$app = null; } - - } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 90ab1ff..4478ad3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,15 +5,14 @@ * @copyright (c) PHP Viet * @license [MIT](https://opensource.org/licenses/MIT) */ - error_reporting(E_ALL); define('YII_ENABLE_ERROR_HANDLER', false); define('YII_DEBUG', true); define('YII_ENV', 'test'); -require_once(__DIR__ . '/../vendor/autoload.php'); -require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); +require_once __DIR__.'/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/yiisoft/yii2/Yii.php'; Yii::setAlias('@phpviet/yii/validation/tests', __DIR__); -Yii::setAlias('@phpviet/yii/validation', dirname(__DIR__) . '/src'); +Yii::setAlias('@phpviet/yii/validation', dirname(__DIR__).'/src');