Skip to content

Commit

Permalink
Merge pull request #11 from whitedigital-eu/fix/larger-arrays
Browse files Browse the repository at this point in the history
fix: validate n-keyed arrays
  • Loading branch information
raraworks authored Jul 5, 2024
2 parents 20af033 + 45ee0b5 commit 6803dfc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Task/AbstractDocumentTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

use function array_diff;
use function array_diff_key;
use function array_filter;
use function array_flip;
use function array_key_exists;
use function array_keys;
use function count;
use function explode;
use function get_debug_type;
use function implode;
use function is_array;
Expand All @@ -27,6 +29,8 @@
use function preg_replace;
use function sprintf;

use const PHP_INT_MAX;

abstract class AbstractDocumentTask implements Task
{
protected ?string $name = null;
Expand Down Expand Up @@ -110,10 +114,10 @@ protected function validate(array $data): void

foreach ($dataDump as $key => $value) {
$check = $key;
if (preg_match('/\.\d+\./', $check) && preg_match('/[0-9]/', $check) > 0) {
if (preg_match('/\.\d+\./', $check) && preg_match('/\d+/', $check) > 0) {
preg_match_all('/\d+/', $check, $matches);
$check = preg_replace("/\d/", '0', $check);
if ('0' !== $matches[0][0] && isset($fullDump[$check])) {
$check = preg_replace("/\d+/", '0', $check);
if (isset($fullDump[$check]) && !empty(array_filter($matches, static fn ($arr) => array_filter($arr, static fn ($value) => '0' !== $value)))) {
$requiredCount++;
}
}
Expand All @@ -135,9 +139,9 @@ protected function validate(array $data): void

foreach ($fullDump as $key => $value) {
$check = $key;
if (preg_match('/\.\d+\./', $check) && preg_match('/[0-9]/', $check) > 0) {
if (preg_match('/\.\d+\./', $check) && preg_match('/\d+/', $check) > 0) {
preg_match_all('/\d+/', $check, $matches);
$check = preg_replace("/\d/", '0', $check);
$check = preg_replace("/\d+/", '0', $check);
if (!array_key_exists($check, $dataDump)) {
$requiredCount--;
}
Expand Down

0 comments on commit 6803dfc

Please sign in to comment.