-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces several new aggregate rules (first, nth, last) in JSON, PHP, YML schema files, and creates corresponding classes. These additions enhance rule validation, allowing further specification of conditions based on first, nth, and last values in a column. The changes include a range of rule adjustments such as number expectations, string expectations, and "not expected" conditions, broadening the flexibility and functionality of the schema validation system.
- Loading branch information
Showing
26 changed files
with
885 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\CsvBlueprint\Rules\Aggregate; | ||
|
||
use JBZoo\CsvBlueprint\Rules\AbstarctRule; | ||
|
||
final class ComboFirstNum extends AbstarctAggregateRuleCombo | ||
{ | ||
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS; | ||
|
||
protected const NAME = 'first value'; | ||
|
||
protected const HELP_TOP = ['First number in the column. Expected value is float or integer.']; | ||
|
||
protected const HELP_OPTIONS = [ | ||
self::EQ => ['5', ''], | ||
self::NOT => ['4.123', ''], | ||
self::MIN => ['-1', ''], | ||
self::MAX => ['2e4', ''], | ||
]; | ||
|
||
protected function getActualAggregate(array $colValues): ?float | ||
{ | ||
if (!isset($colValues[0])) { | ||
return null; | ||
} | ||
|
||
return (float)$colValues[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\CsvBlueprint\Rules\Aggregate; | ||
|
||
use JBZoo\CsvBlueprint\Rules\AbstarctRule; | ||
|
||
final class ComboLastNum extends AbstarctAggregateRuleCombo | ||
{ | ||
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_FLOATS; | ||
|
||
protected const NAME = 'last value'; | ||
|
||
protected const HELP_TOP = ['Last number in the column. Expected value is float or integer.']; | ||
|
||
protected const HELP_OPTIONS = [ | ||
self::EQ => ['5', ''], | ||
self::NOT => ['4.123', ''], | ||
self::MIN => ['-1', ''], | ||
self::MAX => ['2e4', ''], | ||
]; | ||
|
||
protected function getActualAggregate(array $colValues): ?float | ||
{ | ||
if (\count($colValues) === 0) { | ||
return null; | ||
} | ||
|
||
return (float)\end($colValues); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\CsvBlueprint\Rules\Aggregate; | ||
|
||
use JBZoo\CsvBlueprint\Rules\AbstarctRule; | ||
|
||
final class First extends AbstarctAggregateRule | ||
{ | ||
public const INPUT_TYPE = AbstarctRule::INPUT_TYPE_STRINGS; | ||
|
||
protected const HELP_OPTIONS = [ | ||
self::DEFAULT => ['Expected', 'First value in the column. Will be compared as strings.'], | ||
]; | ||
|
||
public function validateRule(array &$columnValues): ?string | ||
{ | ||
if (\count($columnValues) === 0) { | ||
return null; | ||
} | ||
|
||
$first = \reset($columnValues); | ||
if ($first !== $this->getOptionAsString()) { | ||
return "The first value in the column is \"<c>{$first}</c>\", " . | ||
"which is not equal than the expected \"<green>{$this->getOptionAsString()}</green>\""; | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.