Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Smet committed Mar 16, 2024
1 parent 5546e0c commit b6c1882
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 96 deletions.
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,24 +206,27 @@ Schema: ./tests/schemas/demo_invalid.yml
Found CSV files: 3
(1/3) Invalid file: ./tests/fixtures/batch/demo-1.csv
+------+------------------+--------------+----------------- demo-1.csv -----------------------------------------------------------+
| Line | id:Column | Rule | Message |
+------+------------------+--------------+----------------------------------------------------------------------------------------+
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 1, total: 2 |
| 3 | 2:Float | num_max | The number of the "74605.944" is 74605.944, which is greater than the expected "74605" |
| 3 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
+------+------------------+--------------+----------------- demo-1.csv -----------------------------------------------------------+
+------+------------------+--------------+-------------- demo-1.csv -------------------------------------------------------+
| Line | id:Column | Rule | Message |
+------+------------------+--------------+---------------------------------------------------------------------------------+
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 1, total: 2 |
| 3 | 2:Float | num_max | The number of the value "74605.944", which is greater than the expected "74605" |
| 3 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
+------+------------------+--------------+-------------- demo-1.csv -------------------------------------------------------+
(2/3) Invalid file: ./tests/fixtures/batch/demo-2.csv
+------+------------+------------+------------------ demo-2.csv ----------------------------------------------------+
| Line | id:Column | Rule | Message |
+------+------------+------------+----------------------------------------------------------------------------------+
| 2 | 0:Name | length_min | The length of the "Carl" is 4, which is less than the expected "5" |
| 7 | 0:Name | length_min | The length of the "Lois" is 4, which is less than the expected "5" |
| 2 | 3:Birthday | date_min | Value "1955-05-14" is less than the minimum date "1955-05-15T00:00:00.000+00:00" |
| 4 | 3:Birthday | date_min | Value "1955-05-14" is less than the minimum date "1955-05-15T00:00:00.000+00:00" |
| 5 | 3:Birthday | date_max | Value "2010-07-20" is more than the maximum date "2009-01-01T00:00:00.000+00:00" |
+------+------------+------------+------------------ demo-2.csv ----------------------------------------------------+
+------+------------+------------+-------------------------- demo-2.csv ------------------------------------------------------------+
| Line | id:Column | Rule | Message |
+------+------------+------------+--------------------------------------------------------------------------------------------------+
| 2 | 0:Name | length_min | The length of the value "Carl" is 4, which is less than the expected "5" |
| 7 | 0:Name | length_min | The length of the value "Lois" is 4, which is less than the expected "5" |
| 2 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than |
| | | | the expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
| 4 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than |
| | | | the expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
| 5 | 3:Birthday | date_max | The date of the value "2010-07-20" is parsed as "2010-07-20 00:00:00 +00:00", which is greater |
| | | | than the expected "2009-01-01 00:00:00 +00:00 (2009-01-01)" |
+------+------------+------------+-------------------------- demo-2.csv ------------------------------------------------------------+
(3/3) Invalid file: ./tests/fixtures/batch/sub/demo-3.csv
+------+-----------+------------------+---------------------- demo-3.csv ------------------------------------------------------------+
Expand Down
12 changes: 6 additions & 6 deletions src/Rules/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function ruleDiscovery(
string $origRuleName,
null|array|bool|float|int|string $options = null,
): AbstarctRule {
$postfix = AbstractCombo::parseMode($origRuleName);
$noCombo = \preg_replace("/(_{$postfix})\$/", '', $origRuleName);
$mode = AbstractCombo::parseMode($origRuleName);
$noCombo = \preg_replace("/(_{$mode})\$/", '', $origRuleName);

$origRuleClass = Utils::kebabToCamelCase($origRuleName);
$comboRuleClass = Utils::kebabToCamelCase("combo_{$noCombo}");
Expand All @@ -61,7 +61,7 @@ public function ruleDiscovery(
foreach ([$origRuleClass, $comboRuleClass] as $ruleClass) {
$posibleClassName = __NAMESPACE__ . "\\{$group}\\{$ruleClass}";

$rule = $this->createRuleClassAttempt($posibleClassName, $origRuleName, $options);
$rule = $this->createRuleClassAttempt($posibleClassName, $options, $mode);
if ($rule !== null) {
return $rule;
}
Expand All @@ -77,12 +77,12 @@ public function ruleDiscovery(
*/
private function createRuleClassAttempt(
string $posibleClassName,
string $ruleName,
null|array|bool|float|int|string $options = null,
null|array|bool|float|int|string $options,
string $mode,
): ?AbstarctRule {
if (\class_exists($posibleClassName)) {
// @phpstan-ignore-next-line
return new $posibleClassName($this->columnNameId, $options, $ruleName);
return new $posibleClassName($this->columnNameId, $options, $mode);
}

return null;
Expand Down
Loading

0 comments on commit b6c1882

Please sign in to comment.