Skip to content

Commit

Permalink
Merge pull request #13 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 dc6c11c + 2706f6d commit 57c194c
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.phpcs-cache
/.phpunit.result.cache
/clover.xml
/coveralls-upload.json
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"psr/http-message": "^1.0.1"
},
"require-dev": {
"laminas/laminas-coding-standard": "~1.0.0",
"laminas/laminas-coding-standard": "~2.2.0",
"laminas/laminas-servicemanager": "^3.3",
"phpspec/prophecy-phpunit": "^2.0",
"phpspec/prophecy": "^1.12",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3"
},
"conflict": {
Expand Down
373 changes: 300 additions & 73 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>
10 changes: 6 additions & 4 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@

namespace Mezzio\Authorization\Acl;

use Zend\Expressive\Authorization\Acl\ZendAcl;

class ConfigProvider
{
public function __invoke() : array
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
];
}

public function getDependencies() : array
public function getDependencies(): array
{
return [
// Legacy Zend Framework aliases
'aliases' => [
\Zend\Expressive\Authorization\Acl\ZendAcl::class => LaminasAcl::class,
'aliases' => [
ZendAcl::class => LaminasAcl::class,
],
'factories' => [
LaminasAcl::class => LaminasAclFactory::class,
Expand Down
6 changes: 2 additions & 4 deletions src/LaminasAcl.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

class LaminasAcl implements AuthorizationInterface
{
/**
* @var Acl
*/
/** @var Acl */
private $acl;

public function __construct(Acl $acl)
Expand All @@ -29,7 +27,7 @@ public function __construct(Acl $acl)
*
* @throws Exception\RuntimeException
*/
public function isGranted(string $role, ServerRequestInterface $request) : bool
public function isGranted(string $role, ServerRequestInterface $request): bool
{
$routeResult = $request->getAttribute(RouteResult::class, false);
if (false === $routeResult) {
Expand Down
8 changes: 4 additions & 4 deletions src/LaminasAclFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LaminasAclFactory
/**
* @throws Exception\InvalidConfigException
*/
public function __invoke(ContainerInterface $container) : AuthorizationInterface
public function __invoke(ContainerInterface $container): AuthorizationInterface
{
$config = $container->get('config')['mezzio-authorization-acl'] ?? null;
if (null === $config) {
Expand Down Expand Up @@ -50,7 +50,7 @@ public function __invoke(ContainerInterface $container) : AuthorizationInterface
/**
* @throws Exception\InvalidConfigException
*/
private function injectRoles(Acl $acl, array $roles) : void
private function injectRoles(Acl $acl, array $roles): void
{
foreach ($roles as $role => $parents) {
foreach ($parents as $parent) {
Expand All @@ -73,7 +73,7 @@ private function injectRoles(Acl $acl, array $roles) : void
/**
* @throws Exception\InvalidConfigException
*/
private function injectResources(Acl $acl, array $resources) : void
private function injectResources(Acl $acl, array $resources): void
{
foreach ($resources as $resource) {
try {
Expand All @@ -87,7 +87,7 @@ private function injectResources(Acl $acl, array $resources) : void
/**
* @throws Exception\InvalidConfigException
*/
private function injectPermissions(Acl $acl, array $permissions, string $type) : void
private function injectPermissions(Acl $acl, array $permissions, string $type): void
{
if (! in_array($type, ['allow', 'deny'], true)) {
throw new Exception\InvalidConfigException(sprintf(
Expand Down
10 changes: 5 additions & 5 deletions test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class ConfigProviderTest extends TestCase
/** @var ConfigProvider */
private $provider;

protected function setUp() : void
protected function setUp(): void
{
$this->provider = new ConfigProvider();
}

public function testInvocationReturnsArray()
public function testInvocationReturnsArray(): array
{
$config = ($this->provider)();
$this->assertIsArray($config);
Expand Down Expand Up @@ -56,14 +56,14 @@ public function testServicesDefinedInConfigProvider()
foreach ($json['packages'] as $package) {
if (isset($package['extra']['laminas']['config-provider'])) {
$configProvider = new $package['extra']['laminas']['config-provider']();
$config = array_merge_recursive($config, $configProvider());
$config = array_merge_recursive($config, $configProvider());
}
}

$config['dependencies']['services']['config'] = [
'mezzio-authorization-acl' => ['roles' => [], 'resources' => []],
];
$container = $this->getContainer($config['dependencies']);
$container = $this->getContainer($config['dependencies']);

$dependencies = $this->provider->getDependencies();
foreach ($dependencies['factories'] as $name => $factory) {
Expand All @@ -75,7 +75,7 @@ public function testServicesDefinedInConfigProvider()
}
}

private function getContainer(array $dependencies) : ServiceManager
private function getContainer(array $dependencies): ServiceManager
{
return new ServiceManager($dependencies);
}
Expand Down
16 changes: 8 additions & 8 deletions test/LaminasAclFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LaminasAclFactoryTest extends TestCase
/** @var ContainerInterface|ObjectProphecy */
private $container;

protected function setUp() : void
protected function setUp(): void
{
$this->container = $this->prophesize(ContainerInterface::class);
}
Expand Down Expand Up @@ -62,12 +62,12 @@ public function testFactoryWithEmptyRolesResources()
{
$this->container->get('config')->willReturn([
'mezzio-authorization-acl' => [
'roles' => [],
'roles' => [],
'resources' => [],
],
]);

$factory = new LaminasAclFactory();
$factory = new LaminasAclFactory();
$laminasAcl = $factory($this->container->reveal());
$this->assertInstanceOf(LaminasAcl::class, $laminasAcl);
}
Expand All @@ -76,7 +76,7 @@ public function testFactoryWithoutAllowOrDeny()
{
$config = [
'mezzio-authorization-acl' => [
'roles' => [
'roles' => [
'admini' => [],
'editor' => ['administrator'],
'contributor' => ['editor'],
Expand All @@ -91,7 +91,7 @@ public function testFactoryWithoutAllowOrDeny()
];
$this->container->get('config')->willReturn($config);

$factory = new LaminasAclFactory();
$factory = new LaminasAclFactory();
$laminasAcl = $factory($this->container->reveal());
$this->assertInstanceOf(LaminasAcl::class, $laminasAcl);
}
Expand All @@ -100,7 +100,7 @@ public function testFactoryWithInvalidRole()
{
$this->container->get('config')->willReturn([
'mezzio-authorization-acl' => [
'roles' => [
'roles' => [
1 => [],
],
'permissions' => [],
Expand All @@ -117,14 +117,14 @@ public function testFactoryWithUnknownRole()
{
$this->container->get('config')->willReturn([
'mezzio-authorization-acl' => [
'roles' => [
'roles' => [
'administrator' => [],
],
'resources' => [
'admin.dashboard',
'admin.posts',
],
'allow' => [
'allow' => [
'editor' => ['admin.dashboard'],
],
],
Expand Down
2 changes: 1 addition & 1 deletion test/LaminasAclTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LaminasAclTest extends TestCase
/** @var Acl|ObjectProphecy */
private $acl;

protected function setUp() : void
protected function setUp(): void
{
$this->acl = $this->prophesize(Acl::class);
}
Expand Down

0 comments on commit 57c194c

Please sign in to comment.