Skip to content

Commit

Permalink
MDTT-38: Fix for CI failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
sadeesh-sdet committed Sep 16, 2023
1 parent 53acfe1 commit 078521b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader

- name: Security check installed dependencies
uses: symfonycorp/security-checker-action@v2
uses: symfonycorp/security-checker-action@v4

- name: Check PSR2 code style (PHP_CodeSniffer)
run: composer php-cs
Expand All @@ -47,4 +47,4 @@ jobs:
- name: Send code coverage report to Codecov.io
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
34 changes: 29 additions & 5 deletions src/Test/DefaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class DefaultTest extends Test
{

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -53,20 +52,45 @@ public function execute(array $sourceData, array $destinationData): bool
}

/**
* @param array<string, numeric-string|array<string, numeric-string>>|numeric-string $data
* @param array<string> $fields
* Recursively checks if an offset exists in a nested array.
*
* This function is designed to handle nested arrays and verify the existence of
* a specified offset (string key) within them. It performs recursive checks on
* nested arrays to ensure that the offset exists at each level.
*
* @param array<string, numeric-string|array<string, numeric-string>>|numeric-string $data
* The data array to check for the offset in.
* @param array<string> $fields
* An array of string keys representing the path to the desired offset.
*
* @return bool
* Returns `true` if the specified offset exists in the nested array,
* `false` otherwise.
*
* Used a combination of type hinting and explicit checks to assist PHPStan
* in understanding the types involved and resolving static analysis errors.
*/
private function issetField(mixed $data, array $fields): bool

Check warning on line 73 in src/Test/DefaultTest.php

View check run for this annotation

Codecov / codecov/patch

src/Test/DefaultTest.php#L73

Added line #L73 was not covered by tests
{
// Check if $data is an array
if (!is_array($data)) {
return false;

Check warning on line 77 in src/Test/DefaultTest.php

View check run for this annotation

Codecov / codecov/patch

src/Test/DefaultTest.php#L76-L77

Added lines #L76 - L77 were not covered by tests
}

// Get the next key to check
$key = array_shift($fields);

Check warning on line 81 in src/Test/DefaultTest.php

View check run for this annotation

Codecov / codecov/patch

src/Test/DefaultTest.php#L81

Added line #L81 was not covered by tests

// If there are no more keys to check, the offset exists
if ($key === null) {
return true;

Check warning on line 85 in src/Test/DefaultTest.php

View check run for this annotation

Codecov / codecov/patch

src/Test/DefaultTest.php#L84-L85

Added lines #L84 - L85 were not covered by tests
}

$test = isset($data[$key]);
// Check if the key exists in the data array
if (!array_key_exists($key, $data)) {
return false;

Check warning on line 90 in src/Test/DefaultTest.php

View check run for this annotation

Codecov / codecov/patch

src/Test/DefaultTest.php#L89-L90

Added lines #L89 - L90 were not covered by tests
}

return $test && $this->issetField($data[$key], $fields);
// Recursively check the next level
return $this->issetField($data[$key], $fields);

Check warning on line 94 in src/Test/DefaultTest.php

View check run for this annotation

Codecov / codecov/patch

src/Test/DefaultTest.php#L94

Added line #L94 was not covered by tests
}
}

0 comments on commit 078521b

Please sign in to comment.