Skip to content

Commit

Permalink
Merge pull request #9 from geerteltink/feat/coding-standard-2.2.0
Browse files Browse the repository at this point in the history
feat: laminas coding standard 2.2.0
  • Loading branch information
weierophinney committed May 26, 2021
2 parents 3694544 + 53a3ecd commit 8d2367c
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.phpcs-cache
/.phpunit.result.cache
/clover.xml
/coveralls-upload.json
/docs/html/
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "~1.0.0",
"phpspec/prophecy-phpunit": "^2.0",
"laminas/laminas-coding-standard": "~2.2.0",
"phpspec/prophecy": "^1.12",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3"
},
"conflict": {
Expand Down
337 changes: 280 additions & 57 deletions composer.lock

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<?xml version="1.0"?>
<ruleset name="Laminas coding standard">
<rule ref="./vendor/laminas/laminas-coding-standard/ruleset.xml"/>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
2 changes: 1 addition & 1 deletion src/AuthorizationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface AuthorizationInterface
/**
* Check if a role is granted for the request
*/
public function isGranted(string $role, ServerRequestInterface $request) : bool;
public function isGranted(string $role, ServerRequestInterface $request): bool;
}
12 changes: 4 additions & 8 deletions src/AuthorizationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,26 @@

class AuthorizationMiddleware implements MiddlewareInterface
{
/**
* @var AuthorizationInterface
*/
/** @var AuthorizationInterface */
private $authorization;

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

public function __construct(AuthorizationInterface $authorization, callable $responseFactory)
{
$this->authorization = $authorization;

// Ensures type safety of the composed factory
$this->responseFactory = function () use ($responseFactory) : ResponseInterface {
$this->responseFactory = function () use ($responseFactory): ResponseInterface {
return $responseFactory();
};
}

/**
* {@inheritDoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$user = $request->getAttribute(UserInterface::class, false);
if (! $user instanceof UserInterface) {
Expand Down
5 changes: 3 additions & 2 deletions src/AuthorizationMiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

class AuthorizationMiddlewareFactory
{
public function __invoke(ContainerInterface $container) : AuthorizationMiddleware
public function __invoke(ContainerInterface $container): AuthorizationMiddleware
{
if (! $container->has(AuthorizationInterface::class)
if (
! $container->has(AuthorizationInterface::class)
&& ! $container->has(\Zend\Expressive\Authorization\AuthorizationInterface::class)
) {
throw new Exception\InvalidConfigException(sprintf(
Expand Down
8 changes: 4 additions & 4 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ConfigProvider
/**
* Return the configuration array.
*/
public function __invoke() : array
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
Expand All @@ -20,7 +20,7 @@ public function __invoke() : array
/**
* Returns the configuration for the AuthorizationInterface adapter
*/
public function getAuthorizationConfig() : array
public function getAuthorizationConfig(): array
{
return [
/**
Expand Down Expand Up @@ -59,10 +59,10 @@ public function getAuthorizationConfig() : array
/**
* Returns the container dependencies
*/
public function getDependencies() : array
public function getDependencies(): array
{
return [
'aliases' => [
'aliases' => [
// Provide an alias for the AuthorizationInterface based on the adapter you are using.
// AuthorizationInterface::class => LaminasAcl::class,
// AuthorizationInterface::class => LaminasRbac::class,
Expand Down
10 changes: 5 additions & 5 deletions test/AuthorizationMiddlewareFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class AuthorizationMiddlewareFactoryTest extends TestCase

protected function setUp(): void
{
$this->container = $this->prophesize(ContainerInterface::class);
$this->factory = new AuthorizationMiddlewareFactory();
$this->authorization = $this->prophesize(AuthorizationInterface::class);
$this->container = $this->prophesize(ContainerInterface::class);
$this->factory = new AuthorizationMiddlewareFactory();
$this->authorization = $this->prophesize(AuthorizationInterface::class);
$this->responsePrototype = $this->prophesize(ResponseInterface::class);
$this->responseFactory = function () {
$this->responseFactory = function () {
return $this->responsePrototype->reveal();
};

Expand Down Expand Up @@ -75,7 +75,7 @@ public function testFactory()
public static function assertResponseFactoryReturns(
ResponseInterface $expected,
AuthorizationMiddleware $middleware
) : void {
): void {
$r = new ReflectionProperty($middleware, 'responseFactory');
$r->setAccessible(true);
$responseFactory = $r->getValue($middleware);
Expand Down
10 changes: 5 additions & 5 deletions test/AuthorizationMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class AuthorizationMiddlewareTest extends TestCase

protected function setUp(): void
{
$this->authorization = $this->prophesize(AuthorizationInterface::class);
$this->request = $this->prophesize(ServerRequestInterface::class);
$this->handler = $this->prophesize(RequestHandlerInterface::class);
$this->authorization = $this->prophesize(AuthorizationInterface::class);
$this->request = $this->prophesize(ServerRequestInterface::class);
$this->handler = $this->prophesize(RequestHandlerInterface::class);
$this->responsePrototype = $this->prophesize(ResponseInterface::class);
$this->responseFactory = function () {
$this->responseFactory = function () {
return $this->responsePrototype->reveal();
};
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public function testProcessRoleGranted()
$this->assertSame($this->responsePrototype->reveal(), $response);
}

private function generateUser(string $identity, array $roles = []) : DefaultUser
private function generateUser(string $identity, array $roles = []): DefaultUser
{
return new DefaultUser($identity, $roles);
}
Expand Down
2 changes: 1 addition & 1 deletion test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function setUp(): void

public function testProviderDefinesExpectedFactoryServices()
{
$config = $this->provider->getDependencies();
$config = $this->provider->getDependencies();
$factories = $config['factories'];

$this->assertArrayHasKey(AuthorizationMiddleware::class, $factories);
Expand Down
4 changes: 2 additions & 2 deletions test/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class ExceptionTest extends TestCase
{
public function exception() : Generator
public function exception(): Generator
{
$namespace = substr(ExceptionInterface::class, 0, strrpos(ExceptionInterface::class, '\\') + 1);

Expand All @@ -31,7 +31,7 @@ public function exception() : Generator
/**
* @dataProvider exception
*/
public function testExceptionIsInstanceOfExceptionInterface(string $exception) : void
public function testExceptionIsInstanceOfExceptionInterface(string $exception): void
{
self::assertStringContainsString('Exception', $exception);
self::assertTrue(is_a($exception, ExceptionInterface::class, true));
Expand Down

0 comments on commit 8d2367c

Please sign in to comment.