From 63c4e68bb4609ef355f909ff80a07bcc70456f3b Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Mon, 1 Jul 2024 10:20:48 +0200 Subject: [PATCH] Run PHP-CS-Fixer automatically (#15) --- .github/workflows/fix-cs-php.yml | 29 +++++++++++++++++ .gitignore | 1 + .php-cs-fixer.dist.php | 19 +++++++++++ .../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/Driver/Fixture/BlogPost.php | 2 +- .../Driver/Fixture/BlogPostWithAttributes.php | 4 +-- .../Metadata/Driver/PhpDriverTest.php | 10 +++--- .../Metadata/Driver/XmlDriverTest.php | 12 +++---- .../Metadata/Driver/YamlDriverTest.php | 12 +++---- .../Tests/ObjectRouting/ObjectRouterTest.php | 26 +++++++-------- ...uting.Metadata.Driver.Fixture.BlogPost.php | 6 ++-- .../Symfony/Symfony22AdapterTest.php | 6 ++-- tests/bootstrap.php | 12 +++---- 24 files changed, 151 insertions(+), 135 deletions(-) create mode 100644 .github/workflows/fix-cs-php.yml create mode 100644 .php-cs-fixer.dist.php diff --git a/.github/workflows/fix-cs-php.yml b/.github/workflows/fix-cs-php.yml new file mode 100644 index 0000000..4e30909 --- /dev/null +++ b/.github/workflows/fix-cs-php.yml @@ -0,0 +1,29 @@ +# Update this by running +# curl https://gist.github.com/mpdude/ca93a185bcbf56eb7e341632ad4f8263/raw/fix-cs-php.yml > .github/workflows/fix-cs-php.yml + +on: + push: + branches: + - master + pull_request: + +name: Coding Standards + +jobs: + fix-cs-issues: + name: PHP-CS-Fixer + runs-on: ubuntu-22.04 + if: github.actor != 'dependabot[bot]' + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Run PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga + + - name: Commit and push back changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Fix CS with PHP-CS-Fixer" diff --git a/.gitignore b/.gitignore index c8d673d..3b62acd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor/ phpunit.xml composer.lock .phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..87587fc --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,19 @@ +setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => array('syntax' => 'short'), + 'no_unreachable_default_argument_value' => false, + 'braces' => array('allow_single_line_closure' => true), + 'heredoc_to_nowdoc' => false, + 'psr_autoloading' => false, + ]) + ->setRiskyAllowed(true) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ->notPath('vendor/') + ) +; 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/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..efdd49c 100644 --- a/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php +++ b/tests/JMS/Tests/ObjectRouting/Metadata/Driver/PhpDriverTest.php @@ -16,10 +16,10 @@ public function testLoad() $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); } @@ -30,6 +30,6 @@ public function testLoadReturnsNullWhenNoRoutes() 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..17143a3 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; @@ -18,10 +16,10 @@ public function testLoad() $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); } @@ -32,6 +30,6 @@ public function testLoadReturnsNullWhenNoRoutes() 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..8a7f576 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; @@ -18,10 +16,10 @@ public function testLoad() $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); } @@ -32,6 +30,6 @@ public function testLoadReturnsNullWhenNoRoutes() 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..9b3b689 100644 --- a/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php +++ b/tests/JMS/Tests/ObjectRouting/ObjectRouterTest.php @@ -23,32 +23,32 @@ 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() { $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)); } @@ -63,9 +63,9 @@ 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() @@ -75,9 +75,9 @@ public function testGenerateNoMetadata() $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..a953cf8 100644 --- a/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php +++ b/tests/JMS/Tests/ObjectRouting/Symfony/Symfony22AdapterTest.php @@ -17,10 +17,10 @@ public function testGenerate() { $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 @@