Skip to content

Commit 689e2d9

Browse files
style: adjust coding standards and type hints
1 parent 61950b6 commit 689e2d9

79 files changed

Lines changed: 995 additions & 1131 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

rector.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
22

3-
use Rector\Config\RectorConfig;
3+
use Rector\Config\RectorConfig;
44
use Rector\ValueObject\PhpVersion;
55
use Rector\Set\ValueObject\LevelSetList;
66
use Rector\PHPUnit\Set\PHPUnitSetList;
77
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
88

99
return RectorConfig::configure()
10-
->withSkip([PreferPHPUnitThisCallRector::class])
1110
->withPhpVersion(PhpVersion::PHP_84)
1211
->withPaths([
1312
__DIR__ . '/src',
@@ -22,4 +21,7 @@
2221
])
2322
->withAttributesSets(doctrine: true)
2423
->withTypeCoverageLevel(3)
25-
->withParallel(240, 8, 5);
24+
->withParallel(240, 8, 5)
25+
->withSkip([
26+
PreferPHPUnitThisCallRector::class
27+
]);

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public function getConfigTreeBuilder(): TreeBuilder
3030
->scalarPrototype()->end()
3131
->defaultValue([])
3232
->end()
33-
->end()
34-
;
33+
->end();
3534

3635
return $treeBuilder;
3736
}

src/DependencyInjection/TmiTranslationExtension.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Tmi\TranslationBundle\DependencyInjection;
66

77
use Doctrine\DBAL\Types\Exception\TypesException;
8-
use Exception;
98
use Doctrine\DBAL\Types\Type;
109
use Symfony\Component\Config\FileLocator;
1110
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -18,12 +17,13 @@ final class TmiTranslationExtension extends Extension implements PrependExtensio
1817
{
1918
/**
2019
* @param array<array<string, mixed>> $configs
21-
* @throws Exception|\Doctrine\DBAL\Exception|TypesException
20+
*
21+
* @throws \Exception|\Doctrine\DBAL\Exception|TypesException
2222
*/
2323
public function load(array $configs, ContainerBuilder $container): void
2424
{
2525
$configuration = new Configuration();
26-
$config = $this->processConfiguration($configuration, $configs);
26+
$config = $this->processConfiguration($configuration, $configs);
2727

2828
// Set configuration into params
2929
$rootName = 'tmi_translation';
@@ -35,7 +35,7 @@ public function load(array $configs, ContainerBuilder $container): void
3535
Type::addType(TuuidType::NAME, TuuidType::class);
3636
}
3737

38-
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
38+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
3939
$loader->load('services.yaml');
4040
}
4141

@@ -45,12 +45,13 @@ public function prepend(ContainerBuilder $container): void
4545

