Skip to content

Commit f632d19

Browse files
authored
Aktualisiere auf PHP-CS-Fixer 2.19.0, angepasste Konfiguration und automatische Commits (Case 130695) (#11)
* Aktualisiere auf PHP-CS-Fixer 2.19.0, angepasste Konfiguration und automatische Commits (Case 130695) * Fix CS with PHP-CS-Fixer 2.19.0 Co-authored-by: mpdude <mpdude@users.noreply.github.com>
1 parent ceba518 commit f632d19

File tree

11 files changed

+57
-60
lines changed

11 files changed

+57
-60
lines changed

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

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,18 @@ name: Coding Standards
1212
jobs:
1313
open-pr-for-cs-violations:
1414
name: PHP-CS-Fixer
15-
runs-on: ubuntu-18.04
15+
runs-on: ubuntu-20.04
16+
if: github.actor != 'dependabot[bot]'
1617
steps:
17-
1818
- name: Checkout code
1919
uses: actions/checkout@v2
2020
with:
2121
ref: ${{ github.head_ref }}
2222

2323
- name: Run PHP-CS-Fixer
24-
uses: docker://oskarstark/php-cs-fixer-ga:2.16.7
25-
26-
- name: Create PR for CS fixups
27-
uses: peter-evans/create-pull-request@v3.8.2
28-
id: create-pull-request
29-
with:
30-
token: ${{ secrets.GITHUB_TOKEN }}
31-
title: Fix coding standards in ${{ github.ref }}
32-
branch: php-cs-fixer/${{ github.ref }}
33-
assignees: ${{ github.actor }}
34-
labels: php-cs-fixer
35-
body: Please merge these changes into the ${{ github.ref }} branch to fix coding standard violations.
36-
commit-message: Apply php-cs-fixer changes as of ${{ github.sha }}
24+
uses: docker://oskarstark/php-cs-fixer-ga:2.19.0
3725

38-
- name: Leave a notice in the discussion when fixing code in a Pull Request
39-
uses: docker://mpdude/comment-on-pr:v1.2.0
40-
env:
41-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42-
if: steps.create-pull-request.outputs.pr_number # only if PR was created in the previous step
43-
continue-on-error: true # continue on failure - necessary when the current branch does not have a pending PR
26+
- name: Commit and push back changes
27+
uses: stefanzweifel/git-auto-commit-action@v4
4428
with:
45-
msg: |
46-
@${{ github.actor }} please apply the coding standard fixes from #${{ steps.create-pull-request.outputs.pr_number }}
47-
48-
- name: Fail the workflow when necessary CS fixes were detected
49-
run: echo "Failing workflow run because CS violations were detected." && exit 1
50-
if: steps.create-pull-request.outputs.pr_number
29+
commit_message: "Fix CS with PHP-CS-Fixer 2.19.0"

.php_cs.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ return PhpCsFixer\Config::create()
99
'braces' => array('allow_single_line_closure' => true),
1010
'heredoc_to_nowdoc' => false,
1111
'phpdoc_annotation_without_dot' => false,
12+
'php_unit_test_annotation' => false,
13+
'php_unit_method_casing' => false,
14+
'global_namespace_import' => ['import_classes' => true, 'import_constants' => false, 'import_functions' => false],
1215
])
1316
->setRiskyAllowed(true)
1417
->setFinder(

src/Doctrine/PersistentTranslatable.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Webfactory\Bundle\PolyglotBundle\Doctrine;
1111

1212
use Doctrine\Common\Collections\Criteria;
13+
use Exception;
1314
use Psr\Log\LoggerInterface;
1415
use Psr\Log\NullLogger;
1516
use ReflectionClass;
@@ -220,7 +221,7 @@ public function translate($locale = null)
220221
}
221222

