Skip to content

Commit

Permalink
Merge pull request #54 from samsonasik/apply-php74
Browse files Browse the repository at this point in the history
Apply PHP 7.4 syntax and typed property
  • Loading branch information
Ocramius authored Sep 17, 2022
2 parents 9291d0f + c06922c commit bf79105
Show file tree
Hide file tree
Showing 26 changed files with 68 additions and 129 deletions.
8 changes: 6 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,7 @@
</file>
<file src="test/OAuth2AdapterFactoryTest.php">
<MissingClosureReturnType occurrences="2">
<code>function (</code>
<code>function () {</code>
<code>fn()</code>
</MissingClosureReturnType>
<MissingReturnType occurrences="5">
<code>testConstructor</code>
Expand Down Expand Up @@ -892,6 +891,11 @@
<code>reveal</code>
<code>reveal</code>
</PossiblyUndefinedMethod>
<UnusedClosureParam occurrences="3">
<code>$identity</code>
<code>$roles</code>
<code>$details</code>
</UnusedClosureParam>
</file>
<file src="test/OAuth2AdapterTest.php">
<InvalidArgument occurrences="4">
Expand Down
10 changes: 3 additions & 7 deletions src/AuthorizationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
*/
class AuthorizationHandler implements RequestHandlerInterface
{
/** @var AuthorizationServer */
private $server;
private AuthorizationServer $server;

/** @var ResponseFactoryInterface */
private $responseFactory;
private ResponseFactoryInterface $responseFactory;

/**
* @param (callable():ResponseInterface)|ResponseFactoryInterface $responseFactory
Expand All @@ -39,9 +37,7 @@ public function __construct(AuthorizationServer $server, $responseFactory)
$this->server = $server;
if (is_callable($responseFactory)) {
$responseFactory = new CallableResponseFactoryDecorator(
static function () use ($responseFactory): ResponseInterface {
return $responseFactory();
}
static fn(): ResponseInterface => $responseFactory()
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/AuthorizationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public function __construct(AuthorizationServer $server, $responseFactory)
$this->server = $server;
if (is_callable($responseFactory)) {
$responseFactory = new CallableResponseFactoryDecorator(
static function () use ($responseFactory): ResponseInterface {
return $responseFactory();
}
static fn(): ResponseInterface => $responseFactory()
);
}

Expand Down
13 changes: 3 additions & 10 deletions src/OAuth2Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,13 @@ public function __construct(

if (is_callable($responseFactory)) {
$responseFactory = new CallableResponseFactoryDecorator(
static function () use ($responseFactory): ResponseInterface {
return $responseFactory();
}
static fn(): ResponseInterface => $responseFactory()
);
}

$this->responseFactory = $responseFactory;
$this->userFactory = function (
string $identity,
array $roles = [],
array $details = []
) use ($userFactory): UserInterface {
return $userFactory($identity, $roles, $details);
};
$this->userFactory = static fn(string $identity, array $roles = [], array $details = []): UserInterface
=> $userFactory($identity, $roles, $details);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Repository/Pdo/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ protected function scopesToString(array $scopes): string
return '';
}

return trim(array_reduce($scopes, function ($result, $item) {
return $result . ' ' . $item->getIdentifier();
}));
return trim(array_reduce($scopes, static fn($result, $item): string => $result . ' ' . $item->getIdentifier()));
}
}
4 changes: 1 addition & 3 deletions src/TokenEndpointHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public function __construct(AuthorizationServer $server, $responseFactory)
$this->server = $server;
if (is_callable($responseFactory)) {
$responseFactory = new CallableResponseFactoryDecorator(
static function () use ($responseFactory): ResponseInterface {
return $responseFactory();
}
static fn(): ResponseInterface => $responseFactory()
);
}
$this->responseFactory = $responseFactory;
Expand Down
10 changes: 3 additions & 7 deletions test/AuthorizationHandlerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testRaisesTypeErrorForInvalidAuthorizationServer()
->willReturn(new stdClass());
$this->container
->get(ResponseInterface::class)
->willReturn(function () {
->willReturn(static function (): void {
});

$factory = new AuthorizationHandlerFactory();
Expand Down Expand Up @@ -104,9 +104,7 @@ public function testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentI
->willReturn($this->authServer->reveal());
$this->container
->get(ResponseInterface::class)
->willReturn(function () {
return $this->response;
})->shouldBeCalled();
->willReturn(fn(): MockObject => $this->response)->shouldBeCalled();

$factory = new AuthorizationHandlerFactory();
$factory($this->container->reveal());
Expand All @@ -115,9 +113,7 @@ public function testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentI
public function testConfigProvider()
{
$authServer = $this->prophesize(AuthorizationServer::class)->reveal();
$responseFactory = function () {
return $this->prophesize(ResponseInterface::class)->reveal();
};
$responseFactory = fn(): object => $this->prophesize(ResponseInterface::class)->reveal();

$container = new ServiceManager((new ConfigProvider())->getDependencies());
$container->setService(AuthorizationServer::class, $authServer);
Expand Down
8 changes: 2 additions & 6 deletions test/AuthorizationHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public function testHandleUsesAuthorizationServerService(): void
->shouldBeCalled()
->willReturn($expectedResponse);

$subject = new AuthorizationHandler($server->reveal(), function () use ($expectedResponse): ResponseInterface {
return $expectedResponse;
});
$subject = new AuthorizationHandler($server->reveal(), static fn(): ResponseInterface => $expectedResponse);

self::assertSame($expectedResponse, $subject->handle($request->reveal()));
}
Expand All @@ -58,9 +56,7 @@ public function testInvalidResponseFactoryThrowsTypeError()
$server->completeAuthorizationRequest(Argument::any())
->shouldNotBeCalled();

$subject = new AuthorizationHandler($server->reveal(), function () {
return new stdClass();
});
$subject = new AuthorizationHandler($server->reveal(), static fn(): stdClass => new stdClass());

$this->expectException(TypeError::class);
$subject->handle($request->reveal());
Expand Down
6 changes: 2 additions & 4 deletions test/AuthorizationMiddlewareFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testRaisesTypeErrorForInvalidAuthorizationServer()
->willReturn(new stdClass());
$this->container
->get(ResponseInterface::class)
->willReturn(function () {
->willReturn(static function (): void {
});

$factory = new AuthorizationMiddlewareFactory();
Expand Down Expand Up @@ -101,9 +101,7 @@ public function testFactoryReturnsInstanceWhenAppropriateDependenciesArePresentI
->willReturn($this->authServer->reveal());
$this->container
->get(ResponseInterface::class)
->willReturn(function () {
return $this->response;
})
->willReturn(fn(): MockObject => $this->response)
->shouldBeCalled();

$factory = new AuthorizationMiddlewareFactory();
Expand Down
4 changes: 1 addition & 3 deletions test/AuthorizationMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ protected function setUp(): void
$this->serverRequest = $this->prophesize(ServerRequestInterface::class);
$this->authRequest = $this->prophesize(AuthorizationRequest::class);
$this->handler = $this->prophesize(RequestHandlerInterface::class);
$this->responseFactory = function () {
return $this->response;
};
$this->responseFactory = fn(): MockObject => $this->response;
}

public function testConstructor()
Expand Down
2 changes: 1 addition & 1 deletion test/AuthorizationServerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function testInvokeWithListenerConfig()
'event_listeners' => [
[
RequestEvent::CLIENT_AUTHENTICATION_FAILED,
function (RequestEvent $event) {
static function (RequestEvent $event): void {
// do something
},
],
Expand Down
3 changes: 1 addition & 2 deletions test/Entity/UserEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

class UserEntityTest extends TestCase
{
/** @var UserEntity */
private $entity;
private UserEntity $entity;

protected function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion test/InMemoryContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
final class InMemoryContainer implements ContainerInterface
{
/** @var array<string,mixed> */
private $services = [];
private array $services = [];

/**
* @param string $id
Expand Down
12 changes: 2 additions & 10 deletions test/OAuth2AdapterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,9 @@ protected function setUp(): void
$this->resourceServer = $this->prophesize(ResourceServer::class);
$this->response = $this->createMock(ResponseInterface::class);

$this->responseFactory = function () {
return $this->response;
};
$this->responseFactory = fn(): MockObject => $this->response;
$this->user = $this->prophesize(UserInterface::class);
$this->userFactory = function (
string $identity,
array $roles = [],
array $details = []
) {
return $this->user->reveal($identity, $roles, $details);
};
$this->userFactory = fn(string $identity, array $roles = [], array $details = []) => $this->user->reveal();
}

public function testConstructor()
Expand Down
13 changes: 3 additions & 10 deletions test/OAuth2AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ protected function setUp(): void
{
$this->resourceServer = $this->prophesize(ResourceServer::class);
$this->response = $this->createMock(ResponseInterface::class);
$this->responseFactory = function (): ResponseInterface {
return $this->response;
};
$this->userFactory = function (
string $identity,
array $roles = [],
array $details = []
) {
return new DefaultUser($identity, $roles, $details);
};
$this->responseFactory = fn(): ResponseInterface => $this->response;
$this->userFactory = static fn(string $identity, array $roles = [], array $details = []): DefaultUser
=> new DefaultUser($identity, $roles, $details);
}

public function testConstructor()
Expand Down
34 changes: 11 additions & 23 deletions test/Pdo/OAuth2PdoMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,29 @@ class OAuth2PdoMiddlewareTest extends TestCase

private const CODE_VERIFIER = 'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk';

/** @var AccessTokenRepository */
private $accessTokenRepository;
private AccessTokenRepository $accessTokenRepository;

/** @var AuthCodeRepository */
private $authCodeRepository;
private AuthCodeRepository $authCodeRepository;

/** @var AuthorizationServer */
private $authServer;
private AuthorizationServer $authServer;

/** @var ClientRepository */
private $clientRepository;
private ClientRepository $clientRepository;

/** @var RequestHandlerInterface|ObjectProphecy */
private $handler;

/** @var PdoService */
private $pdoService;
private PdoService $pdoService;

/** @var RefreshTokenRepository */
private $refreshTokenRepository;
private RefreshTokenRepository $refreshTokenRepository;

/** @var Response */
private $response;
private Response $response;

/** @var callable */
private $responseFactory;

/** @var ScopeRepository */
private $scopeRepository;
private ScopeRepository $scopeRepository;

/** @var UserRepository */
private $userRepository;
private UserRepository $userRepository;

public static function setUpBeforeClass(): void
{
Expand Down Expand Up @@ -151,9 +142,7 @@ protected function setUp(): void
);

$this->handler = $this->prophesize(RequestHandlerInterface::class);
$this->responseFactory = function () {
return $this->response;
};
$this->responseFactory = fn(): Response => $this->response;
}

/**
Expand Down Expand Up @@ -511,8 +500,7 @@ private function buildConsumerAuthMiddleware(AuthorizationHandler $authHandler):
{
return new class ($authHandler) implements RequestHandlerInterface
{
/** @var AuthorizationHandler */
private $handler;
private AuthorizationHandler $handler;

public function __construct(AuthorizationHandler $handler)
{
Expand Down
16 changes: 5 additions & 11 deletions test/Psr17ResponseFactoryTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

final class Psr17ResponseFactoryTraitTest extends TestCase
{
/** @var Psr17ResponseFactoryTraitImplementation */
private $factory;
private Psr17ResponseFactoryTraitImplementation $factory;

protected function setUp(): void
{
Expand All @@ -32,9 +31,8 @@ public function configurationsWithOverriddenResponseInterfaceFactory(): Generato
[
'dependencies' => [
'factories' => [
ResponseInterface::class => function (): ResponseInterface {
return $this->createMock(ResponseInterface::class);
},
ResponseInterface::class
=> fn(): ResponseInterface => $this->createMock(ResponseInterface::class),
],
],
],
Expand All @@ -55,9 +53,7 @@ public function configurationsWithOverriddenResponseInterfaceFactory(): Generato
'dependencies' => [
'delegators' => [
ResponseInterface::class => [
function (): ResponseInterface {
return $this->createMock(ResponseInterface::class);
},
fn(): ResponseInterface => $this->createMock(ResponseInterface::class),
],
],
],
Expand Down Expand Up @@ -93,9 +89,7 @@ public function testWontUseResponseFactoryInterfaceFromContainerWhenApplicationF
$container->set('config', $config);
$container->set(ResponseFactoryInterface::class, $responseFactory);
$response = $this->createMock(ResponseInterface::class);
$container->set(ResponseInterface::class, function () use ($response): ResponseInterface {
return $response;
});
$container->set(ResponseInterface::class, static fn(): ResponseInterface => $response);

$detectedResponseFactory = ($this->factory)($container);
self::assertNotSame($responseFactory, $detectedResponseFactory);
Expand Down
4 changes: 2 additions & 2 deletions test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use Mezzio\Authentication\OAuth2\Repository\Pdo\PdoService;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;

class AccessTokenRepositoryFactoryTest extends TestCase
{
use ProphecyTrait;

/** @var ContainerInterface */
private $container;
private ObjectProphecy $container;

protected function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions test/Repository/Pdo/AccessTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class AccessTokenRepositoryTest extends TestCase
{
use ProphecyTrait;

/** @var AccessTokenRepository */
private $repo;
private AccessTokenRepository $repo;

protected function setUp(): void
{
Expand Down
Loading

0 comments on commit bf79105

Please sign in to comment.