Skip to content

Commit 806d2f8

Browse files
committed
Revert "Support string assertions resulting in non-empty-string"
This reverts commit 9009135.
1 parent c8c033d commit 806d2f8

File tree

3 files changed

+12
-126
lines changed

3 files changed

+12
-126
lines changed

README.md

-12
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,10 @@ This extension specifies types of values passed to:
6969
* `Assert::methodExists`
7070
* `Assert::propertyExists`
7171
* `Assert::isArrayAccessible`
72-
* `Assert::unicodeLetters`
73-
* `Assert::alpha`
74-
* `Assert::digits`
75-
* `Assert::alnum`
76-
* `Assert::lower`
77-
* `Assert::upper`
7872
* `Assert::length`
7973
* `Assert::minLength`
8074
* `Assert::maxLength`
8175
* `Assert::lengthBetween`
82-
* `Assert::uuid`
83-
* `Assert::ip`
84-
* `Assert::ipv4`
85-
* `Assert::ipv6`
86-
* `Assert::email`
87-
* `Assert::notWhitespaceOnly`
8876
* `nullOr*` and `all*` variants of the above methods
8977

9078

src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php

+12-42
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@
2828
class AssertTypeSpecifyingExtension implements StaticMethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
2929
{
3030

31-
private const ASSERTIONS_RESULTING_IN_NON_EMPTY_STRING = [
32-
'stringNotEmpty',
33-
'unicodeLetters',
34-
'alpha',
35-
'digits',
36-
'alnum',
37-
'lower',
38-
'upper',
39-
'uuid',
40-
'ip',
41-
'ipv4',
42-
'ipv6',
43-
'email',
44-
'notWhitespaceOnly',
45-
];
46-
4731
/** @var \Closure[] */
4832
private static $resolvers;
4933

@@ -66,10 +50,6 @@ public function isStaticMethodSupported(
6650
TypeSpecifierContext $context
6751
): bool
6852
{
69-
if (in_array($staticMethodReflection->getName(), self::ASSERTIONS_RESULTING_IN_NON_EMPTY_STRING, true)) {
70-
return true;
71-
}
72-
7353
if (substr($staticMethodReflection->getName(), 0, 6) === 'allNot') {
7454
$methods = [
7555
'allNotInstanceOf' => 2,
@@ -164,11 +144,6 @@ private static function createExpression(
164144
): ?\PhpParser\Node\Expr
165145
{
166146
$trimmedName = self::trimName($name);
167-
168-
if (in_array($trimmedName, self::ASSERTIONS_RESULTING_IN_NON_EMPTY_STRING, true)) {
169-
return self::createIsNonEmptyStringExpression($args);
170-
}
171-
172147
$resolvers = self::getExpressionResolvers();
173148
$resolver = $resolvers[$trimmedName];
174149
$expression = $resolver($scope, ...$args);
@@ -220,6 +195,18 @@ private static function getExpressionResolvers(): array
220195
[$value]
221196
);
222197
},
198+
'stringNotEmpty' => function (Scope $scope, Arg $value): \PhpParser\Node\Expr {
199+
return new BooleanAnd(
200+
new \PhpParser\Node\Expr\FuncCall(
201+
new \PhpParser\Node\Name('is_string'),
202+
[$value]
203+
),
204+
new NotIdentical(
205+
$value->value,
206+
new String_('')
207+
)
208+
);
209+
},
223210
'float' => function (Scope $scope, Arg $value): \PhpParser\Node\Expr {
224211
return new \PhpParser\Node\Expr\FuncCall(
225212
new \PhpParser\Node\Name('is_float'),
@@ -687,21 +674,4 @@ private function arrayOrIterable(
687674
);
688675
}
689676

690-
/**
691-
* @param \PhpParser\Node\Arg[] $args
692-
*/
693-
private static function createIsNonEmptyStringExpression(array $args): \PhpParser\Node\Expr
694-
{
695-
return new BooleanAnd(
696-
new \PhpParser\Node\Expr\FuncCall(
697-
new \PhpParser\Node\Name('is_string'),
698-
[$args[0]]
699-
),
700-
new NotIdentical(
701-
$args[0]->value,
702-
new String_('')
703-
)
704-
);
705-
}
706-
707677
}

tests/Type/WebMozartAssert/data/string.php

-72
Original file line numberDiff line numberDiff line change
@@ -49,76 +49,4 @@ public function lengthBetween(string $a, string $b, string $c, string $d): void
4949
\PHPStan\Testing\assertType('non-empty-string', $d);
5050
}
5151

52-
public function unicodeLetters($a): void
53-
{
54-
Assert::unicodeLetters($a);
55-
\PHPStan\Testing\assertType('non-empty-string', $a);
56-
}
57-
58-
public function alpha($a): void
59-
{
60-
Assert::alpha($a);
61-
\PHPStan\Testing\assertType('non-empty-string', $a);
62-
}
63-
64-
public function digits(string $a): void
65-
{
66-
Assert::digits($a);
67-
\PHPStan\Testing\assertType('non-empty-string', $a);
68-
}
69-
70-
public function alnum(string $a): void
71-
{
72-
Assert::alnum($a);
73-
\PHPStan\Testing\assertType('non-empty-string', $a);
74-
}
75-
76-
public function lower(string $a): void
77-
{
78-
Assert::lower($a);
79-
\PHPStan\Testing\assertType('non-empty-string', $a);
80-
}
81-
82-
public function upper(string $a): void
83-
{
84-
Assert::upper($a);
85-
\PHPStan\Testing\assertType('non-empty-string', $a);
86-
}
87-
88-
public function uuid(string $a): void
89-
{
90-
Assert::uuid($a);
91-
\PHPStan\Testing\assertType('non-empty-string', $a);
92-
}
93-
94-
public function ip($a): void
95-
{
96-
Assert::ip($a);
97-
\PHPStan\Testing\assertType('non-empty-string', $a);
98-
}
99-
100-
public function ipv4($a): void
101-
{
102-
Assert::ipv4($a);
103-
\PHPStan\Testing\assertType('non-empty-string', $a);
104-
}
105-
106-
public function ipv6($a): void
107-
{
108-
Assert::ipv6($a);
109-
\PHPStan\Testing\assertType('non-empty-string', $a);
110-
}
111-
112-
public function email($a): void
113-
{
114-
Assert::email($a);
115-
\PHPStan\Testing\assertType('non-empty-string', $a);
116-
}
117-
118-
public function notWhitespaceOnly(string $a): void
119-
{
120-
Assert::notWhitespaceOnly($a);
121-
\PHPStan\Testing\assertType('non-empty-string', $a);
122-
}
123-
12452
}

0 commit comments

Comments
 (0)