Skip to content

Commit 63c4e68

Browse files
authored
Run PHP-CS-Fixer automatically (#15)
1 parent bb3b78c commit 63c4e68

24 files changed

+151
-135
lines changed

.github/workflows/fix-cs-php.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Update this by running
2+
# curl https://gist.github.com/mpdude/ca93a185bcbf56eb7e341632ad4f8263/raw/fix-cs-php.yml > .github/workflows/fix-cs-php.yml
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
10+
name: Coding Standards
11+
12+
jobs:
13+
fix-cs-issues:
14+
name: PHP-CS-Fixer
15+
runs-on: ubuntu-22.04
16+
if: github.actor != 'dependabot[bot]'
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.head_ref }}
22+
23+
- name: Run PHP-CS-Fixer
24+
uses: docker://oskarstark/php-cs-fixer-ga
25+
26+
- name: Commit and push back changes
27+
uses: stefanzweifel/git-auto-commit-action@v5
28+
with:
29+
commit_message: "Fix CS with PHP-CS-Fixer"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor/
22
phpunit.xml
33
composer.lock
44
.phpunit.result.cache
5+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
return (new PhpCsFixer\Config())
4+
->setRules([
5+
'@Symfony' => true,
6+
'@Symfony:risky' => true,
7+
'array_syntax' => array('syntax' => 'short'),
8+
'no_unreachable_default_argument_value' => false,
9+
'braces' => array('allow_single_line_closure' => true),
10+
'heredoc_to_nowdoc' => false,
11+
'psr_autoloading' => false,
12+
])
13+
->setRiskyAllowed(true)
14+
->setFinder(
15+
PhpCsFixer\Finder::create()
16+
->in(__DIR__)
17+
->notPath('vendor/')
18+
)
19+
;

src/JMS/ObjectRouting/Attribute/ObjectRoute.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
/*
44
* Copyright 2013 Johannes M. Schmitt <schmittjoh@gmail.com>
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,7 +28,7 @@ final class ObjectRoute
2828
public $name;
2929

3030
/** @var array */
31-
public $params = array();
31+
public $params = [];
3232

3333
public function __construct(string $type, string $name, array $params = [])
3434
{

src/JMS/ObjectRouting/Exception/Exception.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace JMS\ObjectRouting\Exception;
44

5-
65
interface Exception
76
{
8-
9-
}
7+
}

src/JMS/ObjectRouting/Exception/RuntimeException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace JMS\ObjectRouting\Exception;
44

5-
65
class RuntimeException extends \RuntimeException implements Exception
76
{
8-
9-
}
7+
}

src/JMS/ObjectRouting/Exception/XmlErrorException.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22

33
namespace JMS\ObjectRouting\Exception;
44

5-
65
class XmlErrorException extends RuntimeException
76
{
87
private $xmlError;
98

109
public function __construct(\LibXMLError $error)
1110
{
1211
switch ($error->level) {
13-
case LIBXML_ERR_WARNING:
12+
case \LIBXML_ERR_WARNING:
1413
$level = 'WARNING';
1514
break;
16-
case LIBXML_ERR_FATAL:
15+
case \LIBXML_ERR_FATAL:
1716
$level = 'FATAL';
1817
break;
19-
case LIBXML_ERR_ERROR:
18+
case \LIBXML_ERR_ERROR:
2019
$level = 'ERROR';
2120
break;
2221
default:
@@ -30,4 +29,4 @@ public function getXmlError()
3029
{
3130
return $this->xmlError;
3231
}
33-
}
32+
}

src/JMS/ObjectRouting/Metadata/ClassMetadata.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
/*
44
* Copyright 2013 Johannes M. Schmitt <schmittjoh@gmail.com>
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,14 +23,14 @@
2323

2424
class ClassMetadata extends MergeableClassMetadata
2525
{
26-
public $routes = array();
26+
public $routes = [];
2727

28-
public function addRoute($type, $name, array $params = array())
28+
public function addRoute($type, $name, array $params = [])
2929
{
30-
$this->routes[$type] = array(
30+
$this->routes[$type] = [
3131
'name' => $name,
3232
'params' => $params,
33-
);
33+
];
3434
}
3535

3636
public function merge(MergeableInterface $object): void
@@ -42,10 +42,10 @@ public function merge(MergeableInterface $object): void
4242
public function serialize(): string
4343
{
4444
return serialize(
45-
array(
45+
[
4646
$this->routes,
4747
parent::serialize(),
48-
)
48+
]
4949
);
5050
}
5151

@@ -54,9 +54,8 @@ public function unserialize($str): void
5454
list(
5555
$this->routes,
5656
$parentStr
57-
) = unserialize($str);
57+
) = unserialize($str);
5858

5959
parent::unserialize($parentStr);
6060
}
61-
6261
}

src/JMS/ObjectRouting/Metadata/Driver/AttributeDriver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
/*
44
* Copyright 2013 Johannes M. Schmitt <schmittjoh@gmail.com>
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/JMS/ObjectRouting/Metadata/Driver/PhpDriver.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818

1919
namespace JMS\ObjectRouting\Metadata\Driver;
2020

21-
2221
use JMS\ObjectRouting\Exception\RuntimeException;
2322
use JMS\ObjectRouting\Metadata\ClassMetadata;
2423
use Metadata\Driver\AbstractFileDriver;
2524

2625
/**
27-
* Class PhpDriver
28-
* @package JMS\ObjectRouting\Metadata\Driver
26+
* Class PhpDriver.
27+
*
2928
* @author Sebastian Kroczek <sk@xbug.de>
3029
*/
3130
class PhpDriver extends AbstractFileDriver

0 commit comments

Comments
 (0)