Skip to content

Commit

Permalink
update 'optimze' method to accept only DataRulesInterface instead cal…
Browse files Browse the repository at this point in the history
…lback
  • Loading branch information
BMTmohammedtaha committed Nov 17, 2023
1 parent 98b6f64 commit a6d437a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/DataOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Effectra\DataOptimizer;

use Effectra\Database\Exception\DataValidatorException;
use Effectra\DataOptimizer\Contracts\DataRulesInterface;

/**
* DataOptimizer class for optimizing and transforming data based on defined rules.
Expand All @@ -19,7 +20,7 @@ class DataOptimizer
/**
* @var DataRules $data_rule The data validation rules.
*/
private DataRules $data_rule;
private DataRulesInterface $data_rule;

/**
* Constructor for DataOptimizer.
Expand All @@ -35,8 +36,6 @@ public function __construct($data)
}

$this->data = $data;

$this->data_rule = new DataRules();
}

/**
Expand Down Expand Up @@ -130,14 +129,13 @@ public function applyRule(string $rule, string $key, $value): Result
/**
* Optimize the data based on defined rules.
*
* @param callable $rules A callback function to define rules using DataRules.
* @param DataRulesInterface $rules define rules using DataRulesInterface.
* @return array The optimized data.
*/
public function optimize($rules): array
public function optimize(DataRulesInterface $rules): array
{
$data = [];
call_user_func($rules, $this->data_rule);
$this->data_rule->getRules();
$this->data_rule = $rules;

if ((new DataValidator($this->data))->isArrayOfAssoc()) {

Expand Down

0 comments on commit a6d437a

Please sign in to comment.