forked from schmittjoh/object-routing
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run PHP-CS-Fixer automatically (#15)
- Loading branch information
Showing
24 changed files
with
151 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ vendor/ | |
phpunit.xml | ||
composer.lock | ||
.phpunit.result.cache | ||
.php-cs-fixer.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
return (new PhpCsFixer\Config()) | ||
->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/') | ||
) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
|
||
/* | ||
* Copyright 2013 Johannes M. Schmitt <[email protected]> | ||
* | ||
* | ||
* 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 = []) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
|
||
namespace JMS\ObjectRouting\Exception; | ||
|
||
|
||
interface Exception | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
|
||
/* | ||
* Copyright 2013 Johannes M. Schmitt <[email protected]> | ||
* | ||
* | ||
* 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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
|
||
/* | ||
* Copyright 2013 Johannes M. Schmitt <[email protected]> | ||
* | ||
* | ||
* 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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
*/ | ||
class PhpDriver extends AbstractFileDriver | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
*/ | ||
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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,20 +24,15 @@ | |
use Symfony\Component\Yaml\Yaml; | ||
|
||
/** | ||
* Class YamlDriver | ||
* @package JMS\ObjectRouting\Metadata\Driver | ||
* Class YamlDriver. | ||
* | ||
* @author Sebastian Kroczek <[email protected]> | ||
*/ | ||
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 | ||
{ | ||
|
Oops, something went wrong.