From 56ec0e70df1197c5dfcec6f425e3c03ed598bbd5 Mon Sep 17 00:00:00 2001 From: bim-g Date: Sun, 1 May 2022 22:31:49 +0200 Subject: [PATCH 1/4] [UPD] Composer.json: update license and author --- .gitignore | 4 +++- composer.json | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index dc72bdc..f98aeb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /nbproject/private/ /.idea .idea -vendor \ No newline at end of file +vendor +.phpunit.result.cache +.phpunit-watcher.yml \ No newline at end of file diff --git a/composer.json b/composer.json index 77a625a..aea6cf0 100644 --- a/composer.json +++ b/composer.json @@ -2,17 +2,22 @@ "name": "wepesi/validation", "description": "This module has been design to help you validate data values", "type": "library", - "license": "Apache", + "license": "Apache-2.0", "Stabilities": "v3.1-BETA", "minimum-stability": "beta", + "support":{ + "email": "ibmussafb@gmail.com" + } , "authors": [ { "name": "Boss Ibrahim Mussa Gregoire", - "email": "ibmussafb@gmail.com" + "email": "ibmussafb@gmail.com", + "role": "Develloper" }, { "name": "Masikilizano Emanuel Domeshow", - "email": "domeshowemmanuel@gmail.com" + "email": "domeshowemmanuel@gmail.com", + "role": "Develloper" } ], "autoload": { From 36ba0df342b55fa344fe8d864ce4a624c8b7a2f2 Mon Sep 17 00:00:00 2001 From: bim-g Date: Tue, 3 May 2022 12:04:39 +0200 Subject: [PATCH 2/4] [FIX]composer Schema: update composer.json update --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index aea6cf0..a487304 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,6 @@ "description": "This module has been design to help you validate data values", "type": "library", "license": "Apache-2.0", - "Stabilities": "v3.1-BETA", "minimum-stability": "beta", "support":{ "email": "ibmussafb@gmail.com" From b3a288013756c092843cbde24f4201ba4155eafa Mon Sep 17 00:00:00 2001 From: bim-g Date: Tue, 3 May 2022 12:05:52 +0200 Subject: [PATCH 3/4] [ENH]add validation test module --- test/ValidationTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/ValidationTest.php diff --git a/test/ValidationTest.php b/test/ValidationTest.php new file mode 100644 index 0000000..f79d22e --- /dev/null +++ b/test/ValidationTest.php @@ -0,0 +1,16 @@ +assertIsObject($validate); + } +} \ No newline at end of file From e62c49f52753e286c61ce7514c0adbc50102becf Mon Sep 17 00:00:00 2001 From: bim-g Date: Tue, 3 May 2022 12:06:33 +0200 Subject: [PATCH 4/4] [UPD]Refactoring app structure --- .phpunit.result.cache | 2 +- src/Providers/Contracts/Contracts.php | 11 +++++ src/Providers/Contracts/SchemaContracts.php | 10 ++++ .../Contracts/ValidationContracts.php | 12 +++++ src/Providers/SChemaProvider.php | 46 +++++++++++++++++++ src/Providers/ValidationProvider.php | 31 +++++++++++++ src/Schema/BooleanSchema.php | 2 +- src/Schema/DateSchema.php | 4 +- src/Schema/NumberSchema.php | 4 +- src/Schema/SChema.php | 45 ------------------ src/Schema/StringSchema.php | 5 +- src/Script/StringValidation.php | 30 +++--------- 12 files changed, 129 insertions(+), 73 deletions(-) create mode 100644 src/Providers/Contracts/Contracts.php create mode 100644 src/Providers/Contracts/SchemaContracts.php create mode 100644 src/Providers/Contracts/ValidationContracts.php create mode 100644 src/Providers/SChemaProvider.php create mode 100644 src/Providers/ValidationProvider.php delete mode 100644 src/Schema/SChema.php diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 3cf6e4e..2f14574 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Test\\Schema\\SCHStringTest::testStringObject":4,"Test\\Schema\\SCHStringTest::testStringObjectIsNotKey":3,"Test\\Schema\\SCHStringTest::testStringEmailKey":3,"Test\\Schema\\SCHStringTest::testStringObjectIsKey":4,"Test\\Schema\\StringSchemaTest::testStringURLKey":3,"Test\\Schema\\StringSchemaTest::testStringMatchKey":4,"Test\\Schema\\StringSchemaTest::testStringMinimumKey":3,"Test\\Schema\\NumberSchemaTest::testStringIsObject":4,"Test\\Schema\\NumberSchemaTest::testRequiredKey":3,"Test\\Schema\\DateSchemaTest::testDateTodayKey":4,"Test\\Schema\\BooleanSchemaTest::testBooleanIsRequireddKey":4,"Test\\Script\\StringValidationTest::testStringIsObject":4,"Test\\Script\\StringValidationTest::testStringObjectException":4,"Test\\Script\\StringValidationTest::testException":3,"Test\\Script\\StringValidationTest::testStringMin":3,"Test\\Script\\StringValidationTest::testStringMaxError":4,"Test\\Script\\StringValidationTest::testStringMaxSuccess":3,"Test\\Script\\StringValidationTest::testStringValidationSourceDataException":4,"Test\\Script\\StringValidationTest::testStringValidationSchemaException":4,"Test\\Script\\StringValidationTest::testStringMinError":4,"Test\\Script\\StringValidationTest::testStringMinSuccess":3,"Test\\Script\\StringValidationTest::testStringEmailError":3,"Test\\Script\\StringValidationTest::testStringURLSuccess":3,"Test\\Script\\StringValidationTest::testStringRequiredSuccess":4,"Test\\Script\\StringValidationTest::testStringRequiredErrors":3,"Test\\Script\\StringValidationTest::testStringRequiredErrorsUnknown":4,"Test\\Script\\StringValidationTest::testStringMatchSuccess":3,"Test\\Script\\StringValidationTest::testStringMatchErrors":3},"times":{"Test\\Schema\\SCHStringTest::testStringObject":0.021,"Test\\Schema\\SCHStringTest::testStringObjectIsKey":0,"Test\\Schema\\SCHStringTest::testStringObjectIsNotKey":0.01,"Test\\Schema\\SCHStringTest::testStringEmailKey":0.001,"Test\\Schema\\SCHStringTest::testStringIsObject":0.008,"Test\\Schema\\StringSchemaTest::testStringIsObject":0.014,"Test\\Schema\\StringSchemaTest::testStringObjectIsKey":0.001,"Test\\Schema\\StringSchemaTest::testStringEmailKey":0.001,"Test\\Schema\\StringSchemaTest::testStringURLKey":0,"Test\\Schema\\StringSchemaTest::testStringMatchKey":0,"Test\\Schema\\StringSchemaTest::testStringMinimumKey":0,"Test\\Schema\\StringSchemaTest::testStringMaximumKey":0.001,"Test\\Schema\\NumberSchemaTest::testStringIsObject":0.009,"Test\\Schema\\NumberSchemaTest::testStringObjectIsKey":0.001,"Test\\Schema\\NumberSchemaTest::testRequiredKey":0.001,"Test\\Schema\\NumberSchemaTest::testNumberPositiveKey":0,"Test\\Schema\\DateSchemaTest::testStringIsObject":0.011,"Test\\Schema\\DateSchemaTest::testStringObjectIsKey":0.001,"Test\\Schema\\DateSchemaTest::testDateNowKey":0.001,"Test\\Schema\\DateSchemaTest::testDateTodayKey":0,"Test\\Schema\\BooleanSchemaTest::testBooleanIsObject":0.03,"Test\\Schema\\BooleanSchemaTest::testStringObjectIsKey":0.001,"Test\\Schema\\BooleanSchemaTest::testBooleanIsRequireddKey":0.006,"Test\\Schema\\BooleanSchemaTest::testBooleanIsValidKey":0.002,"Test\\Script\\StringValidationTest::testStringIsObject":0,"Test\\Script\\StringValidationTest::testStringObjectException":0.006,"Test\\Script\\StringValidationTest::testException":0.007,"Test\\Script\\StringValidationTest::testStringMin":0.001,"Test\\Script\\StringValidationTest::testStringValidationException":0.006,"Test\\Script\\StringValidationTest::testStringValidationSchemaException":0,"Test\\Script\\StringValidationTest::testStringValidationSourceDataException":0.007,"Test\\Script\\StringValidationTest::testStringMinError":0,"Test\\Script\\StringValidationTest::testStringMinSuccess":0,"Test\\Script\\StringValidationTest::testStringMaxError":0,"Test\\Script\\StringValidationTest::testStringMaxSuccess":0,"Test\\Script\\StringValidationTest::testStringEmailError":0.001,"Test\\Script\\StringValidationTest::testStringEmailSuccess":0,"Test\\Script\\StringValidationTest::testStringUrlError":0.008,"Test\\Script\\StringValidationTest::testStringURLError":0,"Test\\Script\\StringValidationTest::testStringURLSuccess":0,"Test\\Script\\StringValidationTest::testStringRequiredSuccess":0.001,"Test\\Script\\StringValidationTest::testStringRequiredErrors":0,"Test\\Script\\StringValidationTest::testStringRequiredErrorsUnknow":0,"Test\\Script\\StringValidationTest::testStringRequiredErrorsUnknown":0,"Test\\Script\\StringValidationTest::testStringMatchErrors":0,"Test\\Script\\StringValidationTest::testStringMatchSuccess":0,"Test\\Script\\StringValidationTest::testStringValidationFieldNotDefinedException":0}} \ No newline at end of file +{"version":1,"defects":{"Test\\Schema\\SCHStringTest::testStringObject":4,"Test\\Schema\\SCHStringTest::testStringObjectIsNotKey":3,"Test\\Schema\\SCHStringTest::testStringEmailKey":3,"Test\\Schema\\SCHStringTest::testStringObjectIsKey":4,"Test\\Schema\\StringSchemaTest::testStringURLKey":4,"Test\\Schema\\StringSchemaTest::testStringMatchKey":4,"Test\\Schema\\StringSchemaTest::testStringMinimumKey":4,"Test\\Schema\\NumberSchemaTest::testStringIsObject":4,"Test\\Schema\\NumberSchemaTest::testRequiredKey":4,"Test\\Schema\\DateSchemaTest::testDateTodayKey":4,"Test\\Schema\\BooleanSchemaTest::testBooleanIsRequireddKey":4,"Test\\Script\\StringValidationTest::testStringIsObject":4,"Test\\Script\\StringValidationTest::testStringObjectException":4,"Test\\Script\\StringValidationTest::testException":3,"Test\\Script\\StringValidationTest::testStringMin":3,"Test\\Script\\StringValidationTest::testStringMaxError":4,"Test\\Script\\StringValidationTest::testStringMaxSuccess":3,"Test\\Script\\StringValidationTest::testStringValidationSourceDataException":4,"Test\\Script\\StringValidationTest::testStringValidationSchemaException":4,"Test\\Script\\StringValidationTest::testStringMinError":4,"Test\\Script\\StringValidationTest::testStringMinSuccess":3,"Test\\Script\\StringValidationTest::testStringEmailError":3,"Test\\Script\\StringValidationTest::testStringURLSuccess":4,"Test\\Script\\StringValidationTest::testStringRequiredSuccess":4,"Test\\Script\\StringValidationTest::testStringRequiredErrors":3,"Test\\Script\\StringValidationTest::testStringRequiredErrorsUnknown":4,"Test\\Script\\StringValidationTest::testStringMatchSuccess":3,"Test\\Script\\StringValidationTest::testStringMatchErrors":3,"Test\\Schema\\StringSchemaTest::testStringIsObject":4,"Test\\Schema\\StringSchemaTest::testStringObjectIsKey":4,"Test\\Schema\\StringSchemaTest::testStringEmailKey":4,"Test\\Schema\\StringSchemaTest::testStringMaximumKey":4,"Test\\Schema\\DateSchemaTest::testStringIsObject":4,"Test\\Schema\\DateSchemaTest::testStringObjectIsKey":4,"Test\\Schema\\DateSchemaTest::testDateNowKey":4,"Test\\Schema\\NumberSchemaTest::testStringObjectIsKey":4,"Test\\Schema\\NumberSchemaTest::testNumberPositiveKey":4},"times":{"Test\\Schema\\SCHStringTest::testStringObject":0.021,"Test\\Schema\\SCHStringTest::testStringObjectIsKey":0,"Test\\Schema\\SCHStringTest::testStringObjectIsNotKey":0.01,"Test\\Schema\\SCHStringTest::testStringEmailKey":0.001,"Test\\Schema\\SCHStringTest::testStringIsObject":0.008,"Test\\Schema\\StringSchemaTest::testStringIsObject":0.009,"Test\\Schema\\StringSchemaTest::testStringObjectIsKey":0.001,"Test\\Schema\\StringSchemaTest::testStringEmailKey":0.001,"Test\\Schema\\StringSchemaTest::testStringURLKey":0,"Test\\Schema\\StringSchemaTest::testStringMatchKey":0,"Test\\Schema\\StringSchemaTest::testStringMinimumKey":0,"Test\\Schema\\StringSchemaTest::testStringMaximumKey":0,"Test\\Schema\\NumberSchemaTest::testStringIsObject":0.008,"Test\\Schema\\NumberSchemaTest::testStringObjectIsKey":0,"Test\\Schema\\NumberSchemaTest::testRequiredKey":0,"Test\\Schema\\NumberSchemaTest::testNumberPositiveKey":0,"Test\\Schema\\DateSchemaTest::testStringIsObject":0.022,"Test\\Schema\\DateSchemaTest::testStringObjectIsKey":0.002,"Test\\Schema\\DateSchemaTest::testDateNowKey":0.002,"Test\\Schema\\DateSchemaTest::testDateTodayKey":0,"Test\\Schema\\BooleanSchemaTest::testBooleanIsObject":0.007,"Test\\Schema\\BooleanSchemaTest::testStringObjectIsKey":0.001,"Test\\Schema\\BooleanSchemaTest::testBooleanIsRequireddKey":0.001,"Test\\Schema\\BooleanSchemaTest::testBooleanIsValidKey":0,"Test\\Script\\StringValidationTest::testStringIsObject":0,"Test\\Script\\StringValidationTest::testStringObjectException":0.006,"Test\\Script\\StringValidationTest::testException":0.007,"Test\\Script\\StringValidationTest::testStringMin":0.001,"Test\\Script\\StringValidationTest::testStringValidationException":0.006,"Test\\Script\\StringValidationTest::testStringValidationSchemaException":0,"Test\\Script\\StringValidationTest::testStringValidationSourceDataException":0.007,"Test\\Script\\StringValidationTest::testStringMinError":0,"Test\\Script\\StringValidationTest::testStringMinSuccess":0,"Test\\Script\\StringValidationTest::testStringMaxError":0,"Test\\Script\\StringValidationTest::testStringMaxSuccess":0,"Test\\Script\\StringValidationTest::testStringEmailError":0.001,"Test\\Script\\StringValidationTest::testStringEmailSuccess":0,"Test\\Script\\StringValidationTest::testStringUrlError":0.008,"Test\\Script\\StringValidationTest::testStringURLError":0,"Test\\Script\\StringValidationTest::testStringURLSuccess":0.008,"Test\\Script\\StringValidationTest::testStringRequiredSuccess":0.001,"Test\\Script\\StringValidationTest::testStringRequiredErrors":0,"Test\\Script\\StringValidationTest::testStringRequiredErrorsUnknow":0,"Test\\Script\\StringValidationTest::testStringRequiredErrorsUnknown":0,"Test\\Script\\StringValidationTest::testStringMatchErrors":0,"Test\\Script\\StringValidationTest::testStringMatchSuccess":0,"Test\\Script\\StringValidationTest::testStringValidationFieldNotDefinedException":0,"Test\\ValidationTest::testValidationObject":0.008}} \ No newline at end of file diff --git a/src/Providers/Contracts/Contracts.php b/src/Providers/Contracts/Contracts.php new file mode 100644 index 0000000..1ceed04 --- /dev/null +++ b/src/Providers/Contracts/Contracts.php @@ -0,0 +1,11 @@ +schema[$this->source]["min"]=$rule; + return $this; + } + + /** + * @param $rule + * @return $this + */ + function max($rule): SChemaProvider + { + $this->schema[$this->source]["max"]=$rule; + return $this; + } + + function required(): SChemaProvider + { + $this->schema[$this->source]["required"]=true; + return $this; + } + + /** + * @return array + */ + function check(): array + { + return $this->schema; + } +} \ No newline at end of file diff --git a/src/Providers/ValidationProvider.php b/src/Providers/ValidationProvider.php new file mode 100644 index 0000000..b92b090 --- /dev/null +++ b/src/Providers/ValidationProvider.php @@ -0,0 +1,31 @@ +errors[] = $value; + } + + /** + * @return array + */ + function result(): ?array + { + return $this->errors; + } +} \ No newline at end of file diff --git a/src/Schema/BooleanSchema.php b/src/Schema/BooleanSchema.php index 05699d2..f7ea8b5 100644 --- a/src/Schema/BooleanSchema.php +++ b/src/Schema/BooleanSchema.php @@ -29,7 +29,7 @@ function isValid(): BooleanSchema return $this; } - function required(): SChema + function required(): BooleanSchema { $this->schema[$this->source]['required'] = true; diff --git a/src/Schema/DateSchema.php b/src/Schema/DateSchema.php index 3d8c911..27ac866 100644 --- a/src/Schema/DateSchema.php +++ b/src/Schema/DateSchema.php @@ -2,12 +2,14 @@ namespace Wepesi\App\Schema; +use Wepesi\App\Providers\SChemaProvider; + /** * Description of VDate * * @author Boss Ibrahim Mussa */ -class DateSchema extends SChema +class DateSchema extends SChemaProvider { function __construct() { $this->source="VDate"; diff --git a/src/Schema/NumberSchema.php b/src/Schema/NumberSchema.php index 545ecaa..b244c2c 100644 --- a/src/Schema/NumberSchema.php +++ b/src/Schema/NumberSchema.php @@ -8,12 +8,14 @@ namespace Wepesi\App\Schema; +use Wepesi\App\Providers\SChemaProvider; + /** * Description of VNumber * * @author Boss Ibrahim Mussa */ -class NumberSchema extends SChema { +class NumberSchema extends SChemaProvider { function __construct() { $this->source="VNumber"; diff --git a/src/Schema/SChema.php b/src/Schema/SChema.php deleted file mode 100644 index a3da073..0000000 --- a/src/Schema/SChema.php +++ /dev/null @@ -1,45 +0,0 @@ -schema[$this->source]["min"]=$rule_values; - return $this; - } - - /** - * @param int $rule_values - * @return DateSchema try to check maximum date of a defined period use this module - * while try to check maximum date of a defined period use this module - */ - function max(int $rule_values): SChema - { - $this->schema[$this->source]["max"]=$rule_values; - return $this; - } - - function required(): SChema - { - $this->schema[$this->source]["required"]=true; - return $this; - } - - /** - * @return array - */ - function check(): array - { - return $this->schema; - } -} \ No newline at end of file diff --git a/src/Schema/StringSchema.php b/src/Schema/StringSchema.php index 5afa97f..aa2b98a 100644 --- a/src/Schema/StringSchema.php +++ b/src/Schema/StringSchema.php @@ -6,12 +6,15 @@ * and open the template in the editor. */ +use Wepesi\App\Providers\SChemaProvider; + + /** * Description of String * * @author Boss Ibrahim Mussa */ -class StringSchema extends SChema { +class StringSchema extends SChemaProvider { function __construct() { $this->source="String"; diff --git a/src/Script/StringValidation.php b/src/Script/StringValidation.php index 66cc6c4..9ad8dc3 100644 --- a/src/Script/StringValidation.php +++ b/src/Script/StringValidation.php @@ -2,16 +2,17 @@ namespace Wepesi\App\Script; use Exception; +use Wepesi\App\Providers\ValidationProvider; /** * Description of String * * @author Boss Ibrahim Mussa */ -class StringValidation { +class StringValidation extends ValidationProvider { private string $string_value, $field_item,$field_value; private array $source_data; - private ?array $errors; + protected ?array $errors; private int $_min, $_max; /** @@ -21,7 +22,7 @@ class StringValidation { * @throws Exception */ function __construct(array $source,array $schema) { - $this->init_app($source,$schema); + $this->initInstance($source,$schema); } /** @@ -38,7 +39,7 @@ private function extract_data(array $schema ){ /** * @throws Exception */ - private function init_app($source, $schema){ + private function initInstance($source, $schema){ $this->errors=null; $this->_min=0; $this->_max=1; @@ -70,7 +71,7 @@ private function init_app($source, $schema){ * @param int $rule * */ - function min(int $rule):void + function min($rule):void { if (strlen($this->field_value) < $rule) { $message=[ @@ -88,7 +89,7 @@ function min(int $rule):void * @param int $rule * */ - function max(int $rule) + function max($rule) { $this->_max=$rule; if (strlen($this->string_value) > $rule) { @@ -185,21 +186,4 @@ private function isString(string $item_key): bool } return true; } - /** - * - * @param array $value - * @return void - */ - private function addError(array $value): void - { - $this->errors[] = $value; - } - - /** - * @return array - */ - function result(): ?array - { - return $this->errors; - } }