Skip to content

Commit

Permalink
Tweaked types for phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Dec 14, 2019
1 parent 318ad67 commit 152f46a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
3 changes: 1 addition & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ parameters:
level: max
ignoreErrors:
- '/\$arguments [a-z ]+ no value type specified in iterable type array/'
- '#Method PhpOption\\None::getOr[a-zA-Z]+\(\) should return T but returns S.#'
- '#Method PhpOption\\Option::fromArraysValue\(\) should return PhpOption\\Option<T> but returns PhpOption\\Some<T>.#'
- '#Method PhpOption\\Option::fromValue\(\) should return PhpOption\\Option<S> but returns PhpOption\\Some<N|S>.#'
37 changes: 24 additions & 13 deletions src/PhpOption/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ abstract class Option implements IteratorAggregate
* case, and everything else as Some.
*
* @template S
* @template N
*
* @param T|S $value The actual return value.
* @param S $noneValue The value which should be considered "None"; null by
* @param S|N $value The actual return value.
* @param N $noneValue The value which should be considered "None"; null by
* default.
*
* @return Option<T>
* @return Option<S>
*/
public static function fromValue($value, $noneValue = null)
{
Expand All @@ -59,10 +60,12 @@ public static function fromValue($value, $noneValue = null)
* array, or the array's value at the given key is null, None is returned.
* Otherwise, Some is returned wrapping the value at the given key.
*
* @param array<string,T>|ArrayAccess<string,T>|null $array A potential array or \ArrayAccess value.
* @template S
*
* @param array<string,S>|ArrayAccess<string,S>|null $array A potential array or \ArrayAccess value.
* @param string $key The key to check.
*
* @return Option<T>
* @return Option<S>
*/
public static function fromArraysValue($array, $key)
{
Expand All @@ -80,12 +83,15 @@ public static function fromArraysValue($array, $key)
* the return value is not yet an option. By default, we treat ``null`` as
* None case, and everything else as Some.
*
* @template S
* @template N
*
* @param callable $callback The callback to evaluate.
* @param array $arguments The arguments for the callback.
* @param mixed $noneValue The value which should be considered "None"; null
* by default.
* @param N $noneValue The value which should be considered "None";
* null by default.
*
* @return Option<T>
* @return LazyOption<S>
*/
public static function fromReturn($callback, array $arguments = [], $noneValue = null)
{
Expand All @@ -108,11 +114,14 @@ public static function fromReturn($callback, array $arguments = [], $noneValue =
* returned from callback, it returns directly. On other case value passed
* to Option::fromValue() method.
*
* @param Option<T>|callable|T $value
* @param mixed $noneValue Used when $value is mixed or
* callable, for None-check.
* @template S
* @template N
*
* @return Option<T>
* @param Option<S>|callable|S|N $value
* @param N $noneValue Used when $value is mixed or
* callable, for None-check.
*
* @return Option<S>|LazyOption<S>
*/
public static function ensure($value, $noneValue = null)
{
Expand Down Expand Up @@ -142,10 +151,12 @@ public static function ensure($value, $noneValue = null)
* original callback and return the value inside a new Option, unless an
* Option is returned from the function, in which case, we use that.
*
* @template S
*
* @param callable $callback
* @param mixed $noneValue
*
* @return callable
* @return callable(): Option<S>|LazyOption<S>
*/
public static function lift($callback, $noneValue = null)
{
Expand Down
9 changes: 7 additions & 2 deletions vendor-bin/phpstan/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"require": {
"phpstan/phpstan": "^0.12.2"
}
"phpstan/phpstan": "^0.12.3"
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "dev",
"prefer-stable": true
}

0 comments on commit 152f46a

Please sign in to comment.