Skip to content

Commit 54c81ea

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 54c81ea

40 files changed

+145
-238
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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;
1617
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
1718
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector;
1819
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
@@ -34,6 +35,7 @@
3435
->withComposerBased(doctrine: true, phpunit: true, symfony: true)
3536
->withPreparedSets(deadCode: true, codeQuality: true, privatization: true, rectorPreset: true, phpunitCodeQuality: true, symfonyCodeQuality: true)
3637
->withAttributesSets(all: true)
38+
->withPhpSets(php80: true)
3739
->withConfiguredRule(RenameFunctionRector::class, [
3840
'implode' => 'join',
3941
'join' => 'join',
@@ -42,6 +44,7 @@
4244
AddAnnotationToRepositoryRector::class,
4345
AddInstanceofAssertForNullableInstanceRector::class,
4446
AssertEmptyNullableObjectToAssertInstanceofRector::class,
47+
ClosureToArrowFunctionRector::class,
4548
CombineIfRector::class,
4649
ConstraintOptionsToNamedArgumentsRector::class,
4750
DeclareStrictTypesRector::class,

api/src/DTO/Invitation.php

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -62,47 +62,37 @@ class Invitation {
6262
'swagger_definition_name' => 'read',
6363
];
6464

65-
#[ApiProperty(readable: false, writable: false, identifier: true, example: 'myInviteKey')]
66-
public string $inviteKey;
67-
68-
/**
69-
* The id of the camp for which this invitation is valid. This is useful for
70-
* redirecting the user to the correct place after they accept.
71-
*/
72-
#[ApiProperty(writable: false, example: '1a2b3c4d')]
73-
#[Groups('read')]
74-
public string $campId;
75-
76-
/**
77-
* The full title of the camp for which this invitation is valid. This should help
78-
* the user to decide whether to accept or reject the invitation.
79-
*/
80-
#[ApiProperty(writable: false, example: 'Abteilungs-Sommerlager 2022')]
81-
#[Groups('read')]
82-
public string $campTitle;
83-
84-
/**
85-
* The display name of the user that is invited. May be null in case the user does
86-
* not already have an account.
87-
*/
88-
#[ApiProperty(writable: false, example: 'Robert Baden-Powell')]
89-
#[Groups('read')]
90-
public ?string $userDisplayName;
91-
92-
/**
93-
* Indicates whether the logged in user is already collaborating in the camp, and
94-
* can therefore not accept the invitation.
95-
*/
96-
#[ApiProperty(writable: false, example: false)]
97-
#[Groups('read')]
98-
#[Assert\IsFalse(message: 'This user is already associated with the camp.', groups: ['accept'])]
99-
public ?bool $userAlreadyInCamp;
100-
101-
public function __construct(string $inviteKey, string $campId, string $campTitle, ?string $userDisplayName, ?bool $userAlreadyInCamp) {
102-
$this->inviteKey = $inviteKey;
103-
$this->campId = $campId;
104-
$this->campTitle = $campTitle;
105-
$this->userDisplayName = $userDisplayName;
106-
$this->userAlreadyInCamp = $userAlreadyInCamp;
107-
}
65+
public function __construct(
66+
#[ApiProperty(readable: false, writable: false, identifier: true, example: 'myInviteKey')]
67+
public string $inviteKey,
68+
/**
69+
* The id of the camp for which this invitation is valid. This is useful for
70+
* redirecting the user to the correct place after they accept.
71+
*/
72+
#[ApiProperty(writable: false, example: '1a2b3c4d')]
73+
#[Groups('read')]
74+
public string $campId,
75+
/**
76+
* The full title of the camp for which this invitation is valid. This should help
77+
* the user to decide whether to accept or reject the invitation.
78+
*/
79+
#[ApiProperty(writable: false, example: 'Abteilungs-Sommerlager 2022')]
80+
#[Groups('read')]
81+
public string $campTitle,
82+
/**
83+
* The display name of the user that is invited. May be null in case the user does
84+
* not already have an account.
85+
*/
86+
#[ApiProperty(writable: false, example: 'Robert Baden-Powell')]
87+
#[Groups('read')]
88+
public ?string $userDisplayName,
89+
/**
90+
* Indicates whether the logged in user is already collaborating in the camp, and
91+
* can therefore not accept the invitation.
92+
*/
93+
#[ApiProperty(writable: false, example: false)]
94+
#[Groups('read')]
95+
#[Assert\IsFalse(message: 'This user is already associated with the camp.', groups: ['accept'])]
96+
public ?bool $userAlreadyInCamp
97+
) {}
10898
}

api/src/DTO/PersonalInvitation.php

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,23 @@ class PersonalInvitation {
5757
'swagger_definition_name' => 'read',
5858
];
5959

60-
#[ApiProperty(readable: true, writable: false, identifier: true, example: '1a2b3c4d')]
61-
#[Groups('read')]
62-
public string $id;
63-
64-
/**
65-
* The id of the camp for which this invitation is valid. This is useful for
66-
* redirecting the user to the correct place after they accept.
67-
*/
68-
#[ApiProperty(writable: false, example: '1a2b3c4d')]
69-
#[Groups('read')]
70-
public string $campId;
71-
72-
/**
73-
* The full title of the camp for which this invitation is valid. This should help
74-
* the user to decide whether to accept or reject the invitation.
75-
*/
76-
#[ApiProperty(writable: false, example: 'Abteilungs-Sommerlager 2022')]
77-
#[Groups('read')]
78-
public string $campTitle;
79-
80-
public function __construct(string $id, string $campId, string $campTitle) {
81-
$this->id = $id;
82-
$this->campId = $campId;
83-
$this->campTitle = $campTitle;
84-
}
60+
public function __construct(
61+
#[ApiProperty(readable: true, writable: false, identifier: true, example: '1a2b3c4d')]
62+
#[Groups('read')]
63+
public string $id,
64+
/**
65+
* The id of the camp for which this invitation is valid. This is useful for
66+
* redirecting the user to the correct place after they accept.
67+
*/
68+
#[ApiProperty(writable: false, example: '1a2b3c4d')]
69+
#[Groups('read')]
70+
public string $campId,
71+
/**
72+
* The full title of the camp for which this invitation is valid. This should help
73+
* the user to decide whether to accept or reject the invitation.
74+
*/
75+
#[ApiProperty(writable: false, example: 'Abteilungs-Sommerlager 2022')]
76+
#[Groups('read')]
77+
public string $campTitle
78+
) {}
8579
}

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
/**

0 commit comments

Comments
 (0)