Skip to content

Commit

Permalink
Merge pull request #97 from gsteel/boolean-int-mask
Browse files Browse the repository at this point in the history
Boolean filter constructor should accept int mask of types
  • Loading branch information
Ocramius committed Jan 12, 2023
2 parents ace4d14 + adc7ecc commit 548a659
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
5 changes: 1 addition & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.3.0@b6faa3e96b8eb50ec71384c53799b8a107236bb6">
<files psalm-version="5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863">
<file src="src/AbstractDateDropdown.php">
<MissingReturnType occurrences="1">
<code>filterable</code>
Expand Down Expand Up @@ -1373,9 +1373,6 @@
<ArgumentTypeCoercion occurrences="1">
<code>$type</code>
</ArgumentTypeCoercion>
<InvalidArgument occurrences="1">
<code>true</code>
</InvalidArgument>
<MixedArgument occurrences="4">
<code>$value</code>
<code>$value</code>
Expand Down
5 changes: 3 additions & 2 deletions src/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class Boolean extends AbstractFilter
];

/**
* @param self::TYPE_*|value-of<self::CONSTANTS>|list<self::TYPE_*>|Options|iterable|null $typeOrOptions
* phpcs:ignore Generic.Files.LineLength.TooLong
* @param self::TYPE_*|value-of<self::CONSTANTS>|list<self::TYPE_*>|int-mask-of<self::TYPE_*>|Options|iterable|null $typeOrOptions
* @param bool $casting
* @param array $translations
*/
Expand Down Expand Up @@ -102,7 +103,7 @@ public function __construct($typeOrOptions = null, $casting = true, $translation
/**
* Set boolean types
*
* @param self::TYPE_*|value-of<self::CONSTANTS>|list<self::TYPE_*>|null $type
* @param self::TYPE_*|int-mask-of<self::TYPE_*>|value-of<self::CONSTANTS>|list<self::TYPE_*>|null $type
* @throws Exception\InvalidArgumentException
* @return self
*/
Expand Down
1 change: 1 addition & 0 deletions test/BooleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function testSettingFalseType(): void
$filter = new BooleanFilter();
$this->expectException(Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Unknown type value');
/** @psalm-suppress InvalidScalarArgument */
$filter->setType(true);
}

Expand Down
41 changes: 41 additions & 0 deletions test/StaticAnalysis/BooleanFilterChecks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Filter\StaticAnalysis;

use Laminas\Filter;

final class BooleanFilterChecks
{
public function constructorAcceptsSingleTypeConstant(): Filter\Boolean
{
return new Filter\Boolean(Filter\Boolean::TYPE_FLOAT);
}

public function constructorAcceptsListOfConstants(): Filter\Boolean
{
return new Filter\Boolean([
Filter\Boolean::TYPE_EMPTY_ARRAY,
Filter\Boolean::TYPE_FALSE_STRING,
]);
}

public function constructorAcceptsIntMaskOfConstants(): Filter\Boolean
{
return new Filter\Boolean(Filter\Boolean::TYPE_ALL ^ Filter\Boolean::TYPE_FLOAT);
}

public function constructorAcceptsNamedType(): Filter\Boolean
{
return new Filter\Boolean('localized');
}

public function constructorAcceptsOptionsArray(): Filter\Boolean
{
return new Filter\Boolean([
'type' => Filter\Boolean::TYPE_FALSE_STRING | Filter\Boolean::TYPE_FLOAT,
'casting' => false,
]);
}
}

0 comments on commit 548a659

Please sign in to comment.