Skip to content

Commit

Permalink
Marking pure API with @psalm-pure for usage in pure downstream cons…
Browse files Browse the repository at this point in the history
…umers
  • Loading branch information
Ocramius committed Dec 11, 2019
1 parent 0bfafd8 commit 500f5d2
Show file tree
Hide file tree
Showing 39 changed files with 163 additions and 2 deletions.
99 changes: 99 additions & 0 deletions src/Assert.php

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/static-analysis/assert-alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): string
Expand All @@ -14,6 +15,9 @@ function consume($value): string
return $value;
}

/**
* @psalm-pure
*/
function consumeNullableString(?string $value): string
{
Assert::alpha($value);
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): bool
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-classExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


/**
* @psalm-pure
* @param mixed $value
*
* @return string
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-false.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @param mixed $value
*/
function consume($value): bool
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-float.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): float
Expand Down
4 changes: 4 additions & 0 deletions tests/static-analysis/assert-implementsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ interface ImplementsInterfaceC
/**
* @param mixed $value
*
* @psalm-pure
*
* @psalm-return class-string<ImplementsInterfaceA> $value
*/
function consumeMixed($value): string
Expand All @@ -29,6 +31,8 @@ function consumeMixed($value): string
}

/**
* @psalm-pure
*
* @psalm-param class-string<ImplementsInterfaceB>|class-string<ImplementsInterfaceC> $value
*
* @psalm-return class-string<ImplementsInterfaceB> $value
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): int
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-integerish.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param string|numeric $value
*
* @psalm-return numeric
Expand Down
2 changes: 2 additions & 0 deletions tests/static-analysis/assert-interfaceExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* @param mixed $value
*
* @return string
*
* @psalm-pure
* @psalm-return class-string
*/
function consume($value): string
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-isArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): array
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-isArrayAccessible.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*
* @return array|\ArrayAccess
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-isCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): callable
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-isCountable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param object $value
*/
function consume($value): Countable
Expand Down
3 changes: 2 additions & 1 deletion tests/static-analysis/assert-isEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@


/**
* @psalm-pure
*
* @return null
*/
function consume(?object $value)
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-isInstanceOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @param mixed $value
*/
function consume($value) : stdClass
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-isIterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): iterable
Expand Down
4 changes: 4 additions & 0 deletions tests/static-analysis/assert-isList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
*
* @psalm-param mixed $value
*
* @psalm-return list<mixed>
Expand All @@ -17,6 +19,8 @@ function consume($value): array
}

/**
* @psalm-pure
*
* @psalm-param array<\stdClass> $value
*
* @psalm-return list<\stdClass>
Expand Down
4 changes: 4 additions & 0 deletions tests/static-analysis/assert-isMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
*
* @param mixed $value
*
* @return array<string, mixed>
Expand All @@ -19,6 +21,8 @@ function consume($value): array
/**
* Verifying that the type of the elements in the array is preserved by the assertion
*
* @psalm-pure
*
* @param array<int|string, \stdClass> $value
*
* @return array<string, \stdClass>
Expand Down
2 changes: 2 additions & 0 deletions tests/static-analysis/assert-isNonEmptyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
*
* @psalm-param mixed $value
*
* @psalm-return non-empty-list<mixed>
Expand Down
4 changes: 4 additions & 0 deletions tests/static-analysis/assert-isNonEmptyMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
*
* @param mixed $value
*
* @return array<string, mixed>
Expand All @@ -19,6 +21,8 @@ function consume($value): array
/**
* Verifying that the type of the elements in the array is preserved by the assertion
*
* @psalm-pure
*
* @param array<int|string, \stdClass> $value
*
* @return array<string, \stdClass>
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-isTraversable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): iterable
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-natural.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): int
Expand Down
3 changes: 3 additions & 0 deletions tests/static-analysis/assert-notEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Webmozart\Assert\Assert;

/**
* @psalm-pure
*/
function consume(?object $value): object
{
Assert::notEmpty($value);
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-notInstanceOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class NotA {}
class NotB {}

/**
* @psalm-pure
* @param NotA|NotB $value
*/
function consume($value): NotA
Expand Down
3 changes: 3 additions & 0 deletions tests/static-analysis/assert-notNull.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Webmozart\Assert\Assert;

/**
* @psalm-pure
*/
function consume(?object $value): object
{
Assert::notNull($value);
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-null.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @return null
*/
function consume(?object $value)
Expand Down
3 changes: 2 additions & 1 deletion tests/static-analysis/assert-numeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use Webmozart\Assert\Assert;

/**
* @psalm-param string|numeric $value
* @psalm-pure
* @psalm-param mixed $value
*
* @psalm-return numeric
*/
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-object.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): object
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*
* @return resource
Expand Down
3 changes: 3 additions & 0 deletions tests/static-analysis/assert-same.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): string
Expand All @@ -16,6 +17,7 @@ function consume($value): string
}

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consumeWillInferObject($value): stdClass
Expand All @@ -26,6 +28,7 @@ function consumeWillInferObject($value): stdClass
}

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consumeWillInferArray($value): array
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-scalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param \Exception|bool $value
*/
function consume($value): bool
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-startsWithLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): string
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-string.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): string
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-stringNotEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): string
Expand Down
2 changes: 2 additions & 0 deletions tests/static-analysis/assert-subclassOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SubclassOfC
/**
* @param mixed $value
*
* @psalm-pure
* @psalm-return class-string<SubclassOfA> $value
*/
function consumeMixed($value): string
Expand All @@ -29,6 +30,7 @@ function consumeMixed($value): string
}

/**
* @psalm-pure
* @psalm-param class-string<SubclassOfB>|class-string<SubclassOfC> $value
*
* @psalm-return class-string<SubclassOfB> $value
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-true.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @param mixed $value
*/
function consume($value): bool
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-unicodeLetters.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
*/
function consume($value): string
Expand Down
1 change: 1 addition & 0 deletions tests/static-analysis/assert-validArrayKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Webmozart\Assert\Assert;

/**
* @psalm-pure
* @psalm-param mixed $value
* @param array<int> $array
*
Expand Down

0 comments on commit 500f5d2

Please sign in to comment.