Skip to content

Commit 6a23a92

Browse files
committed
chore(api): rector to php80
I know we started with php 8 with this version of the backend, but it seems we did not write php8 code. Disable ClosureToArrowFunctionRector for now because too much would change, and one can argue that it's a choice to use a closure instead of an arrow function.
1 parent 67fe4b3 commit 6a23a92

38 files changed

+97
-170
lines changed

api/config/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919

2020
$_SERVER += $_ENV;
2121
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
22-
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
22+
$_SERVER['APP_DEBUG'] ??= $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
2323
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';

api/rector.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Rector\Config\RectorConfig;
1414
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
1515
use Rector\Doctrine\Bundle230\Rector\Class_\AddAnnotationToRepositoryRector;
16+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
17+
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
1618
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
1719
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector;
1820
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
@@ -34,6 +36,7 @@
3436
->withComposerBased(doctrine: true, phpunit: true, symfony: true)
3537
->withPreparedSets(deadCode: true, codeQuality: true, privatization: true, rectorPreset: true, phpunitCodeQuality: true, symfonyCodeQuality: true)
3638
->withAttributesSets(all: true)
39+
->withPhpSets(php80: true)
3740
->withConfiguredRule(RenameFunctionRector::class, [
3841
'implode' => 'join',
3942
'join' => 'join',
@@ -42,6 +45,7 @@
4245
AddAnnotationToRepositoryRector::class,
4346
AddInstanceofAssertForNullableInstanceRector::class,
4447
AssertEmptyNullableObjectToAssertInstanceofRector::class,
48+
ClosureToArrowFunctionRector::class,
4549
CombineIfRector::class,
4650
ConstraintOptionsToNamedArgumentsRector::class,
4751
DeclareStrictTypesRector::class,
@@ -56,5 +60,8 @@
5660
SimplifyIfReturnBoolRector::class,
5761
ThrowWithPreviousExceptionRector::class,
5862
UseIdenticalOverEqualWithSameTypeRector::class,
63+
ClassPropertyAssignToConstructorPromotionRector::class => [
64+
__DIR__.'/src/DTO/*',
65+
],
5966
])
6067
;

api/src/Doctrine/Filter/ExpressionDateTimeFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected function addWhere(
134134
) {
135135
try {
136136
$value = new \DateTime($value);
137-
} catch (\Exception $e) {
137+
} catch (\Exception) {
138138
// Silently ignore this filter if it can not be transformed to a \DateTime
139139
$this->logger->notice('Invalid filter ignored', [
140140
'exception' => new InvalidArgumentException(sprintf('The field "%s" has a wrong date format. Use one accepted by the \DateTime constructor', $field)),

api/src/Doctrine/FilterByCurrentUserExtension.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
use Symfony\Bundle\SecurityBundle\Security;
1414

1515
final class FilterByCurrentUserExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface {
16-
private Security $security;
17-
private EntityManagerInterface $entityManager;
18-
19-
public function __construct(Security $security, EntityManagerInterface $entityManager) {
20-
$this->security = $security;
21-
$this->entityManager = $entityManager;
22-
}
16+
public function __construct(private Security $security, private EntityManagerInterface $entityManager) {}
2317

2418
public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, ?string $resourceClass = null, ?Operation $operation = null, array $context = []): void {
2519
$extraProperties = $operation->getExtraProperties();

api/src/Doctrine/Orm/Extension/FilterEagerLoadingsExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function buildAliasMap(EntityManagerInterface $em, ClassMetadata $classM
6262

6363
foreach ($joins as $join) {
6464
// @var Join $join
65-
list($fromAlias, $fromProperty) = explode('.', $join->getJoin(), 2);
65+
[$fromAlias, $fromProperty] = explode('.', $join->getJoin(), 2);
6666
$toAlias = $join->getAlias();
6767

6868
$fromClassMetadata = $aliasMap[$fromAlias][0];

api/src/Entity/Activity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class Activity extends BaseEntity implements BelongsToCampInterface {
144144
*/
145145
#[ApiProperty(example: '/activities/1a2b3c4d')]
146146
#[Groups(['create'])]
147-
public ?Activity $copyActivitySource;
147+
public ?Activity $copyActivitySource = null;
148148

149149
/**
150150
* The current assigned ProgressLabel.

api/src/Entity/Camp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class Camp extends BaseEntity implements BelongsToCampInterface, CopyFromPrototy
246246
#[ApiProperty(example: 'SoLa 2022')]
247247
#[Groups(['read', 'write'])]
248248
#[ORM\Column(type: 'text', nullable: true)]
249-
public ?string $shortTitle;
249+
public ?string $shortTitle = null;
250250

251251
/**
252252
* The full title of the camp. Used for identifying the camp in lists of camps, so

api/src/Entity/Category.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class Category extends BaseEntity implements BelongsToCampInterface, CopyFromPro
140140
*/
141141
#[ApiProperty(example: '/categories/1a2b3c4d')]
142142
#[Groups(['create'])]
143-
public Activity|Category|null $copyCategorySource;
143+
public Activity|Category|null $copyCategorySource = null;
144144

145145
/**
146146
* The id of the category that was used as a template for creating this category. Internal for now, is
@@ -257,25 +257,14 @@ public function removeActivity(Activity $activity): void {
257257
}
258258

259259
public function getStyledNumber(int $num): string {
260-
switch ($this->numberingStyle) {
261-
case 'a':
262-
return strtolower($this->getAlphaNum($num));
263-
264-
case 'A':
265-
return strtoupper($this->getAlphaNum($num));
266-
267-
case 'i':
268-
return strtolower($this->getRomanNum($num));
269-
270-
case 'I':
271-
return strtoupper($this->getRomanNum($num));
272-
273-
case '-':
274-
return '';
275-
276-
default:
277-
return strval($num);
278-
}
260+
return match ($this->numberingStyle) {
261+
'a' => strtolower($this->getAlphaNum($num)),
262+
'A' => strtoupper($this->getAlphaNum($num)),
263+
'i' => strtolower($this->getRomanNum($num)),
264+
'I' => strtoupper($this->getRomanNum($num)),
265+
'-' => '',
266+
default => strval($num),
267+
};
279268
}
280269

281270
/**

api/src/Entity/Checklist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Checklist extends BaseEntity implements BelongsToCampInterface, CopyFromPr
9696
*/
9797
#[ApiProperty(example: '/checklists/1a2b3c4d')]
9898
#[Groups(['create'])]
99-
public ?Checklist $copyChecklistSource;
99+
public ?Checklist $copyChecklistSource = null;
100100

101101
/**
102102
* All ChecklistItems that belong to this Checklist.

api/src/Entity/Day.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function getStart(): ?\DateTime {
157157
$start?->add(new \DateInterval('P'.$this->dayOffset.'D'));
158158

159159
return $start;
160-
} catch (\Exception $e) {
160+
} catch (\Exception) {
161161
return null;
162162
}
163163
}
@@ -173,7 +173,7 @@ public function getEnd(): ?\DateTime {
173173
$end?->add(new \DateInterval('P'.($this->dayOffset + 1).'D'));
174174

175175
return $end;
176-
} catch (\Exception $e) {
176+
} catch (\Exception) {
177177
return null;
178178
}
179179
}

0 commit comments

Comments
 (0)