-
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.
Aggregate rules and refactor rules structure (#27)
The rules structure for the Csv-Blueprint project is reorganized in this change, to better differentiate between "Cell Rules" and "Aggregate Rules". With this change, all former rules are moved into a dedicated rules folder, highlighting their specific focus. This structural change improves the readability of the project and facilitates future additions to the cell rules or aggregate rules.
- Loading branch information
Showing
62 changed files
with
593 additions
and
641 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,33 @@ | ||
<?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\AggregateRules; | ||
|
||
use JBZoo\CsvBlueprint\AbstarctRule; | ||
|
||
abstract class AbstarctAggregateRule extends AbstarctRule | ||
{ | ||
/** | ||
* Validate the rule. | ||
* | ||
* This method takes an array reference &$columnValues as input and returns a nullable string. | ||
* We use a reference to the array to avoid copying the array. Important memory optimization! | ||
* Please DO NOT change the array in this method! | ||
* | ||
* @param string[] $columnValues | ||
*/ | ||
abstract public function validateRule(array &$columnValues): ?string; | ||
} |
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,40 @@ | ||
<?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\AggregateRules; | ||
|
||
final class Unique extends AbstarctAggregateRule | ||
{ | ||
public function validateRule(array &$columnValues): ?string | ||
{ | ||
if (!$this->getOptionAsBool()) { | ||
return null; | ||
} | ||
|
||
if (\count($columnValues) === 0) { | ||
return null; | ||
} | ||
|
||
$uValuesCount = \count(\array_unique($columnValues)); | ||
$valuesCount = \count($columnValues); | ||
|
||
if ($uValuesCount !== $valuesCount) { | ||
return "Column has non-unique values. Unique: <c>{$uValuesCount}</c>, total: <green>{$valuesCount}</green>"; | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.