From f83c30aa6215918cf6aa716cc556806ca77d6e93 Mon Sep 17 00:00:00 2001 From: mpdude Date: Mon, 1 Jul 2024 08:12:51 +0000 Subject: [PATCH] Fix CS with PHP-CS-Fixer --- .php-cs-fixer.cache | 1 + .../ObjectRouting/Attribute/ObjectRoute.php | 8 ++-- src/JMS/ObjectRouting/Exception/Exception.php | 4 +- .../Exception/RuntimeException.php | 4 +- .../Exception/XmlErrorException.php | 9 ++-- .../ObjectRouting/Metadata/ClassMetadata.php | 21 ++++----- .../Metadata/Driver/AttributeDriver.php | 6 +-- .../Metadata/Driver/PhpDriver.php | 5 +- .../Metadata/Driver/XmlDriver.php | 23 ++++------ .../Metadata/Driver/YamlDriver.php | 17 ++----- src/JMS/ObjectRouting/ObjectRouter.php | 32 ++++++------- src/JMS/ObjectRouting/RouterInterface.php | 8 ++-- .../Symfony/Symfony22Adapter.php | 10 ++-- .../Metadata/ClassMetadataTest.php | 5 +- .../Metadata/Driver/AttributeDriverTest.php | 10 +++- .../Metadata/Driver/Fixture/BlogPost.php | 2 +- .../Driver/Fixture/BlogPostWithAttributes.php | 4 +- .../Metadata/Driver/PhpDriverTest.php | 20 +++++--- .../Metadata/Driver/XmlDriverTest.php | 22 +++++---- .../Metadata/Driver/YamlDriverTest.php | 22 +++++---- .../Tests/ObjectRouting/ObjectRouterTest.php | 46 ++++++++++++------- ...uting.Metadata.Driver.Fixture.BlogPost.php | 6 +-- .../Symfony/Symfony22AdapterTest.php | 11 +++-- tests/bootstrap.php | 12 ++--- 24 files changed, 159 insertions(+), 149 deletions(-) create mode 100644 .php-cs-fixer.cache diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache new file mode 100644 index 0000000..cb07595 --- /dev/null +++ b/.php-cs-fixer.cache @@ -0,0 +1 @@ +{"php":"8.3.8","version":"3.59.3","indent":" ","lineEnding":"\n","rules":{"align_multiline_comment":true,"array_syntax":{"syntax":"short"},"backtick_to_shell_exec":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["return"]},"braces_position":{"allow_single_line_anonymous_functions":true,"allow_single_line_empty_anonymous_classes":true},"class_attributes_separation":{"elements":{"method":"one"}},"class_definition":{"single_line":true},"class_reference_name_casing":true,"clean_namespace":true,"concat_space":true,"declare_parentheses":true,"echo_tag_syntax":true,"empty_loop_body":{"style":"braces"},"empty_loop_condition":true,"fully_qualified_strict_types":true,"function_declaration":true,"general_phpdoc_tag_rename":{"replacements":{"inheritDocs":"inheritDoc"}},"global_namespace_import":{"import_classes":false,"import_constants":false,"import_functions":false},"include":true,"increment_style":true,"integer_literal_case":true,"lambda_not_used_import":true,"linebreak_after_opening_tag":true,"magic_constant_casing":true,"magic_method_casing":true,"method_argument_space":{"on_multiline":"ignore"},"native_function_casing":true,"native_type_declaration_casing":true,"no_alias_language_construct_call":true,"no_alternative_syntax":true,"no_binary_string":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["attribute","case","continue","curly_brace_block","default","extra","parenthesis_brace_block","square_brace_block","switch","throw","use"]},"no_leading_namespace_whitespace":true,"no_mixed_echo_print":true,"no_multiline_whitespace_around_double_arrow":true,"no_null_property_initialization":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_superfluous_phpdoc_tags":{"allow_hidden_params":true,"remove_inheritdoc":true},"no_trailing_comma_in_singleline":true,"no_unneeded_braces":{"namespaces":true},"no_unneeded_control_parentheses":{"statements":["break","clone","continue","echo_print","others","return","switch_case","yield","yield_from"]},"no_unneeded_import_alias":true,"no_unset_cast":true,"no_unused_imports":true,"no_useless_concat_operator":true,"no_useless_nullsafe_operator":true,"no_whitespace_before_comma_in_array":true,"normalize_index_brace":true,"nullable_type_declaration":true,"nullable_type_declaration_for_default_null_value":true,"object_operator_without_whitespace":true,"operator_linebreak":{"only_booleans":true},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"alpha"},"ordered_types":{"null_adjustment":"always_last","sort_algorithm":"none"},"php_unit_fqcn_annotation":true,"phpdoc_align":true,"phpdoc_indent":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_order":{"order":["param","return","throws"]},"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":{"skip_unlisted_annotations":true},"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_tag_type":{"tags":{"inheritDoc":"inline"}},"phpdoc_trim":true,"phpdoc_trim_consecutive_blank_line_separation":true,"phpdoc_types":true,"phpdoc_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"phpdoc_var_without_name":true,"semicolon_after_instruction":true,"simple_to_complex_string_variable":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_comment_spacing":true,"single_line_comment_style":{"comment_types":["hash"]},"single_line_throw":true,"single_quote":true,"single_space_around_construct":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"statement_indentation":{"stick_comment_to_next_continuous_control_statement":true},"switch_continue_to_break":true,"trailing_comma_in_multiline":true,"trim_array_spaces":true,"type_declaration_spaces":true,"types_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"yoda_style":true,"array_indentation":true,"cast_spaces":true,"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"return_type_declaration":true,"short_scalar_cast":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_line_after_imports":true,"spaces_inside_parentheses":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_push":true,"combine_nested_dirname":true,"dir_constant":true,"ereg_to_preg":true,"error_suppression":true,"fopen_flag_order":true,"fopen_flags":{"b_mode":false},"function_to_constant":true,"get_class_to_class_keyword":true,"implode_call":true,"is_null":true,"logical_operators":true,"long_to_shorthand_operator":true,"modernize_strpos":true,"modernize_types_casting":true,"native_constant_invocation":{"strict":false},"native_function_invocation":{"include":["@compiler_optimized"],"scope":"namespaced","strict":true},"no_alias_functions":true,"no_homoglyph_names":true,"no_php4_constructor":true,"no_unneeded_final_method":true,"no_useless_sprintf":true,"non_printable_character":true,"ordered_traits":true,"php_unit_construct":true,"php_unit_mock_short_will_return":true,"php_unit_set_up_tear_down_visibility":true,"php_unit_test_annotation":{"style":"annotation"},"self_accessor":true,"set_type_to_cast":true,"string_length_to_empty":true,"string_line_ending":true,"ternary_to_elvis_operator":true,"pow_to_exponentiation":true,"no_trailing_whitespace_in_string":true,"braces":{"allow_single_line_closure":true}},"hashes":{"src\/JMS\/ObjectRouting\/ObjectRouter.php":"28b20b7a7b8ab6f47600449807c59b4f","src\/JMS\/ObjectRouting\/Attribute\/ObjectRoute.php":"c21d2ee5f0476efd8567a03f75036248","src\/JMS\/ObjectRouting\/Exception\/RuntimeException.php":"6e2821a77a207e98a5b665ceb50146e2","src\/JMS\/ObjectRouting\/Exception\/Exception.php":"2da3b5414a5631f767c6ac63f9c81d23","src\/JMS\/ObjectRouting\/Exception\/XmlErrorException.php":"8c1cf2073ffbb285439038df05b022d2","src\/JMS\/ObjectRouting\/Metadata\/Driver\/XmlDriver.php":"ccdbaf104a07c41d17c2c288ac1e3731","src\/JMS\/ObjectRouting\/Metadata\/Driver\/PhpDriver.php":"8353e4d0be48e9e529b74d75936a553e","src\/JMS\/ObjectRouting\/Metadata\/Driver\/AttributeDriver.php":"f97675b0ec3d6e1d202e5b53917f34fc","src\/JMS\/ObjectRouting\/Metadata\/Driver\/YamlDriver.php":"0fc88b0d1a68652c04c94754f7fe4c59","src\/JMS\/ObjectRouting\/Metadata\/ClassMetadata.php":"9cb90afe0e92602637d10608d25281cb","src\/JMS\/ObjectRouting\/Twig\/RoutingExtension.php":"8eccb83032ac318a3904670f6af9064f","src\/JMS\/ObjectRouting\/RouterInterface.php":"e0a4222cc5ee68cc7001d4c93cb19a76","src\/JMS\/ObjectRouting\/Symfony\/Symfony22Adapter.php":"888661f26ec2a24c021726a7289c299e","tests\/bootstrap.php":"94c5fde333ebff7dbc0c7769f0c3ef20","tests\/JMS\/Tests\/ObjectRouting\/Resources\/config\/JMS.Tests.ObjectRouting.Metadata.Driver.Fixture.BlogPost.php":"55c2abfa1bb8e02bc0e4e1aa80d2d42f","tests\/JMS\/Tests\/ObjectRouting\/ObjectRouterTest.php":"799a001d8487813f813dae79919d8a6e","tests\/JMS\/Tests\/ObjectRouting\/Metadata\/Driver\/PhpDriverTest.php":"2767b53353b0bf6c72127efb9d591855","tests\/JMS\/Tests\/ObjectRouting\/Metadata\/Driver\/AttributeDriverTest.php":"0cc46fbe228e4126a465377b91e835cd","tests\/JMS\/Tests\/ObjectRouting\/Metadata\/Driver\/Fixture\/BlogPostWithAttributes.php":"aaf1b32a0c3d4304ddba2132ddb501d7","tests\/JMS\/Tests\/ObjectRouting\/Metadata\/Driver\/Fixture\/BlogPost.php":"99d1bd67a0b641012ca71e0fd3ab7174","tests\/JMS\/Tests\/ObjectRouting\/Metadata\/Driver\/XmlDriverTest.php":"15fea5da3b0762f1496dc219573f236b","tests\/JMS\/Tests\/ObjectRouting\/Metadata\/Driver\/YamlDriverTest.php":"081fc99cb8050c3eee1b92feee3ce174","tests\/JMS\/Tests\/ObjectRouting\/Metadata\/ClassMetadataTest.php":"4da1e2dc51cc28c7d30317d288b76e6c","tests\/JMS\/Tests\/ObjectRouting\/Symfony\/Symfony22AdapterTest.php":"6c6806ee90a05d06fb1f40f857648c23"}} \ No newline at end of file diff --git a/src/JMS/ObjectRouting/Attribute/ObjectRoute.php b/src/JMS/ObjectRouting/Attribute/ObjectRoute.php index 01458a4..087219c 100644 --- a/src/JMS/ObjectRouting/Attribute/ObjectRoute.php +++ b/src/JMS/ObjectRouting/Attribute/ObjectRoute.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,7 +28,7 @@ final class ObjectRoute public $name; /** @var array */ - public $params = array(); + public $params = []; public function __construct(string $type, string $name, array $params = []) { diff --git a/src/JMS/ObjectRouting/Exception/Exception.php b/src/JMS/ObjectRouting/Exception/Exception.php index 033dfd4..4ad6894 100644 --- a/src/JMS/ObjectRouting/Exception/Exception.php +++ b/src/JMS/ObjectRouting/Exception/Exception.php @@ -2,8 +2,6 @@ namespace JMS\ObjectRouting\Exception; - interface Exception { - -} \ No newline at end of file +} diff --git a/src/JMS/ObjectRouting/Exception/RuntimeException.php b/src/JMS/ObjectRouting/Exception/RuntimeException.php index 28a7a1a..f93105e 100644 --- a/src/JMS/ObjectRouting/Exception/RuntimeException.php +++ b/src/JMS/ObjectRouting/Exception/RuntimeException.php @@ -2,8 +2,6 @@ namespace JMS\ObjectRouting\Exception; - class RuntimeException extends \RuntimeException implements Exception { - -} \ No newline at end of file +} diff --git a/src/JMS/ObjectRouting/Exception/XmlErrorException.php b/src/JMS/ObjectRouting/Exception/XmlErrorException.php index 4b65e05..0f8499b 100644 --- a/src/JMS/ObjectRouting/Exception/XmlErrorException.php +++ b/src/JMS/ObjectRouting/Exception/XmlErrorException.php @@ -2,7 +2,6 @@ namespace JMS\ObjectRouting\Exception; - class XmlErrorException extends RuntimeException { private $xmlError; @@ -10,13 +9,13 @@ class XmlErrorException extends RuntimeException public function __construct(\LibXMLError $error) { switch ($error->level) { - case LIBXML_ERR_WARNING: + case \LIBXML_ERR_WARNING: $level = 'WARNING'; break; - case LIBXML_ERR_FATAL: + case \LIBXML_ERR_FATAL: $level = 'FATAL'; break; - case LIBXML_ERR_ERROR: + case \LIBXML_ERR_ERROR: $level = 'ERROR'; break; default: @@ -30,4 +29,4 @@ public function getXmlError() { return $this->xmlError; } -} \ No newline at end of file +} diff --git a/src/JMS/ObjectRouting/Metadata/ClassMetadata.php b/src/JMS/ObjectRouting/Metadata/ClassMetadata.php index dc7856e..2d1f701 100644 --- a/src/JMS/ObjectRouting/Metadata/ClassMetadata.php +++ b/src/JMS/ObjectRouting/Metadata/ClassMetadata.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,14 +23,14 @@ class ClassMetadata extends MergeableClassMetadata { - public $routes = array(); + public $routes = []; - public function addRoute($type, $name, array $params = array()) + public function addRoute($type, $name, array $params = []) { - $this->routes[$type] = array( + $this->routes[$type] = [ 'name' => $name, 'params' => $params, - ); + ]; } public function merge(MergeableInterface $object): void @@ -42,10 +42,10 @@ public function merge(MergeableInterface $object): void public function serialize(): string { return serialize( - array( + [ $this->routes, parent::serialize(), - ) + ] ); } @@ -54,9 +54,8 @@ public function unserialize($str): void list( $this->routes, $parentStr - ) = unserialize($str); + ) = unserialize($str); parent::unserialize($parentStr); } - } diff --git a/src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php b/src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php index 3a74288..6a739d9 100644 --- a/src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php +++ b/src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php b/src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php index 7936863..680c197 100644 --- a/src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php +++ b/src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php @@ -18,14 +18,13 @@ namespace JMS\ObjectRouting\Metadata\Driver; - use JMS\ObjectRouting\Exception\RuntimeException; use JMS\ObjectRouting\Metadata\ClassMetadata; use Metadata\Driver\AbstractFileDriver; /** - * Class PhpDriver - * @package JMS\ObjectRouting\Metadata\Driver + * Class PhpDriver. + * * @author Sebastian Kroczek */ class PhpDriver extends AbstractFileDriver diff --git a/src/JMS/ObjectRouting/Metadata/Driver/XmlDriver.php b/src/JMS/ObjectRouting/Metadata/Driver/XmlDriver.php index 5c9435e..d7ff896 100644 --- a/src/JMS/ObjectRouting/Metadata/Driver/XmlDriver.php +++ b/src/JMS/ObjectRouting/Metadata/Driver/XmlDriver.php @@ -18,26 +18,21 @@ namespace JMS\ObjectRouting\Metadata\Driver; - use JMS\ObjectRouting\Exception\RuntimeException; use JMS\ObjectRouting\Exception\XmlErrorException; use JMS\ObjectRouting\Metadata\ClassMetadata; use Metadata\Driver\AbstractFileDriver; /** - * Class XmlDriver - * @package JMS\ObjectRouting\Metadata\Driver + * Class XmlDriver. + * * @author Sebastian Kroczek */ class XmlDriver extends AbstractFileDriver { - /** * Parses the content of the file, and converts it to the desired metadata. * - * @param \ReflectionClass $class - * @param string $file - * * @return \Metadata\ClassMetadata|null */ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?ClassMetadata @@ -57,23 +52,23 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): $metadata->fileResources[] = $class->getFileName(); if (null !== $xmlRootName = $elem->attributes()->{'xml-root-name'}) { - $metadata->xmlRootName = (string)$xmlRootName; + $metadata->xmlRootName = (string) $xmlRootName; } if (null !== $xmlRootNamespace = $elem->attributes()->{'xml-root-namespace'}) { - $metadata->xmlRootNamespace = (string)$xmlRootNamespace; + $metadata->xmlRootNamespace = (string) $xmlRootNamespace; } foreach ($elem->xpath('./route') as $r) { - if ('' === $type = (string)$r->attributes()->{'type'}) { + if ('' === $type = (string) $r->attributes()->{'type'}) { throw new RuntimeException('Could not find attribute "type" inside XML element.'); } - if ('' === $name = (string)$r->attributes()->{'name'}) { + if ('' === $name = (string) $r->attributes()->{'name'}) { throw new RuntimeException('Could not find attribute "name" inside XML element.'); } - $params = array(); + $params = []; foreach ($r->xpath('./param') as $p) { - $params[(string)$p->attributes()] = (string)$p; + $params[(string) $p->attributes()] = (string) $p; } $metadata->addRoute($type, $name, $params); @@ -84,8 +79,6 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): /** * Returns the extension of the file. - * - * @return string */ protected function getExtension(): string { diff --git a/src/JMS/ObjectRouting/Metadata/Driver/YamlDriver.php b/src/JMS/ObjectRouting/Metadata/Driver/YamlDriver.php index 57ea4dc..4c0029e 100644 --- a/src/JMS/ObjectRouting/Metadata/Driver/YamlDriver.php +++ b/src/JMS/ObjectRouting/Metadata/Driver/YamlDriver.php @@ -24,20 +24,15 @@ use Symfony\Component\Yaml\Yaml; /** - * Class YamlDriver - * @package JMS\ObjectRouting\Metadata\Driver + * Class YamlDriver. + * * @author Sebastian Kroczek */ class YamlDriver extends AbstractFileDriver { - - /** * Parses the content of the file, and converts it to the desired metadata. * - * @param \ReflectionClass $class - * @param string $file - * * @return \Metadata\ClassMetadata|null */ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?ClassMetadata @@ -48,27 +43,23 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file): throw new RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file)); } - $config = $config[$name]; $metadata = new ClassMetadata($name); $metadata->fileResources[] = $file; $metadata->fileResources[] = $class->getFileName(); foreach ($config as $type => $value) { - if (!array_key_exists('name', $value)) { + if (!\array_key_exists('name', $value)) { throw new RuntimeException('Could not find key "type" inside yaml element.'); } - $metadata->addRoute($type, $value['name'], array_key_exists('params', $value) ? $value['params'] : array()); + $metadata->addRoute($type, $value['name'], \array_key_exists('params', $value) ? $value['params'] : []); } return $metadata; - } /** * Returns the extension of the file. - * - * @return string */ protected function getExtension(): string { diff --git a/src/JMS/ObjectRouting/ObjectRouter.php b/src/JMS/ObjectRouting/ObjectRouter.php index 19bddf7..1229f14 100644 --- a/src/JMS/ObjectRouting/ObjectRouter.php +++ b/src/JMS/ObjectRouting/ObjectRouter.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -53,30 +53,24 @@ public function __construct(RouterInterface $router, MetadataFactoryInterface $m * * @param string $type * @param object $object - * @param boolean $absolute - * @param array $extraParams + * @param bool $absolute * * @throws \InvalidArgumentException */ - public function generate($type, $object, $absolute = false, array $extraParams = array()) + public function generate($type, $object, $absolute = false, array $extraParams = []) { - if ( ! is_object($object)) { - throw new \InvalidArgumentException(sprintf('$object must be an object, but got "%s".', gettype($object))); + if (!\is_object($object)) { + throw new \InvalidArgumentException(sprintf('$object must be an object, but got "%s".', \gettype($object))); } /** @var $metadata ClassMetadata */ - $metadata = $this->metadataFactory->getMetadataForClass(get_class($object)); + $metadata = $this->metadataFactory->getMetadataForClass($object::class); if (null === $metadata) { - throw new \RuntimeException(sprintf('There were no object routes defined for class "%s".', get_class($object))); + throw new \RuntimeException(sprintf('There were no object routes defined for class "%s".', $object::class)); } - if ( ! isset($metadata->routes[$type])) { - throw new \RuntimeException(sprintf( - 'The object of class "%s" has no route with type "%s". Available types: %s', - get_class($object), - $type, - implode(', ', array_keys($metadata->routes)) - )); + if (!isset($metadata->routes[$type])) { + throw new \RuntimeException(sprintf('The object of class "%s" has no route with type "%s". Available types: %s', $object::class, $type, implode(', ', array_keys($metadata->routes)))); } $route = $metadata->routes[$type]; @@ -89,12 +83,12 @@ public function generate($type, $object, $absolute = false, array $extraParams = return $this->router->generate($route['name'], $params, $absolute); } - public function path($type, $object, array $extraParams = array()) + public function path($type, $object, array $extraParams = []) { return $this->generate($type, $object, false, $extraParams); } - public function url($type, $object, array $extraParams = array()) + public function url($type, $object, array $extraParams = []) { return $this->generate($type, $object, true, $extraParams); } diff --git a/src/JMS/ObjectRouting/RouterInterface.php b/src/JMS/ObjectRouting/RouterInterface.php index e95407d..183fba9 100644 --- a/src/JMS/ObjectRouting/RouterInterface.php +++ b/src/JMS/ObjectRouting/RouterInterface.php @@ -2,13 +2,13 @@ /* * Copyright 2013 Johannes M. Schmitt - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,4 +21,4 @@ interface RouterInterface { public function generate($name, array $params, $absolute = false); -} \ No newline at end of file +} diff --git a/src/JMS/ObjectRouting/Symfony/Symfony22Adapter.php b/src/JMS/ObjectRouting/Symfony/Symfony22Adapter.php index d278fa0..e92f1a7 100644 --- a/src/JMS/ObjectRouting/Symfony/Symfony22Adapter.php +++ b/src/JMS/ObjectRouting/Symfony/Symfony22Adapter.php @@ -2,13 +2,13 @@ /* * Copyright 2016 Sebastian Kroczek - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,8 +22,8 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** - * Class Symfony22Adapter - * @package JMS\ObjectRouting\Symfony + * Class Symfony22Adapter. + * * @author Sebastian Kroczek */ class Symfony22Adapter implements RouterInterface diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/ClassMetadataTest.php b/tests/JMS/Tests/ObjectRouting/Metadata/ClassMetadataTest.php index b2b17f3..433079a 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/ClassMetadataTest.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/ClassMetadataTest.php @@ -7,7 +7,10 @@ class ClassMetadataTest extends TestCase { - public function testMerge() + /** + * @test + */ + public function merge() { $base = new ClassMetadata(TestCase::class); $base->addRoute('test', 'base-route'); diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/AttributeDriverTest.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/AttributeDriverTest.php index 7755b0a..68199ec 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/AttributeDriverTest.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/AttributeDriverTest.php @@ -10,7 +10,10 @@ class AttributeDriverTest extends TestCase { private readonly AttributeDriver $driver; - public function testLoad() + /** + * @test + */ + public function load() { $metadata = $this->driver->loadMetadataForClass(new \ReflectionClass(BlogPostWithAttributes::class)); $this->assertCount(2, $metadata->routes); @@ -22,7 +25,10 @@ public function testLoad() $this->assertEquals($routes, $metadata->routes); } - public function testLoadReturnsNullWhenNoRoutes() + /** + * @test + */ + public function loadReturnsNullWhenNoRoutes() { $this->assertNull($this->driver->loadMetadataForClass(new \ReflectionClass('stdClass'))); } diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPost.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPost.php index 37621e5..b3489dd 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPost.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPost.php @@ -25,4 +25,4 @@ public function getSlug() { return $this->slug; } -} \ No newline at end of file +} diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPostWithAttributes.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPostWithAttributes.php index 90c61be..d8c9fbe 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPostWithAttributes.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/Fixture/BlogPostWithAttributes.php @@ -4,8 +4,8 @@ use JMS\ObjectRouting\Attribute\ObjectRoute; -#[ObjectRoute(type: "view", name: "blog_post_view", params: ['slug' => 'slug'])] -#[ObjectRoute(type: "edit", name: "blog_post_edit", params: ['slug' => 'slug'])] +#[ObjectRoute(type: 'view', name: 'blog_post_view', params: ['slug' => 'slug'])] +#[ObjectRoute(type: 'edit', name: 'blog_post_edit', params: ['slug' => 'slug'])] class BlogPostWithAttributes { private $slug; diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php index f112ed6..689cb62 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php @@ -11,25 +11,31 @@ class PhpDriverTest extends TestCase /** @var PhpDriver */ private $driver; - public function testLoad() + /** + * @test + */ + public function load() { $metadata = $this->driver->loadMetadataForClass(new \ReflectionClass('JMS\Tests\ObjectRouting\Metadata\Driver\Fixture\BlogPost')); $this->assertCount(2, $metadata->routes); - $routes = array( - 'view' => array('name' => 'blog_post_view', 'params' => array('slug' => 'slug')), - 'edit' => array('name' => 'blog_post_edit', 'params' => array('slug' => 'slug')), - ); + $routes = [ + 'view' => ['name' => 'blog_post_view', 'params' => ['slug' => 'slug']], + 'edit' => ['name' => 'blog_post_edit', 'params' => ['slug' => 'slug']], + ]; $this->assertEquals($routes, $metadata->routes); } - public function testLoadReturnsNullWhenNoRoutes() + /** + * @test + */ + public function loadReturnsNullWhenNoRoutes() { $this->assertNull($this->driver->loadMetadataForClass(new \ReflectionClass('stdClass'))); } protected function setUp(): void { - $this->driver = new PhpDriver(new FileLocator(array('' => realpath(__DIR__.'/../../Resources/config')))); + $this->driver = new PhpDriver(new FileLocator(['' => realpath(__DIR__.'/../../Resources/config')])); } } diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/XmlDriverTest.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/XmlDriverTest.php index 8892fa2..f17d76b 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/XmlDriverTest.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/XmlDriverTest.php @@ -2,8 +2,6 @@ namespace JMS\Tests\ObjectRouting\Metadata\Driver; -use Doctrine\Common\Annotations\AnnotationReader; -use JMS\ObjectRouting\Metadata\Driver\AnnotationDriver; use JMS\ObjectRouting\Metadata\Driver\XmlDriver; use Metadata\Driver\FileLocator; use PHPUnit\Framework\TestCase; @@ -13,25 +11,31 @@ class XmlDriverTest extends TestCase /** @var XmlDriver */ private $driver; - public function testLoad() + /** + * @test + */ + public function load() { $metadata = $this->driver->loadMetadataForClass(new \ReflectionClass('JMS\Tests\ObjectRouting\Metadata\Driver\Fixture\BlogPost')); $this->assertCount(2, $metadata->routes); - $routes = array( - 'view' => array('name' => 'blog_post_view', 'params' => array('slug' => 'slug')), - 'edit' => array('name' => 'blog_post_edit', 'params' => array('slug' => 'slug')), - ); + $routes = [ + 'view' => ['name' => 'blog_post_view', 'params' => ['slug' => 'slug']], + 'edit' => ['name' => 'blog_post_edit', 'params' => ['slug' => 'slug']], + ]; $this->assertEquals($routes, $metadata->routes); } - public function testLoadReturnsNullWhenNoRoutes() + /** + * @test + */ + public function loadReturnsNullWhenNoRoutes() { $this->assertNull($this->driver->loadMetadataForClass(new \ReflectionClass('stdClass'))); } protected function setUp(): void { - $this->driver = new XmlDriver(new FileLocator(array('' => realpath(__DIR__.'/../../Resources/config')))); + $this->driver = new XmlDriver(new FileLocator(['' => realpath(__DIR__.'/../../Resources/config')])); } } diff --git a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/YamlDriverTest.php b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/YamlDriverTest.php index 3e65704..11300ba 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/YamlDriverTest.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/YamlDriverTest.php @@ -2,8 +2,6 @@ namespace JMS\Tests\ObjectRouting\Metadata\Driver; -use Doctrine\Common\Annotations\AnnotationReader; -use JMS\ObjectRouting\Metadata\Driver\AnnotationDriver; use JMS\ObjectRouting\Metadata\Driver\YamlDriver; use Metadata\Driver\FileLocator; use PHPUnit\Framework\TestCase; @@ -13,25 +11,31 @@ class YamlDriverTest extends TestCase /** @var YamlDriver */ private $driver; - public function testLoad() + /** + * @test + */ + public function load() { $metadata = $this->driver->loadMetadataForClass(new \ReflectionClass('JMS\Tests\ObjectRouting\Metadata\Driver\Fixture\BlogPost')); $this->assertCount(2, $metadata->routes); - $routes = array( - 'view' => array('name' => 'blog_post_view', 'params' => array('slug' => 'slug')), - 'edit' => array('name' => 'blog_post_edit', 'params' => array('slug' => 'slug')), - ); + $routes = [ + 'view' => ['name' => 'blog_post_view', 'params' => ['slug' => 'slug']], + 'edit' => ['name' => 'blog_post_edit', 'params' => ['slug' => 'slug']], + ]; $this->assertEquals($routes, $metadata->routes); } - public function testLoadReturnsNullWhenNoRoutes() + /** + * @test + */ + public function loadReturnsNullWhenNoRoutes() { $this->assertNull($this->driver->loadMetadataForClass(new \ReflectionClass('stdClass'))); } protected function setUp(): void { - $this->driver = new YamlDriver(new FileLocator(array('' => realpath(__DIR__.'/../../Resources/config')))); + $this->driver = new YamlDriver(new FileLocator(['' => realpath(__DIR__.'/../../Resources/config')])); } } diff --git a/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php b/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php index 2b35cb0..1dc0ead 100644 --- a/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php +++ b/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php @@ -15,7 +15,10 @@ class ObjectRouterTest extends TestCase private $adapter; private $factory; - public function testGenerate() + /** + * @test + */ + public function generate() { $metadata = new ClassMetadata('stdClass'); $metadata->addRoute('view', 'view_name'); @@ -23,37 +26,43 @@ public function testGenerate() $this->factory->expects($this->once()) ->method('getMetadataForClass') ->with('stdClass') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $this->adapter->expects($this->once()) ->method('generate') - ->with('view_name', array(), false) - ->will($this->returnValue('/foo')); + ->with('view_name', [], false) + ->willReturn('/foo'); - $this->assertEquals('/foo', $this->router->generate('view', new \stdClass)); + $this->assertEquals('/foo', $this->router->generate('view', new \stdClass())); } - public function testGenerateWithParams() + /** + * @test + */ + public function generateWithParams() { $metadata = new ClassMetadata('stdClass'); - $metadata->addRoute('view', 'view_name', array('foo' => 'bar')); + $metadata->addRoute('view', 'view_name', ['foo' => 'bar']); - $object = new \stdClass; + $object = new \stdClass(); $object->bar = 'baz'; $this->factory->expects($this->once()) ->method('getMetadataForClass') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $this->adapter->expects($this->once()) ->method('generate') - ->with('view_name', array('foo' => 'baz'), false) - ->will($this->returnValue('/foobar')); + ->with('view_name', ['foo' => 'baz'], false) + ->willReturn('/foobar'); $this->assertEquals('/foobar', $this->router->generate('view', $object)); } - public function testGenerateNonExistentType() + /** + * @test + */ + public function generateNonExistentType() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('The object of class "stdClass" has no route with type "foo". Available types: view'); @@ -63,21 +72,24 @@ public function testGenerateNonExistentType() $this->factory->expects($this->once()) ->method('getMetadataForClass') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); - $this->router->generate('foo', new \stdClass); + $this->router->generate('foo', new \stdClass()); } - public function testGenerateNoMetadata() + /** + * @test + */ + public function generateNoMetadata() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('There were no object routes defined for class "stdClass".'); $this->factory->expects($this->once()) ->method('getMetadataForClass') - ->will($this->returnValue(null)); + ->willReturn(null); - $this->router->generate('foo', new \stdClass); + $this->router->generate('foo', new \stdClass()); } protected function setUp(): void diff --git a/tests/JMS/Tests/ObjectRouting/Resources/config/JMS.Tests.ObjectRouting.Metadata.Driver.Fixture.BlogPost.php b/tests/JMS/Tests/ObjectRouting/Resources/config/JMS.Tests.ObjectRouting.Metadata.Driver.Fixture.BlogPost.php index 5604334..9bcb3a8 100644 --- a/tests/JMS/Tests/ObjectRouting/Resources/config/JMS.Tests.ObjectRouting.Metadata.Driver.Fixture.BlogPost.php +++ b/tests/JMS/Tests/ObjectRouting/Resources/config/JMS.Tests.ObjectRouting.Metadata.Driver.Fixture.BlogPost.php @@ -2,7 +2,7 @@ $metadata = new JMS\ObjectRouting\Metadata\ClassMetadata('JMS\Tests\ObjectRouting\Metadata\Driver\Fixture\BlogPost'); -$metadata->addRoute('view', 'blog_post_view', array('slug' => 'slug')); -$metadata->addRoute('edit', 'blog_post_edit', array('slug' => 'slug')); +$metadata->addRoute('view', 'blog_post_view', ['slug' => 'slug']); +$metadata->addRoute('edit', 'blog_post_edit', ['slug' => 'slug']); -return $metadata; \ No newline at end of file +return $metadata; diff --git a/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php b/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php index 3e3410b..d369b81 100644 --- a/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php +++ b/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php @@ -13,14 +13,17 @@ class Symfony22AdapterTest extends TestCase private $adapter; private $router; - public function testGenerate() + /** + * @test + */ + public function generate() { $this->router->expects($this->once()) ->method('generate') - ->with('foo', array('bar' => 'baz'), UrlGeneratorInterface::ABSOLUTE_URL) - ->will($this->returnValue('/foo-bar-baz')); + ->with('foo', ['bar' => 'baz'], UrlGeneratorInterface::ABSOLUTE_URL) + ->willReturn('/foo-bar-baz'); - $this->assertEquals('/foo-bar-baz', $this->adapter->generate('foo', array('bar' => 'baz'), true)); + $this->assertEquals('/foo-bar-baz', $this->adapter->generate('foo', ['bar' => 'baz'], true)); } protected function setUp(): void diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 95b1e11..79fcc41 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,16 +1,16 @@