Skip to content

Commit

Permalink
added RuleHelper, release 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Apr 11, 2024
1 parent 37e3891 commit 2ee5cff
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/RuleHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace leandrogehlen\querybuilder;

class RuleHelper
{

/**
* Adds a table prefix for any field in conditions if not existing
* @param array $rules for Translator
* @param string $prefix
* @return array
*/
public static function addPrefixToRules(array $rules, string $prefix) : array

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.4)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() has parameter $rules with no value type specified in iterable type array.

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.4)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() return type has no value type specified in iterable type array.

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() has parameter $rules with no value type specified in iterable type array.

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() return type has no value type specified in iterable type array.

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.1)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() has parameter $rules with no value type specified in iterable type array.

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.1)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() return type has no value type specified in iterable type array.

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.2)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() has parameter $rules with no value type specified in iterable type array.

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.2)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() return type has no value type specified in iterable type array.

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.3)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() has parameter $rules with no value type specified in iterable type array.

Check failure on line 14 in src/RuleHelper.php

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.3)

Method leandrogehlen\querybuilder\RuleHelper::addPrefixToRules() return type has no value type specified in iterable type array.
{
if (!isset($rules['rules']) || !$rules['rules']) {
return $rules;
}

$out = [];
foreach ($rules['rules'] as $key => $rule) {
if (isset($rule['condition'])) {
$out[$key] = static::addPrefixToRules($rule, $prefix);
} else {
if(!str_contains($rule['field'], ".")) {
$rule['field'] = "$prefix.".$rule['field'];
}
$out[$key] = $rule;
}
}
$rules['rules'] = $out;
return $rules;

}




}

0 comments on commit 2ee5cff

Please sign in to comment.