-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from rdohms/kdadler-php8-nullable-fields
PHP 8 fixes
- Loading branch information
Showing
16 changed files
with
176 additions
and
32 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 |
---|---|---|
@@ -1,30 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
verbose="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
beStrictAboutChangesToGlobalState="true" | ||
> | ||
<testsuites> | ||
<testsuite name="DMS Filter Suite"> | ||
<directory>tests/DMS</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/DMS</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<logging> | ||
<log type="coverage-html" target="tests/_reports/coverage/" lowUpperBound="35" highLowerBound="70"/> | ||
<log type="testdox-text" target="tests/_reports/testdox/tests.txt"/> | ||
<log type="testdox-html" target="tests/_reports/testdox/tests.html"/> | ||
</logging> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" verbose="true" beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" beStrictAboutChangesToGlobalState="true"> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src/DMS</directory> | ||
</include> | ||
<report> | ||
<html outputDirectory="tests/_reports/coverage/" lowUpperBound="35" highLowerBound="70"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="DMS Filter Suite"> | ||
<directory>tests/DMS</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<testdoxText outputFile="tests/_reports/testdox/tests.txt"/> | ||
<testdoxHtml outputFile="tests/_reports/testdox/tests.html"/> | ||
</logging> | ||
</phpunit> |
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,64 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DMS\Filter\Filters; | ||
|
||
use DMS\Filter\Exception\InvalidZendFilterException; | ||
use DMS\Filter\FilterInterface; | ||
use DMS\Filter\Rules\Laminas as LaminasRule; | ||
use DMS\Filter\Rules\Rule; | ||
use ReflectionException; | ||
use ReflectionMethod; | ||
|
||
use function class_exists; | ||
use function sprintf; | ||
use function strpos; | ||
|
||
/** | ||
* Laminas Filter | ||
* | ||
* Instantiates and runs Laminas Filters (from ZF2) | ||
*/ | ||
class Laminas extends BaseFilter | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param LaminasRule $rule | ||
*/ | ||
public function apply(Rule $rule, $value) | ||
{ | ||
return $this->getLaminasInstance($rule->class, $rule->laminasOptions)->filter($value); | ||
} | ||
|
||
/** | ||
* Instantiates a configured Laminas Filter, if it exists | ||
* | ||
* @param mixed[] $options | ||
* | ||
* @return FilterInterface|object | ||
* | ||
* @throws InvalidZendFilterException | ||
*/ | ||
public function getLaminasInstance(string $class, array $options): object | ||
{ | ||
if (strpos($class, 'Laminas\Filter') === false) { | ||
$class = 'Laminas\Filter\\' . $class; | ||
} | ||
|
||
if (! class_exists($class)) { | ||
throw new InvalidZendFilterException(sprintf('Could not find or autoload: %s', $class)); | ||
} | ||
|
||
try { | ||
new ReflectionMethod($class, 'setOptions'); | ||
|
||
$filter = new $class(); | ||
$filter->setOptions($options); | ||
|
||
return $filter; | ||
} catch (ReflectionException $e) { | ||
return new $class($options); | ||
} | ||
} | ||
} |
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
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
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,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DMS\Filter\Rules; | ||
|
||
/** | ||
* Laminas Rule | ||
* | ||
* Allows the use for Laminas Filters | ||
* | ||
* @Annotation | ||
*/ | ||
class Laminas extends Rule | ||
{ | ||
/** | ||
* Laminas\Filter class, can be either a FQN or just Boolean for example | ||
*/ | ||
public string $class; | ||
|
||
/** | ||
* Array of options to be passed into the Laminas Filter | ||
* | ||
* @var mixed[] | ||
*/ | ||
public array $laminasOptions = []; | ||
|
||
public function getDefaultOption(): ?string | ||
{ | ||
return 'class'; | ||
} | ||
} |
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
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,46 @@ | ||
<?php | ||
|
||
|
||
namespace DMS\Filter\Filters; | ||
|
||
use DMS\Filter\Exception\InvalidZendFilterException; | ||
use DMS\Filter\Rules\Laminas as LaminasRule; | ||
use DMS\Tests\FilterTestCase; | ||
|
||
class LaminasTest extends FilterTestCase | ||
{ | ||
|
||
public function testFilterShortname(): void | ||
{ | ||
$rule = $this->buildRule('Boolean', ['casting' => false]); | ||
$filter = new Laminas(); | ||
$filter->apply($rule, '0'); | ||
$this->expectNotToPerformAssertions(); | ||
} | ||
|
||
public function testFilterFullname(): void | ||
{ | ||
$rule = $this->buildRule('Laminas\Filter\Boolean', ['casting' => false]); | ||
$filter = new Laminas(); | ||
$filter->apply($rule, '0'); | ||
$this->expectNotToPerformAssertions(); | ||
} | ||
|
||
public function testInvalidFilter(): void | ||
{ | ||
$this->expectException(InvalidZendFilterException::class); | ||
$rule = $this->buildRule('MissingFilter'); | ||
$filter = new Laminas(); | ||
$filter->apply($rule, '0'); | ||
} | ||
|
||
protected function buildRule($class, $options = []): LaminasRule | ||
{ | ||
return new LaminasRule( | ||
[ | ||
'class' => $class, | ||
'laminasOptions' => $options, | ||
] | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -35,6 +35,7 @@ public function provideForRule(): array | |
null, "My | ||
Text", "MyText" | ||
], | ||
[null, null, null], | ||
]; | ||
} | ||
} |
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
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