-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38586be
commit 4bbd267
Showing
4 changed files
with
140 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of SebastianFeldmann\Git. | ||
* | ||
* (c) Sebastian Feldmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SebastianFeldmann\Git\Diff; | ||
|
||
/** | ||
* Filter utility class | ||
* | ||
* | ||
* @author Sebastian Feldmann <[email protected]> | ||
* @link https://github.com/sebastianfeldmann/git | ||
* @since Class available since Release 3.9.0 | ||
*/ | ||
abstract class FilterUtil | ||
{ | ||
/** | ||
* Remove all invalid filter options | ||
* | ||
* @param array<int, string> $filter | ||
* @return array<int, string> | ||
*/ | ||
public static function sanitize(array $filter): array | ||
{ | ||
return array_filter($filter, fn($e) => in_array($e, ['A', 'C', 'D', 'M', 'R', 'T', 'U', 'X', 'B', '*']) ); | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of SebastianFeldmann\Git. | ||
* | ||
* (c) Sebastian Feldmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SebastianFeldmann\Git\Diff; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class FilterUtilTest extends TestCase | ||
{ | ||
/** | ||
* Tests FilterUtil::sanitize | ||
*/ | ||
public function testSanitize(): void | ||
{ | ||
$sanitized = FilterUtil::sanitize(['A', 'C', 'Z']); | ||
|
||
$this->assertFalse(in_array('Z', $sanitized)); | ||
$this->assertTrue(in_array('A', $sanitized)); | ||
$this->assertTrue(in_array('C', $sanitized)); | ||
} | ||
|
||
/** | ||
* Tests FilterUtil::sanitize | ||
*/ | ||
public function testSanitizeEmpty(): void | ||
{ | ||
$sanitized = FilterUtil::sanitize(['Q', 'L', 'Z']); | ||
|
||
$this->assertEmpty($sanitized); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters