From bd128e6b45c0ade9379fb460560602a0ac4640ae Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Thu, 23 May 2024 10:04:31 -0400 Subject: [PATCH 1/2] Fixed issue #42. Fix code as per coding standard --- .php-cs-fixer.php | 10 ---------- src/Assertion/AssertionContainer.php | 2 +- src/Assertion/AssertionSet.php | 4 ++-- src/Container/RoleServiceFactory.php | 1 - src/Role/InMemoryRoleProvider.php | 2 +- test/Assertion/AssertionSetTest.php | 8 +++++--- test/Container/RoleServiceFactoryTest.php | 4 ---- test/Service/AuthorizationServiceTest.php | 7 +++++-- 8 files changed, 14 insertions(+), 24 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index fe5a040f..aa211e98 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -22,7 +22,6 @@ public function getRules(): array ], 'blank_line_after_opening_tag' => true, 'blank_line_after_namespace' => true, -// 'blank_line_before_return' => true, 'blank_line_before_statement' => ['statements' => ['return']], 'braces' => true, 'cast_spaces' => true, @@ -35,18 +34,15 @@ public function getRules(): array 'full_opening_tag' => true, 'function_declaration' => true, 'function_typehint_space' => true, -// 'hash_to_slash_comment' => true, 'single_line_comment_style' => ['comment_types' => ['hash']], 'header_comment' => false, 'include' => true, 'indentation_type' => true, 'linebreak_after_opening_tag' => true, 'line_ending' => true, -// 'lowercase_constants' => true, 'constant_case' => ['case' => 'lower'], 'lowercase_keywords' => true, 'method_argument_space' => true, -// 'method_separation' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'modernize_types_casting' => true, 'native_function_casing' => true, @@ -55,15 +51,12 @@ public function getRules(): array 'no_blank_lines_after_class_opening' => true, 'no_closing_tag' => true, 'no_empty_statement' => true, -// 'no_extra_consecutive_blank_lines' => true, 'no_extra_blank_lines' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_multiline_whitespace_around_double_arrow' => true, -// 'no_multiline_whitespace_before_semicolons' => true, 'multiline_whitespace_before_semicolons' => true, 'no_short_bool_cast' => true, -// 'no_short_echo_tag' => true, 'echo_tag_syntax' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_around_offset' => true, @@ -83,11 +76,9 @@ public function getRules(): array 'object_operator_without_whitespace' => true, 'ordered_imports' => true, 'phpdoc_indent' => true, -// 'phpdoc_inline_tag' => true, 'general_phpdoc_tag_rename' => true, 'phpdoc_inline_tag_normalizer' => true, 'phpdoc_tag_type' => true, -// 'psr4' => true, 'psr_autoloading' => true, 'return_type_declaration' => true, 'semicolon_after_instruction' => true, @@ -103,7 +94,6 @@ public function getRules(): array 'switch_case_semicolon_to_colon' => true, 'switch_case_space' => true, 'ternary_operator_spaces' => true, -// 'trailing_comma_in_multiline_array' => true, 'trailing_comma_in_multiline' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, diff --git a/src/Assertion/AssertionContainer.php b/src/Assertion/AssertionContainer.php index 0ebf7205..e156385b 100644 --- a/src/Assertion/AssertionContainer.php +++ b/src/Assertion/AssertionContainer.php @@ -34,7 +34,7 @@ final class AssertionContainer extends AbstractPluginManager implements Assertio protected $instanceOf = AssertionInterface::class; /** - * {@inheritdoc} + * @inheritdoc */ public function get($name, array $options = null): AssertionInterface { diff --git a/src/Assertion/AssertionSet.php b/src/Assertion/AssertionSet.php index 6df8f84e..12f5131f 100644 --- a/src/Assertion/AssertionSet.php +++ b/src/Assertion/AssertionSet.php @@ -29,8 +29,8 @@ final class AssertionSet implements AssertionInterface /** * Condition constants */ - const CONDITION_OR = 'condition_or'; - const CONDITION_AND = 'condition_and'; + public const CONDITION_OR = 'condition_or'; + public const CONDITION_AND = 'condition_and'; /** * @var AssertionContainerInterface diff --git a/src/Container/RoleServiceFactory.php b/src/Container/RoleServiceFactory.php index 090647a8..20277ead 100644 --- a/src/Container/RoleServiceFactory.php +++ b/src/Container/RoleServiceFactory.php @@ -23,7 +23,6 @@ use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use LmcRbac\Options\ModuleOptions; -use LmcRbac\Role\RoleProviderInterface; use LmcRbac\Service\RoleService; use Psr\Container\ContainerInterface; diff --git a/src/Role/InMemoryRoleProvider.php b/src/Role/InMemoryRoleProvider.php index b6b96e92..6af557fa 100644 --- a/src/Role/InMemoryRoleProvider.php +++ b/src/Role/InMemoryRoleProvider.php @@ -55,7 +55,7 @@ public function __construct(array $rolesConfig) } /** - * {@inheritdoc} + * @inheritdoc */ public function getRoles(iterable $roleNames): iterable { diff --git a/test/Assertion/AssertionSetTest.php b/test/Assertion/AssertionSetTest.php index 01bb5fe4..a783ac07 100644 --- a/test/Assertion/AssertionSetTest.php +++ b/test/Assertion/AssertionSetTest.php @@ -84,10 +84,12 @@ public function testWhenNoConditionIsGivenAndIsUsed() $matcher = $this->exactly(2); $assertionContainer->expects($matcher) ->method('get') - ->willReturnCallback(fn (string $key) => match ($key) { + ->willReturnCallback(function (string $key) use ($fooAssertion, $barAssertion) { + return match ($key) { 'fooFactory' => $fooAssertion, 'barFactory' => $barAssertion, - }); + }; + }); $this->assertFalse($assertionSet->assert('permission')); @@ -244,7 +246,7 @@ private function assertionsCalled(array $assertions, array $assertionCalledCount } } - static public function dpMatrix(): array + public static function dpMatrix(): array { return [ // no assertions will fail diff --git a/test/Container/RoleServiceFactoryTest.php b/test/Container/RoleServiceFactoryTest.php index d8c577de..5f0163a9 100644 --- a/test/Container/RoleServiceFactoryTest.php +++ b/test/Container/RoleServiceFactoryTest.php @@ -22,11 +22,9 @@ namespace LmcRbacTest\Container; use Laminas\ServiceManager\ServiceManager; -use LmcRbac\Container\InMemoryRoleProviderFactory; use LmcRbac\Container\RoleServiceFactory; use LmcRbac\Options\ModuleOptions; use LmcRbac\Role\InMemoryRoleProvider; -use LmcRbac\Role\RoleProviderInterface; use PHPUnit\Framework\TestCase; /** @@ -45,8 +43,6 @@ public function testCanCreateRoleService(): void ], ]); - - $container = new ServiceManager(['services' => [ ModuleOptions::class => $options, InMemoryRoleProvider::class => new InMemoryRoleProvider([]), diff --git a/test/Service/AuthorizationServiceTest.php b/test/Service/AuthorizationServiceTest.php index b346f614..5a11039e 100644 --- a/test/Service/AuthorizationServiceTest.php +++ b/test/Service/AuthorizationServiceTest.php @@ -43,7 +43,7 @@ */ class AuthorizationServiceTest extends TestCase { - static function grantedProvider(): array + public static function grantedProvider(): array { return [ // Simple is granted @@ -302,7 +302,10 @@ public function testUsesAssertionsAsCallable(): void $called = false; - $authorizationService = new AuthorizationService($rbac, $roleService, $assertionContainer, + $authorizationService = new AuthorizationService( + $rbac, + $roleService, + $assertionContainer, [ 'foo' => function ($permission, IdentityInterface $identity = null, $context = null) use (&$called) { $called = true; From e2fff77266b641cb17781e66bd87a9b5f45b84c0 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Thu, 23 May 2024 10:19:57 -0400 Subject: [PATCH 2/2] Fixed issue #42. Fix code as per coding standard --- .php-cs-fixer.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index aa211e98..e49d52b4 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -23,30 +23,35 @@ public function getRules(): array 'blank_line_after_opening_tag' => true, 'blank_line_after_namespace' => true, 'blank_line_before_statement' => ['statements' => ['return']], - 'braces' => true, +// 'braces' => true, + 'braces_position' => true, 'cast_spaces' => true, + 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'class_definition' => true, 'combine_consecutive_unsets' => true, 'concat_space' => false, + 'constant_case' => ['case' => 'lower'], + 'control_structure_braces' => true, + 'control_structure_continuation_position' => true, 'declare_strict_types' => true, + 'declare_parentheses' => true, + 'echo_tag_syntax' => true, 'elseif' => true, 'encoding' => true, 'full_opening_tag' => true, 'function_declaration' => true, - 'function_typehint_space' => true, - 'single_line_comment_style' => ['comment_types' => ['hash']], +// 'function_typehint_space' => true, 'header_comment' => false, 'include' => true, 'indentation_type' => true, 'linebreak_after_opening_tag' => true, 'line_ending' => true, - 'constant_case' => ['case' => 'lower'], 'lowercase_keywords' => true, 'method_argument_space' => true, - 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'modernize_types_casting' => true, 'native_function_casing' => true, - 'new_with_braces' => true, +// 'new_with_braces' => true, + 'new_with_parentheses' => true, 'no_alias_functions' => true, 'no_blank_lines_after_class_opening' => true, 'no_closing_tag' => true, @@ -55,20 +60,21 @@ public function getRules(): array 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_multiline_whitespace_around_double_arrow' => true, + 'no_multiple_statements_per_line' => true, 'multiline_whitespace_before_semicolons' => true, 'no_short_bool_cast' => true, - 'echo_tag_syntax' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_around_offset' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_comma_in_singleline_array' => true, +// 'no_trailing_comma_in_list_call' => true, +// 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_comma_in_singleline' => true, + 'no_trailing_whitespace_in_comment' => true, 'no_unneeded_control_parentheses' => true, 'no_unreachable_default_argument_value' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, - 'no_spaces_inside_parenthesis' => true, - 'no_trailing_whitespace_in_comment' => true, +// 'no_spaces_inside_parenthesis' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, 'normalize_index_brace' => true, @@ -88,14 +94,19 @@ public function getRules(): array 'single_class_element_per_statement' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, + 'single_line_comment_style' => ['comment_types' => ['hash']], 'single_quote' => true, + 'single_space_around_construct' => true, + 'spaces_inside_parentheses' => true, 'standardize_not_equals' => true, + 'statement_indentation' => true, 'strict_comparison' => true, 'switch_case_semicolon_to_colon' => true, 'switch_case_space' => true, 'ternary_operator_spaces' => true, 'trailing_comma_in_multiline' => true, 'trim_array_spaces' => true, + 'type_declaration_spaces' => true, 'unary_operator_spaces' => true, 'visibility_required' => true, 'whitespace_after_comma_in_array' => true,