4646
/**
4747
* Add config keys as parameters.
48+
*
4849
* @param array<string, mixed> $params
4950
*/
5051
private function setConfigAsParameters(ContainerBuilder $container, array $params, string $parent): void
5152
{
5253
foreach ($params as $key => $value) {
53-
$name = $parent . '.' . $key;
54+
$name = $parent.'.'.$key;
5455
$container->setParameter($name, $value);
5556

5657
if (is_array($value)) {

src/Doctrine/Attribute/EmptyOnTranslate.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace Tmi\TranslationBundle\Doctrine\Attribute;
66

7-
use Attribute;
8-
9-
#[Attribute(Attribute::TARGET_PROPERTY)]
7+
#[\Attribute(\Attribute::TARGET_PROPERTY)]
108
class EmptyOnTranslate
119
{
1210
}

src/Doctrine/Attribute/SharedAmongstTranslations.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace Tmi\TranslationBundle\Doctrine\Attribute;
66

7-
use Attribute;
8-
9-
#[Attribute(Attribute::TARGET_PROPERTY)]
7+
#[\Attribute(\Attribute::TARGET_PROPERTY)]
108
class SharedAmongstTranslations
119
{
1210
}

src/Doctrine/Filter/LocaleFilter.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use Doctrine\ORM\Query\Filter\SQLFilter;
99
use Tmi\TranslationBundle\Doctrine\Model\TranslatableInterface;
1010

11-
use function in_array;
12-
1311
/**
1412
* Filters translatable contents by the current locale.
1513
*/
@@ -20,7 +18,7 @@ final class LocaleFilter extends SQLFilter
2018
*/
2119
public function setLocale(string|null $locale): self
2220
{
23-
if ($locale !== null) {
21+
if (null !== $locale) {
2422
$this->setParameter('locale', $locale);
2523
}
2624

@@ -35,8 +33,8 @@ public function addFilterConstraint(ClassMetadata $targetEntity, string $targetT
3533

3634
$locale = $this->getParameter('locale');
3735

38-
if (in_array(TranslatableInterface::class, $targetEntity->getReflectionClass()?->getInterfaceNames(), true)) {
39-
return sprintf("%s.locale = %s", $targetTableAlias, $locale);
36+
if (\in_array(TranslatableInterface::class, $targetEntity->getReflectionClass()?->getInterfaceNames(), true)) {
37+
return sprintf('%s.locale = %s', $targetTableAlias, $locale);
4038
}
4139

4240
return '';

src/Doctrine/Model/TranslatableInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function getLocale(): string|null;
1717
public function setLocale(string|null $locale = null): self;
1818

1919
/**
20-
* Returns translations ids per locale
20+
* Returns translations ids per locale.
2121
*
2222
* @return array<string, string>
2323
*/

src/Doctrine/Model/TranslatableTrait.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Doctrine\DBAL\Types\Types;
88
use Doctrine\ORM\Mapping as ORM;
99
use Symfony\Component\Uid\Uuid;
10-
use Tmi\TranslationBundle\ValueObject\Tuuid;
1110
use Tmi\TranslationBundle\Doctrine\Attribute\SharedAmongstTranslations;
11+
use Tmi\TranslationBundle\ValueObject\Tuuid;
1212

1313
trait TranslatableTrait
1414
{
@@ -24,17 +24,18 @@ trait TranslatableTrait
2424

2525
final public function generateTuuid(): void
2626
{
27-
if ($this->tuuid === null) {
27+
if (null === $this->tuuid) {
2828
$this->tuuid = new Tuuid(Uuid::v4()->toRfc4122());
2929
}
3030
}
3131

3232
/**
33-
* Set the Translation UUID
33+
* Set the Translation UUID.
3434
*/
3535
final public function setTuuid(Tuuid|null $tuuid): self
3636
{
3737
$this->tuuid = $tuuid;
38+
3839
return $this;
3940
}
4041

@@ -89,8 +90,6 @@ final public function setTranslation(string $locale, array $translation): self
8990
return $this;
9091
}
9192

92-
/**
93-
*/
9493
final public function getTranslation(string $locale): array|null
9594
{
9695
return $this->translations[$locale] ?? null;

src/Doctrine/Type/TuuidType.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,42 @@
77
use Doctrine\DBAL\Platforms\AbstractPlatform;
88
use Doctrine\DBAL\Types\ConversionException;
99
use Doctrine\DBAL\Types\GuidType;
10-
use InvalidArgumentException;
1110
use Tmi\TranslationBundle\ValueObject\Tuuid;
1211

1312
final class TuuidType extends GuidType
1413
{
1514
public const string NAME = 'tuuid';
1615

17-
public function convertToPHPValue($value, AbstractPlatform $platform): ?Tuuid
16+
#[\Override]
17+
public function convertToPHPValue($value, AbstractPlatform $platform): Tuuid|null
1818
{
19-
if ($value === null) {
19+
if (null === $value) {
2020
return null;
2121
}
2222

2323
try {
2424
return new Tuuid($value);
25-
} catch (InvalidArgumentException $e) {
26-
throw new ConversionException(
27-
sprintf('Cannot convert "%s" to Tuuid', $value),
28-
0,
29-
$e
30-
);
25+
} catch (\InvalidArgumentException $e) {
26+
throw new ConversionException(sprintf('Cannot convert "%s" to Tuuid', $value), 0, $e);
3127
}
3228
}
3329

30+
#[\Override]
3431
public function convertToDatabaseValue($value, AbstractPlatform $platform): string|null
3532
{
36-
if ($value === null) {
33+
if (null === $value) {
3734
return null;
3835
}
3936

4037
if (!$value instanceof Tuuid) {
41-
throw new InvalidArgumentException('Value must be a Tuuid object.');
38+
throw new \InvalidArgumentException('Value must be a Tuuid object.');
4239
}
4340

44-
return (string)$value;
41+
return (string) $value;
4542
}
4643

4744
public function getName(): string
4845
{
4946
return self::NAME;
5047
}
51-
}
48+
}

src/Event/TranslateEvent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public function __construct(
2424
*/
2525
protected object $sourceEntity,
2626
/**
27-
* The target locale
27+
* The target locale.
2828
*/
2929
private readonly string $locale,
3030
/**
3131
* The translated entity.
3232
*/
33-
protected object|null $translatedEntity = null
33+
protected object|null $translatedEntity = null,
3434
) {
3535
}
3636

0 commit comments

Comments
 (0)