-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractAggregateRule.php
More file actions
53 lines (45 loc) · 1.77 KB
/
Copy pathAbstractAggregateRule.php
File metadata and controls
53 lines (45 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?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\AbstractRule;
abstract class AbstractAggregateRule extends AbstractRule
{
public const INPUT_TYPE = AbstractRule::INPUT_TYPE_STRINGS;
/**
* Validates a rule based on the given column values.
* @param string[] $columnValues The column values to validate against the rule
* @return null|string The error message if the rule is not valid, null otherwise
*/
abstract public function validateRule(array $columnValues): ?string;
/**
* The metod for Unit tests only! Let's say it's a lifehack :).
* @param array $cellValue The input array for testing
* @param bool $isHtml Whether to return the error message as HTML or plain text
* @return string The error message, either as HTML or plain text, based on the value of $isHtml
*/
public function test(array $cellValue, bool $isHtml = false): string
{
$errorMessage = (string)$this->validateRule($cellValue);
return $isHtml ? $errorMessage : \strip_tags($errorMessage);
}
/**
* Get rule code method.
* @param null|string $mode (optional) The mode for getting the rule code (default: null)
* @return string The rule code with prefix 'ag:'
*/
public function getRuleCode(?string $mode = null): string
{
return 'ag:' . parent::getRuleCode($mode);
}
}