Skip to content

Commit 3efd432

Browse files
committed
make resolvers return attempts
1 parent 894cd04 commit 3efd432

17 files changed

Lines changed: 44 additions & 45 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Changed
66

77
- `Innmind\HttpAuthentication\Authenticator::__invoke()` now returns an `Innmind\Immutable\Attempt`
8+
- All resolvers now return an `Innmind\Immutable\Attempt`
89

910
## 4.0.0 - 2023-11-01
1011

src/ViaAuthorization.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __invoke(ServerRequest $request): Attempt
3030
->find(Authorization::class)
3131
->flatMap(static fn($header) => $header->values()->find(static fn() => true))
3232
->keep(Instance::of(AuthorizationValue::class))
33-
->flatMap(fn($value) => ($this->resolve)($value))
34-
->attempt(static fn() => new \RuntimeException('Failed to resolve identity'));
33+
->attempt(static fn() => new \RuntimeException('Failed to resolve identity'))
34+
->flatMap(fn($value) => ($this->resolve)($value));
3535
}
3636
}

src/ViaAuthorization/NullResolver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
use Innmind\HttpAuthentication\Identity;
77
use Innmind\Http\Header\AuthorizationValue;
8-
use Innmind\Immutable\Maybe;
8+
use Innmind\Immutable\Attempt;
99

1010
final class NullResolver implements Resolver
1111
{
12-
public function __invoke(AuthorizationValue $value): Maybe
12+
public function __invoke(AuthorizationValue $value): Attempt
1313
{
14-
/** @var Maybe<Identity> */
15-
return Maybe::nothing();
14+
/** @var Attempt<Identity> */
15+
return Attempt::error(new \LogicException('Not implemented'));
1616
}
1717
}

src/ViaAuthorization/Resolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
use Innmind\HttpAuthentication\Identity;
77
use Innmind\Http\Header\AuthorizationValue;
8-
use Innmind\Immutable\Maybe;
8+
use Innmind\Immutable\Attempt;
99

1010
interface Resolver
1111
{
1212
/**
13-
* @return Maybe<Identity>
13+
* @return Attempt<Identity>
1414
*/
15-
public function __invoke(AuthorizationValue $value): Maybe;
15+
public function __invoke(AuthorizationValue $value): Attempt;
1616
}

src/ViaBasicAuthorization.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public function __invoke(ServerRequest $request): Attempt
2525
->headers()
2626
->find(Authorization::class)
2727
->filter(static fn($header) => $header->scheme() === 'Basic')
28+
->attempt(static fn() => new \RuntimeException('Failed to resolve identity'))
2829
->flatMap(function($header) {
2930
[$user, $password] = \explode(':', \base64_decode($header->parameter(), true));
3031

3132
return ($this->resolve)($user, $password);
32-
})
33-
->attempt(static fn() => new \RuntimeException('Failed to resolve identity'));
33+
});
3434
}
3535
}

src/ViaBasicAuthorization/NullResolver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
namespace Innmind\HttpAuthentication\ViaBasicAuthorization;
55

66
use Innmind\HttpAuthentication\Identity;
7-
use Innmind\Immutable\Maybe;
7+
use Innmind\Immutable\Attempt;
88

99
final class NullResolver implements Resolver
1010
{
11-
public function __invoke(string $user, string $password): Maybe
11+
public function __invoke(string $user, string $password): Attempt
1212
{
13-
/** @var Maybe<Identity> */
14-
return Maybe::nothing();
13+
/** @var Attempt<Identity> */
14+
return Attempt::error(new \LogicException('Not implemented'));
1515
}
1616
}

src/ViaBasicAuthorization/Resolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
namespace Innmind\HttpAuthentication\ViaBasicAuthorization;
55

66
use Innmind\HttpAuthentication\Identity;
7-
use Innmind\Immutable\Maybe;
7+
use Innmind\Immutable\Attempt;
88

99
interface Resolver
1010
{
1111
/**
12-
* @return Maybe<Identity>
12+
* @return Attempt<Identity>
1313
*/
14-
public function __invoke(string $user, string $password): Maybe;
14+
public function __invoke(string $user, string $password): Attempt;
1515
}

src/ViaForm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __invoke(ServerRequest $request): Attempt
2626
{
2727
return Maybe::just($request)
2828
->filter(static fn($request) => $request->method() === Method::post)
29-
->flatMap(fn($request) => ($this->resolve)($request->form()))
30-
->attempt(static fn() => new \RuntimeException('Failed to resolve identity'));
29+
->attempt(static fn() => new \RuntimeException('Failed to resolve identity'))
30+
->flatMap(fn($request) => ($this->resolve)($request->form()));
3131
}
3232
}

src/ViaForm/NullResolver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
use Innmind\HttpAuthentication\Identity;
77
use Innmind\Http\ServerRequest\Form;
8-
use Innmind\Immutable\Maybe;
8+
use Innmind\Immutable\Attempt;
99

1010
final class NullResolver implements Resolver
1111
{
12-
public function __invoke(Form $form): Maybe
12+
public function __invoke(Form $form): Attempt
1313
{
14-
/** @var Maybe<Identity> */
15-
return Maybe::nothing();
14+
/** @var Attempt<Identity> */
15+
return Attempt::error(new \LogicException('Not implemented'));
1616
}
1717
}

src/ViaForm/Resolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
use Innmind\HttpAuthentication\Identity;
77
use Innmind\Http\ServerRequest\Form;
8-
use Innmind\Immutable\Maybe;
8+
use Innmind\Immutable\Attempt;
99

1010
interface Resolver
1111
{
1212
/**
13-
* @return Maybe<Identity>
13+
* @return Attempt<Identity>
1414
*/
15-
public function __invoke(Form $form): Maybe;
15+
public function __invoke(Form $form): Attempt;
1616
}

0 commit comments

Comments
 (0)