Skip to content

Commit

Permalink
Revert "Support string assertions resulting in non-empty-string"
Browse files Browse the repository at this point in the history
This reverts commit 9009135.
  • Loading branch information
herndlm authored and ondrejmirtes committed Jan 17, 2022
1 parent 8e664e7 commit 67f970c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 126 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,10 @@ This extension specifies types of values passed to:
* `Assert::methodExists`
* `Assert::propertyExists`
* `Assert::isArrayAccessible`
* `Assert::unicodeLetters`
* `Assert::alpha`
* `Assert::digits`
* `Assert::alnum`
* `Assert::lower`
* `Assert::upper`
* `Assert::length`
* `Assert::minLength`
* `Assert::maxLength`
* `Assert::lengthBetween`
* `Assert::uuid`
* `Assert::ip`
* `Assert::ipv4`
* `Assert::ipv6`
* `Assert::email`
* `Assert::notWhitespaceOnly`
* `nullOr*` and `all*` variants of the above methods


Expand Down
54 changes: 12 additions & 42 deletions src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@
class AssertTypeSpecifyingExtension implements StaticMethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
{

private const ASSERTIONS_RESULTING_IN_NON_EMPTY_STRING = [
'stringNotEmpty',
'unicodeLetters',
'alpha',
'digits',
'alnum',
'lower',
'upper',
'uuid',
'ip',
'ipv4',
'ipv6',
'email',
'notWhitespaceOnly',
];

/** @var \Closure[] */
private static $resolvers;

Expand All @@ -66,10 +50,6 @@ public function isStaticMethodSupported(
TypeSpecifierContext $context
): bool
{
if (in_array($staticMethodReflection->getName(), self::ASSERTIONS_RESULTING_IN_NON_EMPTY_STRING, true)) {
return true;
}

if (substr($staticMethodReflection->getName(), 0, 6) === 'allNot') {
$methods = [
'allNotInstanceOf' => 2,
Expand Down Expand Up @@ -164,11 +144,6 @@ private static function createExpression(
): ?\PhpParser\Node\Expr
{
$trimmedName = self::trimName($name);

if (in_array($trimmedName, self::ASSERTIONS_RESULTING_IN_NON_EMPTY_STRING, true)) {
return self::createIsNonEmptyStringExpression($args);
}

$resolvers = self::getExpressionResolvers();
$resolver = $resolvers[$trimmedName];
$expression = $resolver($scope, ...$args);
Expand Down Expand Up @@ -220,6 +195,18 @@ private static function getExpressionResolvers(): array
[$value]
);
},
'stringNotEmpty' => function (Scope $scope, Arg $value): \PhpParser\Node\Expr {
return new BooleanAnd(
new \PhpParser\Node\Expr\FuncCall(
new \PhpParser\Node\Name('is_string'),
[$value]
),
new NotIdentical(
$value->value,
new String_('')
)
);
},
'float' => function (Scope $scope, Arg $value): \PhpParser\Node\Expr {
return new \PhpParser\Node\Expr\FuncCall(
new \PhpParser\Node\Name('is_float'),
Expand Down Expand Up @@ -687,21 +674,4 @@ private function arrayOrIterable(
);
}

/**
* @param \PhpParser\Node\Arg[] $args
*/
private static function createIsNonEmptyStringExpression(array $args): \PhpParser\Node\Expr
{
return new BooleanAnd(
new \PhpParser\Node\Expr\FuncCall(
new \PhpParser\Node\Name('is_string'),
[$args[0]]
),
new NotIdentical(
$args[0]->value,
new String_('')
)
);
}

}
72 changes: 0 additions & 72 deletions tests/Type/WebMozartAssert/data/string.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,76 +49,4 @@ public function lengthBetween(string $a, string $b, string $c, string $d): void
\PHPStan\Testing\assertType('non-empty-string', $d);
}

public function unicodeLetters($a): void
{
Assert::unicodeLetters($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function alpha($a): void
{
Assert::alpha($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function digits(string $a): void
{
Assert::digits($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function alnum(string $a): void
{
Assert::alnum($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function lower(string $a): void
{
Assert::lower($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function upper(string $a): void
{
Assert::upper($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function uuid(string $a): void
{
Assert::uuid($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function ip($a): void
{
Assert::ip($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function ipv4($a): void
{
Assert::ipv4($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function ipv6($a): void
{
Assert::ipv6($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function email($a): void
{
Assert::email($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

public function notWhitespaceOnly(string $a): void
{
Assert::notWhitespaceOnly($a);
\PHPStan\Testing\assertType('non-empty-string', $a);
}

}

0 comments on commit 67f970c

Please sign in to comment.