222223
return $this->primaryValue;
223-
} catch (\Exception $e) {
224+
} catch (Exception $e) {
224225
$message = sprintf(
225226
'Cannot translate property %s::%s into locale %s',
226227
\get_class($this->entity),
@@ -249,7 +250,7 @@ public function __toString()
249250
{
250251
try {
251252
return (string) $this->translate();
252-
} catch (\Exception $e) {
253+
} catch (Exception $e) {
253254
$this->logger->error($this->stringifyException($e));
254255

255256
return '';
@@ -332,12 +333,12 @@ protected function getCachedTranslation($locale)
332333
/**
333334
* @return string
334335
*/
335-
private function stringifyException(\Exception $e)
336+
private function stringifyException(Exception $e)
336337
{
337338
$exceptionAsString = '';
338339
while (null !== $e) {
339340
if (!empty($exceptionAsString)) {
340-
$exceptionAsString .= PHP_EOL.'Previous exception: '.PHP_EOL;
341+
$exceptionAsString .= \PHP_EOL.'Previous exception: '.\PHP_EOL;
341342
}
342343
$exceptionAsString .= sprintf(
343344
"Exception '%s' with message '%s' in %s:%d\n%s",

src/Doctrine/PolyglotListener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\ORM\Event\PreFlushEventArgs;
1717
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1818
use Psr\Log\LoggerInterface;
19+
use SplObjectStorage;
1920
use Webfactory\Bundle\PolyglotBundle\Locale\DefaultLocaleProvider;
2021

2122
class PolyglotListener
@@ -27,7 +28,7 @@ class PolyglotListener
2728
protected $_proxiesStripped = [];
2829
protected $defaultLocaleProvider;
2930

30-
/** @var \SplObjectStorage */
31+
/** @var SplObjectStorage */
3132
private $entitiesWithTranslations;
3233

3334
/**
@@ -47,7 +48,7 @@ public function __construct(
4748
$this->defaultLocaleProvider = $defaultLocaleProvider;
4849
$this->logger = $logger;
4950

50-
$this->entitiesWithTranslations = new \SplObjectStorage();
51+
$this->entitiesWithTranslations = new SplObjectStorage();
5152
}
5253

5354
public function postLoad(LifecycleEventArgs $event)

src/Doctrine/TranslatableClassMetadata.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Doctrine\Persistence\Mapping\ClassMetadata;
1717
use Doctrine\Persistence\Mapping\ReflectionService;
1818
use Psr\Log\LoggerInterface;
19+
use ReflectionClass;
20+
use ReflectionProperty;
21+
use RuntimeException;
1922
use Webfactory\Bundle\PolyglotBundle\Annotation as Annotation;
2023
use Webfactory\Bundle\PolyglotBundle\Locale\DefaultLocaleProvider;
2124
use Webfactory\Bundle\PolyglotBundle\Translatable;
@@ -32,40 +35,40 @@ class TranslatableClassMetadata
3235
* Ein Mapping von Feldnamen in der Hauptklasse auf die Felder in der
3336
* Übersetzungs-Klasse, in denen die jeweilige Übersetzung liegt.
3437
*
35-
* @var \ReflectionProperty[]
38+
* @var ReflectionProperty[]
3639
*/
3740
protected $translationFieldMapping = [];
3841

3942
/**
4043
* Die Eigenschaften der Haupt-Klasse, die übersetzbar sind; indiziert nach Feldnamen.
4144
*
42-
* @var \ReflectionProperty[]
45+
* @var ReflectionProperty[]
4346
*/
4447
protected $translatedProperties = [];
4548

4649
/**
4750
* Die Eigenschaft der Haupt-Klasse, die die Collection der Übersetzungen hält.
4851
*
49-
* @var \ReflectionProperty
52+
* @var ReflectionProperty
5053
*/
5154
protected $translationsCollectionProperty;
5255

5356
/**
5457
* Die Eigenschaft der Übersetzungs-Klasse, die als many-to-one auf die Haupt-Klasse verweist.
5558
*
56-
* @var \ReflectionProperty
59+
* @var ReflectionProperty
5760
*/
5861
protected $translationMappingProperty;
5962

6063
/**
6164
* Die Eigenschaft in der Übersetzungs-Klasse, die die Sprache einer Übersetzungsinstanz enhtält.
6265
*
63-
* @var \ReflectionProperty
66+
* @var ReflectionProperty
6467
*/
6568
protected $translationLocaleProperty;
6669

6770
/**
68-
* @var \ReflectionClass Die Übersetzungs-Klasse.
71+
* @var ReflectionClass Die Übersetzungs-Klasse.
6972
*/
7073
protected $translationClass;
7174

@@ -148,19 +151,19 @@ protected function assertNoAnnotationsArePresent()
148151
protected function assertAnnotationsAreComplete()
149152
{
150153
if (null === $this->translationClass) {
151-
throw new \RuntimeException('The annotation with the translation class name is missing or incorrect, e.g. '.'@ORM\OneToMany(targetEntity="TestEntityTranslation", ...)');
154+
throw new RuntimeException('The annotation with the translation class name is missing or incorrect, e.g. '.'@ORM\OneToMany(targetEntity="TestEntityTranslation", ...)');
152155
}
153156

154157
if (null === $this->translationLocaleProperty) {
155-
throw new \RuntimeException('The @Polyglot\Locale annotation at the language property of the translation class is missing or '.'incorrect');
158+
throw new RuntimeException('The @Polyglot\Locale annotation at the language property of the translation class is missing or '.'incorrect');
156159
}
157160

158161
if (null === $this->translationMappingProperty) {
159-
throw new \RuntimeException('The attribute referenced in the mappedBy-Attribute of the @ORM\OneToMany(..., mappedBy="...") is '.'missing or incorrect');
162+
throw new RuntimeException('The attribute referenced in the mappedBy-Attribute of the @ORM\OneToMany(..., mappedBy="...") is '.'missing or incorrect');
160163
}
161164

162165
if (0 === \count($this->translatedProperties)) {
163-
throw new \RuntimeException('No translatable attributes annotated with @Polyglot\Translatable were found');
166+
throw new RuntimeException('No translatable attributes annotated with @Polyglot\Translatable were found');
164167
}
165168
}
166169

@@ -221,7 +224,7 @@ protected function findPrimaryLocale(Reader $reader, ClassMetadata $classMetadat
221224

222225
protected function parseTranslationsEntity(Reader $reader, $class)
223226
{
224-
$this->translationClass = new \ReflectionClass($class);
227+
$this->translationClass = new ReflectionClass($class);
225228

226229
foreach ($this->translationClass->getProperties() as $property) {
227230
$annotation = $reader->getPropertyAnnotation(

src/Exception/TranslationException.php

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

33
namespace Webfactory\Bundle\PolyglotBundle\Exception;
44

5-
class TranslationException extends \Exception
5+
use Exception;
6+
7+
class TranslationException extends Exception
68
{
79
/**
810
* TranslationException constructor.
911
*
1012
* @param string $message
1113
*/
12-
public function __construct($message, \Exception $previous)
14+
public function __construct($message, Exception $previous)
1315
{
1416
parent::__construct($message, 0, $previous);
1517
}

src/Translatable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Webfactory\Bundle\PolyglotBundle;
1111

12+
use InvalidArgumentException;
1213
use Webfactory\Bundle\PolyglotBundle\Locale\DefaultLocaleProvider;
1314

1415
/**
@@ -58,7 +59,7 @@ class Translatable implements TranslatableInterface
5859
public function __construct($value = null, $defaultLocale = null)
5960
{
6061
if (null !== $defaultLocale && !\is_string($defaultLocale) && !$defaultLocale instanceof DefaultLocaleProvider) {
61-
throw new \InvalidArgumentException('When provided, the $defaultLocale argument must either be a string or an instance of DefaultLocaleProvider');
62+
throw new InvalidArgumentException('When provided, the $defaultLocale argument must either be a string or an instance of DefaultLocaleProvider');
6263
}
6364

6465
$this->defaultLocale = $defaultLocale;

tests/Doctrine/PersistentTranslatableTest.php

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

33
namespace Webfactory\Bundle\PolyglotBundle\Tests\Doctrine;
44

5+
use PHPUnit_Framework_TestCase;
56
use Psr\Log\LoggerInterface;
67
use Psr\Log\NullLogger;
8+
use ReflectionClass;
9+
use ReflectionProperty;
10+
use RuntimeException;
711
use Symfony\Component\ErrorHandler\BufferingLogger;
812
use Webfactory\Bundle\PolyglotBundle\Doctrine\PersistentTranslatable;
913
use Webfactory\Bundle\PolyglotBundle\Locale\DefaultLocaleProvider;
1014
use Webfactory\Bundle\PolyglotBundle\Tests\TestEntity;
1115

12-
class PersistentTranslatableTest extends \PHPUnit_Framework_TestCase
16+
class PersistentTranslatableTest extends PHPUnit_Framework_TestCase
1317
{
1418
public function testToStringReturnsTranslatedMessage()
1519
{
@@ -155,11 +159,11 @@ private function createProxy(TestEntity $entity, LoggerInterface $logger = null)
155159
$entity,
156160
'en',
157161
$localeProvider,
158-
$this->makeAccessible(new \ReflectionProperty($translationClass, 'text')),
159-
$this->makeAccessible(new \ReflectionProperty($entity, 'translations')),
160-
new \ReflectionClass($translationClass),
161-
$this->makeAccessible(new \ReflectionProperty($translationClass, 'locale')),
162-
$this->makeAccessible(new \ReflectionProperty($translationClass, 'entity')),
162+
$this->makeAccessible(new ReflectionProperty($translationClass, 'text')),
163+
$this->makeAccessible(new ReflectionProperty($entity, 'translations')),
164+
new ReflectionClass($translationClass),
165+
$this->makeAccessible(new ReflectionProperty($translationClass, 'locale')),
166+
$this->makeAccessible(new ReflectionProperty($translationClass, 'entity')),
163167
$logger
164168
);
165169

@@ -171,16 +175,16 @@ private function breakEntity(TestEntity $entity)
171175
$brokenCollection = $this->getMockBuilder('Doctrine\Common\Collections\ArrayCollection')->getMock();
172176
$brokenCollection->expects($this->any())
173177
->method('matching')
174-
->will($this->throwException(new \RuntimeException('Cannot find translations')));
175-
$property = new \ReflectionProperty($entity, 'translations');
178+
->will($this->throwException(new RuntimeException('Cannot find translations')));
179+
$property = new ReflectionProperty($entity, 'translations');
176180
$property->setAccessible(true);
177181
$property->setValue($entity, $brokenCollection);
178182
}
179183

180184
/**
181-
* @return \ReflectionProperty
185+
* @return ReflectionProperty
182186
*/
183-
private function makeAccessible(\ReflectionProperty $property)
187+
private function makeAccessible(ReflectionProperty $property)
184188
{
185189
$property->setAccessible(true);
186190

tests/Doctrine/TranslatableClassMetadataTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
use Doctrine\Common\Annotations\AnnotationReader;
66
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
7+
use PHPUnit_Framework_TestCase;
78
use Psr\Log\LoggerInterface;
89
use Webfactory\Bundle\PolyglotBundle\Doctrine\TranslatableClassMetadata;
910
use Webfactory\Bundle\PolyglotBundle\Tests\TestEntity;
1011
use Webfactory\Bundle\PolyglotBundle\Tests\TestEntityTranslation;
1112
use Webfactory\Doctrine\ORMTestInfrastructure\ORMInfrastructure;
1213

13-
class TranslatableClassMetadataTest extends \PHPUnit_Framework_TestCase
14+
class TranslatableClassMetadataTest extends PHPUnit_Framework_TestCase
1415
{
1516
/**
1617
* @test

tests/IntegrationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\Common\Annotations\AnnotationReader;
66
use Doctrine\ORM\EntityManagerInterface;
7+
use PHPUnit_Framework_TestCase;
78
use Webfactory\Bundle\PolyglotBundle\Doctrine\PolyglotListener;
89
use Webfactory\Bundle\PolyglotBundle\Locale\DefaultLocaleProvider;
910
use Webfactory\Bundle\PolyglotBundle\Tests\TestEntity;
@@ -12,7 +13,7 @@
1213
use Webfactory\Bundle\PolyglotBundle\TranslatableInterface;
1314
use Webfactory\Doctrine\ORMTestInfrastructure\ORMInfrastructure;
1415

15-
class IntegrationTest extends \PHPUnit_Framework_TestCase
16+
class IntegrationTest extends PHPUnit_Framework_TestCase
1617
{
1718
/** @var ORMInfrastructure */
1819
private $infrastructure;

0 commit comments

Comments
 (0)