Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Throwable;

/**
* @template T of mixed type of non-null value

Check notice on line 11 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [Disallow mixed type hint] Usage of "mixed" type hint is disallowed.
*
* @implements JavaSe8\Optional<T>
*/
Expand All @@ -22,7 +22,7 @@
final protected function __construct(
protected readonly mixed $value,
) {
if ($this->value !== null && !@static::isSupported($this->value)) {

Check notice on line 25 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [No silenced errors] Silencing errors is discouraged; found: @static::isSupported... * [Space after not] Expected 1 space(s) after NOT operator; 0 found
throw new InvalidArgumentException('Value is not supported.');
}
}
Expand Down Expand Up @@ -58,12 +58,12 @@
if (static::class === Optional::class) {
if ($value !== null) {
try {
/** @var static */

Check notice on line 61 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [Inline doc comment declaration] Invalid inline documentation comment format "@var static", expected "@var type $variableName Optional description".
return TypedOptional::of($value, Optional::class);
} catch (Exception\CouldNotFindTypedOptionalForValue) {

Check notice on line 63 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [Empty statement] Empty CATCH statement detected
}
}
/** @var static */

Check notice on line 66 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [Inline doc comment declaration] Invalid inline documentation comment format "@var static", expected "@var type $variableName Optional description".
return new class ($value) extends Optional {
protected static function isInstanceOfStatic(object $obj): bool
{
Expand Down Expand Up @@ -115,7 +115,7 @@
$obj->ifPresent(function (mixed $objValue) use (&$equals, $strict): void {
$equals = match (!is_object($this->value) || $strict) {
true => $this->value === $objValue,
false => $this->value == $objValue,

Check notice on line 118 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [Disallow equal operators] Operator == is disallowed, use === instead.
};
});
return $equals ?? $this->value === null;
Expand All @@ -139,7 +139,7 @@
}

/**
* @template U of mixed

Check notice on line 142 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [Disallow mixed type hint] Usage of "mixed" type hint is disallowed.
*
* @param callable(T): JavaSe8\Optional<U> $mapper
*
Expand All @@ -148,13 +148,13 @@
public function flatMap(callable $mapper): self
{
if ($this->value === null) {
/** @var self<U> */

Check notice on line 151 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [Inline doc comment declaration] Invalid inline documentation comment format "@var self<U>", expected "@var type $variableName Optional description".
return Optional::empty();
}

/** @var mixed $mapped */
$mapped = $mapper($this->value);
/** @var self<U> */

Check notice on line 157 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [Inline doc comment declaration] Invalid inline documentation comment format "@var self<U>", expected "@var type $variableName Optional description".
return match (true) {
$mapped instanceof self => $mapped,
$mapped instanceof JavaSe8\Optional => $mapped->isPresent() ? Optional::of($mapped->get()) : Optional::empty(),
Expand Down Expand Up @@ -239,7 +239,7 @@
}

if (is_string($exceptionSupplier)) {
/** @var class-string<E> $exceptionSupplier */

Check notice on line 242 in src/Optional.php

View workflow job for this annotation

GitHub Actions / run

* [Inline doc comment declaration] Missing variable $exceptionSupplier before or after the documentation comment.
if (!class_exists($exceptionSupplier, autoload: true)) {
throw new InvalidArgumentException('Exception supplier must be existing class name.');
}
Expand All @@ -259,20 +259,6 @@
});
}

/**
* @deprecated use {@see self::orElse()}
*
* @todo BC remove it
*
* Inverse of {@see self::ofNullable()}
*
* @return T|null
*/
public function toNullable(): mixed
{
return $this->orElse(null);
}

/**
* @internal overridden by abstracts
*/
Expand Down
14 changes: 0 additions & 14 deletions tests/OptionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,20 +386,6 @@ public static function dataMethodOrElseThrowWorks(): iterable
}
}

#[DataProvider('dataMethodToNullableWorks')]
public function testMethodToNullableWorks(Optional $optional, mixed $expectedValue): void
{
self::assertSame($expectedValue, $optional->toNullable());
}

public static function dataMethodToNullableWorks(): array
{
return self::makeDataSet([
[self::VALUE],
[null],
]);
}

private static function makeDataSet(array $args): array
{
return [
Expand Down