Skip to content

Commit e22e253

Browse files
martingoldgithub-actions[bot]
authored andcommitted
Fix CS with PHP-CS-Fixer
1 parent 97d9982 commit e22e253

File tree

9 files changed

+36
-40
lines changed

9 files changed

+36
-40
lines changed

src/Doctrine/PersistentTranslatable.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function eject(): void
120120

121121
$type = $this->translatedProperty->getType();
122122
if ($type instanceof ReflectionNamedType && TranslatableInterface::class === $type->getName() && \is_string($value)) {
123-
if ($this->valueForEjection === null || $this->valueForEjection->getPrimaryValue() !== $value) {
123+
if (null === $this->valueForEjection || $this->valueForEjection->getPrimaryValue() !== $value) {
124124
$this->valueForEjection = new UninitializedPersistentTranslatable($value);
125125
}
126126
$value = $this->valueForEjection;
@@ -173,7 +173,7 @@ public function setTranslation(mixed $value, ?string $locale = null): void
173173
$this->setPrimaryValue($value);
174174
} else {
175175
$entity = $this->getTranslationEntity($locale);
176-
if ($entity === null) {
176+
if (null === $entity) {
177177
$entity = $this->createTranslationEntity($locale);
178178
}
179179
$this->translationProperty->setValue($entity, $value);
@@ -193,7 +193,7 @@ public function translate(?string $locale = null): mixed
193193
}
194194

195195
$entity = $this->getTranslationEntity($locale);
196-
if ($entity !== null) {
196+
if (null !== $entity) {
197197
$translated = $this->translationProperty->getValue($entity);
198198
if (null !== $translated) {
199199
return $translated;
@@ -215,12 +215,12 @@ public function translate(?string $locale = null): mixed
215215
public function isTranslatedInto(string $locale): bool
216216
{
217217
if ($locale === $this->primaryLocale) {
218-
return $this->primaryValue !== '' && $this->primaryValue !== null;
218+
return '' !== $this->primaryValue && null !== $this->primaryValue;
219219
}
220220

221221
$entity = $this->getTranslationEntity($locale);
222222

223-
return $entity !== null && $this->translationProperty->getValue($entity) !== null;
223+
return null !== $entity && null !== $this->translationProperty->getValue($entity);
224224
}
225225

226226
public function __toString(): string
@@ -258,7 +258,7 @@ private function cacheTranslation(string $locale): void
258258

259259
$translationInLocale = ($translationsFilteredByLocale->count() > 0) ? $translationsFilteredByLocale->first() : null;
260260

261-
if (is_bool($translationInLocale)) {
261+
if (\is_bool($translationInLocale)) {
262262
return;
263263
}
264264

@@ -282,7 +282,7 @@ private function stringifyException(Throwable $e): string
282282
{
283283
$exceptionAsString = '';
284284
while (null !== $e) {
285-
if ($exceptionAsString !== '') {
285+
if ('' !== $exceptionAsString) {
286286
$exceptionAsString .= \PHP_EOL.'Previous exception: '.\PHP_EOL;
287287
}
288288
$exceptionAsString .= \sprintf(

src/Doctrine/PolyglotListener.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Doctrine\ORM\Event\PreFlushEventArgs;
1616
use Doctrine\Persistence\Event\LifecycleEventArgs;
1717
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
18-
use Doctrine\Persistence\ObjectManager;
1918
use Psr\Log\LoggerInterface;
2019
use Psr\Log\NullLogger;
2120
use WeakReference;
@@ -127,7 +126,7 @@ private function getTranslationMetadatas(object $entity, EntityManagerInterface
127126

128127
foreach (array_merge([$classMetadata->name], $classMetadata->parentClasses) as $className) {
129128
$tm = $this->loadTranslationMetadataForClass($className, $em);
130-
if ($tm !== null) {
129+
if (null !== $tm) {
131130
$this->translatableClassMetadatasByClass[$class][] = $tm;
132131
}
133132
}
@@ -150,7 +149,7 @@ private function loadTranslationMetadataForClass(string $className, EntityManage
150149
$cache = $em->getConfiguration()->getMetadataCache();
151150
$cacheKey = $this->getCacheKey($className);
152151

153-
if ($cache !== null && $cache->hasItem($cacheKey)) {
152+
if (null !== $cache && $cache->hasItem($cacheKey)) {
154153
$item = $cache->getItem($cacheKey);
155154
/** @var SerializedTranslatableClassMetadata|null $data */
156155
$data = $item->get();
@@ -176,7 +175,7 @@ private function loadTranslationMetadataForClass(string $className, EntityManage
176175
}
177176

178177
// Save if cache driver available
179-
if ($cache !== null) {
178+
if (null !== $cache) {
180179
$item = $cache->getItem($cacheKey);
181180
$item->set($meta?->sleep());
182181
$cache->save($item);

src/Doctrine/TranslatableClassMetadata.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final class TranslatableClassMetadata
6262
private ?ReflectionProperty $translationLocaleProperty = null;
6363

6464
/**
65-
* @var ReflectionClass<object>|null $translationClass
65+
* @var ReflectionClass<object>|null
6666
*/
6767
private ?ReflectionClass $translationClass = null;
6868

@@ -75,9 +75,9 @@ final class TranslatableClassMetadata
7575

7676
/**
7777
* @param class-string<object> $class The FQCN for the entity class whose translatable fields are described by this
78-
* TranslatableClassMetadata instance. If the class has base entity classes (or mapped
79-
* superclasses), a separate instance of TranslatableClassMetadata will be used for
80-
* their fields.
78+
* TranslatableClassMetadata instance. If the class has base entity classes (or mapped
79+
* superclasses), a separate instance of TranslatableClassMetadata will be used for
80+
* their fields.
8181
*/
8282
private function __construct(
8383
private readonly string $class
@@ -112,23 +112,23 @@ public function setLogger(?LoggerInterface $logger = null): void
112112

113113
public function sleep(): SerializedTranslatableClassMetadata
114114
{
115-
if ($this->translationClass === null) {
115+
if (null === $this->translationClass) {
116116
throw new ShouldNotHappen('translationClass cannot be null');
117117
}
118118

119-
if ($this->primaryLocale === null) {
119+
if (null === $this->primaryLocale) {
120120
throw new ShouldNotHappen('primaryLocale cannot be null');
121121
}
122122

123-
if ($this->translationLocaleProperty === null) {
123+
if (null === $this->translationLocaleProperty) {
124124
throw new ShouldNotHappen('translationLocaleProperty cannot be null');
125125
}
126126

127-
if ($this->translationMappingProperty === null) {
127+
if (null === $this->translationMappingProperty) {
128128
throw new ShouldNotHappen('translationMappingProperty cannot be null');
129129
}
130130

131-
if ($this->translationsCollectionProperty === null) {
131+
if (null === $this->translationsCollectionProperty) {
132132
throw new ShouldNotHappen('translationsCollectionProperty cannot be null');
133133
}
134134

@@ -164,7 +164,6 @@ public static function wakeup(SerializedTranslatableClassMetadata $data, Runtime
164164
$self->primaryLocale = $data->primaryLocale;
165165
$self->translationClass = $reflectionService->getClass($data->translationClass);
166166

167-
168167
foreach ($data->translationFieldMapping as $fieldname => $property) {
169168
$self->translationFieldMapping[$fieldname] = $reflectionService->getAccessibleProperty(...$property) ??
170169
throw new ShouldNotHappen("Cannot get reflection on {$property[0]}::{$property[1]}");
@@ -218,7 +217,7 @@ private function assertAttributesAreComplete(string $class): void
218217
*/
219218
private function findTranslatedProperties(ClassMetadata $cm, ClassMetadataFactory $classMetadataFactory): void
220219
{
221-
if ($this->translationClass === null) {
220+
if (null === $this->translationClass) {
222221
return;
223222
}
224223

@@ -234,13 +233,13 @@ private function findTranslatedProperties(ClassMetadata $cm, ClassMetadataFactor
234233
already contains that declaration, we need not include it.
235234
*/
236235
$declaringClass = $reflectionProperty->getDeclaringClass()->name;
237-
if ($declaringClass !== $cm->name && $cm->parentClasses !== [] && is_a($cm->parentClasses[0], $declaringClass, true)) {
236+
if ($declaringClass !== $cm->name && [] !== $cm->parentClasses && is_a($cm->parentClasses[0], $declaringClass, true)) {
238237
continue;
239238
}
240239

241240
$attributes = $reflectionProperty->getAttributes(Attribute\Translatable::class);
242241

243-
if ($attributes === []) {
242+
if ([] === $attributes) {
244243
continue;
245244
}
246245

@@ -268,7 +267,7 @@ private function findTranslationsCollection(ClassMetadata $cm, ClassMetadataFact
268267

269268
$reflectionProperty = $cm->getReflectionProperty($fieldName);
270269

271-
if ($reflectionProperty !== null && $reflectionProperty->getAttributes(Attribute\TranslationCollection::class) !== []) {
270+
if (null !== $reflectionProperty && [] !== $reflectionProperty->getAttributes(Attribute\TranslationCollection::class)) {
272271
if (!$mapping instanceof InverseSideMapping) {
273272
return;
274273
}
@@ -309,7 +308,7 @@ private function parseTranslationsEntity(ClassMetadata $cm): void
309308
foreach ($cm->fieldMappings as $fieldName => $mapping) {
310309
$reflectionProperty = $cm->getReflectionProperty($fieldName);
311310

312-
if ($reflectionProperty !== null && $reflectionProperty->getAttributes(Attribute\Locale::class) !== []) {
311+
if (null !== $reflectionProperty && [] !== $reflectionProperty->getAttributes(Attribute\Locale::class)) {
313312
$this->translationLocaleProperty = $reflectionProperty;
314313

315314
return;

src/Doctrine/TranslatableStringType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TranslatableStringType extends Type
1818

1919
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
2020
{
21-
if (is_array($column['options']) && ($column['options']['use_text_column'] ?? false)) {
21+
if (\is_array($column['options']) && ($column['options']['use_text_column'] ?? false)) {
2222
return $platform->getClobTypeDeclarationSQL($column);
2323
}
2424

@@ -51,7 +51,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
5151

5252
public function convertToPHPValue($value, AbstractPlatform $platform): UninitializedPersistentTranslatable
5353
{
54-
if (!is_string($value)) {
54+
if (!\is_string($value)) {
5555
throw new ShouldNotHappen('Translated value is not string.');
5656
}
5757

src/Entity/BaseTranslation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ class BaseTranslation
3535
*/
3636
#[Polyglot\Locale]
3737
#[ORM\Column]
38-
protected string|null $locale;
38+
protected ?string $locale;
3939

4040
/**
4141
* @ORM\JoinColumn(name="entity_id", referencedColumnName="id", nullable=false)
4242
*/
4343
#[ORM\JoinColumn(name: 'entity_id', referencedColumnName: 'id', nullable: false)]
4444
protected object $entity;
4545

46-
public function getLocale(): string|null
46+
public function getLocale(): ?string
4747
{
4848
return $this->locale;
4949
}

src/Exception/ShouldNotHappen.php

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

1010
class ShouldNotHappen extends Exception
1111
{
12-
public function __construct(string $message, Throwable|null $previous = null)
12+
public function __construct(string $message, ?Throwable $previous = null)
1313
{
1414
parent::__construct($message, 0, $previous);
1515
}

src/Translatable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function setTranslation(mixed $value, ?string $locale = null): void
9494

9595
public function isTranslatedInto(string $locale): bool
9696
{
97-
return isset($this->translations[$locale]) && (string) $this->translations[$locale] !== '';
97+
return isset($this->translations[$locale]) && '' !== (string) $this->translations[$locale];
9898
}
9999

100100
public function __toString(): string

src/TranslatableChain.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class TranslatableChain implements TranslatableInterface
2121
private array $translatables;
2222

2323
/**
24-
* @param TranslatableInterface<T> ...$translatables
24+
* @param TranslatableInterface<T> ...$translatables
2525
* @return self<T>
2626
*/
2727
public static function firstNonEmpty(TranslatableInterface ...$translatables): self
@@ -32,7 +32,7 @@ public static function firstNonEmpty(TranslatableInterface ...$translatables): s
3232
}
3333

3434
/**
35-
* @param TranslatableInterface<T> ...$translatables
35+
* @param TranslatableInterface<T> ...$translatables
3636
* @return self<T>
3737
*/
3838
public static function firstTranslation(TranslatableInterface ...$translatables): self
@@ -43,7 +43,7 @@ public static function firstTranslation(TranslatableInterface ...$translatables)
4343
}
4444

4545
/**
46-
* @param Closure(T): bool $comparator
46+
* @param Closure(T): bool $comparator
4747
* @param TranslatableInterface<T> ...$translatables
4848
*/
4949
private function __construct(

tests/Fixtures/Entity/TestEntityTranslation.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@ class TestEntityTranslation extends BaseTranslation
2828
* Contains the translation.
2929
*
3030
* Must be protected to be usable when this class is used as base for a mock.
31-
*
32-
* @var string
3331
*/
3432
#[ORM\Column(type: 'string')]
35-
protected string|null $text;
33+
protected ?string $text;
3634

37-
public function __construct(string|null $locale = null, string|null $text = null, ?TestEntity $entity = null)
35+
public function __construct(?string $locale = null, ?string $text = null, ?TestEntity $entity = null)
3836
{
3937
$this->locale = $locale;
4038
$this->text = $text;
4139

42-
if ($entity !== null) {
40+
if (null !== $entity) {
4341
$this->entity = $entity;
4442
}
4543
}

0 commit comments

Comments
 (0)