Skip to content

Commit

Permalink
Merge pull request #23 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 e2d2be8 + 44e0be2 commit 175cbfc
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 51 deletions.
7 changes: 3 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
<InternalMethod occurrences="1">
<code>getResponseFactory</code>
</InternalMethod>
<MissingClosureReturnType occurrences="1">
<code>function () {</code>
<MissingClosureReturnType occurrences="2">
<code>fn()</code>
</MissingClosureReturnType>
<MixedArgumentTypeCoercion occurrences="2">
<code>$details</code>
Expand Down Expand Up @@ -130,8 +130,7 @@
</file>
<file src="test/PhpSessionTest.php">
<MissingClosureReturnType occurrences="2">
<code>function () {</code>
<code>function () {</code>
<code>fn()</code>
</MissingClosureReturnType>
<MixedArgumentTypeCoercion occurrences="12">
<code>$details</code>
Expand Down
22 changes: 6 additions & 16 deletions src/PhpSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@

class PhpSession implements AuthenticationInterface
{
/** @var UserRepositoryInterface */
private $repository;
private UserRepositoryInterface $repository;

/** @var array */
private $config;
private array $config;

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

/** @var callable */
private $userFactory;
Expand All @@ -49,22 +46,15 @@ public function __construct(
if (is_callable($responseFactory)) {
// Ensures type safety of the composed factory
$responseFactory = new CallableResponseFactoryDecorator(
static function () use ($responseFactory): ResponseInterface {
return $responseFactory();
}
static fn(): ResponseInterface => $responseFactory()
);
}

$this->responseFactory = $responseFactory;

// Ensures type safety of the composed factory
$this->userFactory = static 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
3 changes: 1 addition & 2 deletions test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

class ConfigProviderTest extends TestCase
{
/** @var ConfigProvider */
private $provider;
private ConfigProvider $provider;

public function setUp(): void
{
Expand Down
12 changes: 4 additions & 8 deletions test/PhpSessionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class PhpSessionFactoryTest extends TestCase
/** @var ContainerInterface|ObjectProphecy */
private $container;

/** @var PhpSessionFactory */
private $factory;
private PhpSessionFactory $factory;

/** @var UserRepositoryInterface|ObjectProphecy */
private $userRegister;
Expand Down Expand Up @@ -101,11 +100,8 @@ protected function setUp(): void
$this->factory = new PhpSessionFactory();
$this->userRegister = $this->createMock(UserRepositoryInterface::class);
$this->responsePrototype = $this->createMock(ResponseInterface::class);
$this->responseFactory = function () {
return $this->responsePrototype;
};
$this->userFactory = function (string $identity, array $roles = [], array $details = []): UserInterface {
return new DefaultUser($identity, $roles, $details);
};
$this->responseFactory = fn() => $this->responsePrototype;
$this->userFactory = static fn(string $identity, array $roles = [], array $details = []): UserInterface
=> new DefaultUser($identity, $roles, $details);
}
}
12 changes: 5 additions & 7 deletions test/PhpSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MezzioTest\Authentication\Session;

use Generator;
use Mezzio\Authentication\AuthenticationInterface;
use Mezzio\Authentication\DefaultUser;
use Mezzio\Authentication\Session\ConfigProvider;
Expand Down Expand Up @@ -344,7 +345,7 @@ public function testUnauthorizedResponse(): void

public function testIterableRolesWillBeConvertedToArray(): void
{
$roleGenerator = function () {
$roleGenerator = static function (): Generator {
yield 'captain';
};

Expand Down Expand Up @@ -417,12 +418,9 @@ protected function setUp(): void
$this->userRegister = $this->createMock(UserRepositoryInterface::class);
$this->authenticatedUser = $this->createMock(UserInterface::class);
$this->responsePrototype = $this->createMock(ResponseInterface::class);
$this->responseFactory = function () {
return $this->responsePrototype;
};
$this->userFactory = function (string $identity, array $roles = [], array $details = []): UserInterface {
return new DefaultUser($identity, $roles, $details);
};
$this->responseFactory = fn() => $this->responsePrototype;
$this->userFactory = static fn(string $identity, array $roles = [], array $details = []): UserInterface
=> new DefaultUser($identity, $roles, $details);
$this->session = $this->createMock(SessionInterface::class);
$this->defaultConfig = (new ConfigProvider())()['authentication'];
}
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 @@ -97,9 +93,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
2 changes: 1 addition & 1 deletion test/TestAsset/InMemoryContainerPSR11V1.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
final class InMemoryContainerPSR11V1 implements ContainerInterface
{
/** @var array<string,mixed> */
private $services = [];
private array $services = [];

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

/**
* @return mixed
Expand Down
2 changes: 1 addition & 1 deletion test/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use MezzioTest\Authentication\Session\TestAsset\InMemoryContainerPSR11V2;
use Psr\Container\ContainerInterface;

(function () {
(static function () {
$r = new ReflectionMethod(ContainerInterface::class, 'has');
$params = $r->getParameters();
$id = array_shift($params);
Expand Down

0 comments on commit 175cbfc

Please sign in to comment.