Skip to content

Commit

Permalink
Merge pull request #50 from bim-g/version_boss
Browse files Browse the repository at this point in the history
[UPD] Refactoring app structure
  • Loading branch information
bim-g authored May 3, 2022
2 parents 7b6f7bd + e62c49f commit ee2f8e1
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 78 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/nbproject/private/
/.idea
.idea
vendor
vendor
.phpunit.result.cache
.phpunit-watcher.yml
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -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}}
{"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}}
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
"name": "wepesi/validation",
"description": "This module has been design to help you validate data values",
"type": "library",
"license": "Apache",
"Stabilities": "v3.1-BETA",
"license": "Apache-2.0",
"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": {
Expand Down
11 changes: 11 additions & 0 deletions src/Providers/Contracts/Contracts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php


namespace Wepesi\App\Providers\Contracts;


interface Contracts
{
function min($rule);
function max($rule);
}
10 changes: 10 additions & 0 deletions src/Providers/Contracts/SchemaContracts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php


namespace Wepesi\App\Providers\Contracts;


interface SchemaContracts extends Contracts
{

}
12 changes: 12 additions & 0 deletions src/Providers/Contracts/ValidationContracts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php


namespace Wepesi\App\Providers\Contracts;


interface ValidationContracts extends Contracts
{
function required();
function addError(array $value);
function result();
}
46 changes: 46 additions & 0 deletions src/Providers/SChemaProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Wepesi\App\Providers;

use Wepesi\App\Providers\Contracts\SchemaContracts;

abstract class SChemaProvider implements SchemaContracts
{
protected array $schema=[];
protected string $source;

/**
* @param $rule
* @return SChemaProvider
*
*/
function min($rule): SChemaProvider
{
$this->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;
}
}
31 changes: 31 additions & 0 deletions src/Providers/ValidationProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php


namespace Wepesi\App\Providers;


use Wepesi\App\Providers\Contracts\Contracts;

abstract class ValidationProvider implements Contracts
{
abstract function min($rule);
abstract function max($rule);
abstract function required();
/**
*
* @param array $value
* @return void
*/
function addError(array $value): void
{
$this->errors[] = $value;
}

/**
* @return array
*/
function result(): ?array
{
return $this->errors;
}
}
2 changes: 1 addition & 1 deletion src/Schema/BooleanSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function isValid(): BooleanSchema
return $this;
}

function required(): SChema
function required(): BooleanSchema
{
$this->schema[$this->source]['required'] = true;

Expand Down
4 changes: 3 additions & 1 deletion src/Schema/DateSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion src/Schema/NumberSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
45 changes: 0 additions & 45 deletions src/Schema/SChema.php

This file was deleted.

5 changes: 4 additions & 1 deletion src/Schema/StringSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
30 changes: 7 additions & 23 deletions src/Script/StringValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -21,7 +22,7 @@ class StringValidation {
* @throws Exception
*/
function __construct(array $source,array $schema) {
$this->init_app($source,$schema);
$this->initInstance($source,$schema);
}

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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=[
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}
16 changes: 16 additions & 0 deletions test/ValidationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php


namespace Test;


use PHPUnit\Framework\TestCase;
use Wepesi\App\Validate;

class ValidationTest extends TestCase
{
function testValidationObject(){
$validate = new Validate();
$this->assertIsObject($validate);
}
}

0 comments on commit ee2f8e1

Please sign in to comment.