Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@
],
"psalm": [
"psalm.phar"
]
],
"rector": "vendor/bin/rector"
},
"conflict": {
"symfony/dependency-injection": "5.3.7",
Expand Down
79 changes: 51 additions & 28 deletions api/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,57 @@

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\CodeQuality\Rector\Catch_\ThrowWithPreviousExceptionRector;
use Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector;
use Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\If_\CombineIfRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
use Rector\Doctrine\Bundle230\Rector\Class_\AddAnnotationToRepositoryRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
use Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;

return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
// @noinspection PhpUnhandledExceptionInspection
return RectorConfig::configure()
->withPaths([
__DIR__.'/public',
__DIR__.'/config',
__DIR__.'/migrations',
__DIR__.'/src',
__DIR__.'/tests',
]);
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$parameters->set(Option::APPLY_AUTO_IMPORT_NAMES_ON_CHANGED_FILES_ONLY, true);

// Define what rule sets will be applied
$containerConfigurator->import(DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES);

// $containerConfigurator->import(SetList::DEAD_CODE);
// $containerConfigurator->import(SetList::CODE_QUALITY);
// $containerConfigurator->import(SetList::CODING_STYLE);
// $containerConfigurator->import(SetList::PHP_80);

// get services (needed for register a single rule)
// $services = $containerConfigurator->services();

// register a single rule
// $services->set(TypedPropertyRector::class);
};
])
->withComposerBased(doctrine: true, phpunit: true, symfony: true)
->withPreparedSets(deadCode: true, codeQuality: true, privatization: true, rectorPreset: true, phpunitCodeQuality: true, symfonyCodeQuality: true)
->withAttributesSets(all: true)
->withConfiguredRule(RenameFunctionRector::class, [
'implode' => 'join',
'join' => 'join',
])
->withSkip([
AddAnnotationToRepositoryRector::class,
AddInstanceofAssertForNullableInstanceRector::class,
AssertEmptyNullableObjectToAssertInstanceofRector::class,
CombineIfRector::class,
DeclareStrictTypesRector::class,
DisallowedEmptyRuleFixerRector::class,
ExplicitBoolCompareRector::class,
FinalizeTestCaseClassRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
LocallyCalledStaticMethodToNonStaticRector::class,
PreferPHPUnitThisCallRector::class,
RemoveDeadInstanceOfRector::class,
SimplifyIfElseToTernaryRector::class,
SimplifyIfReturnBoolRector::class,
ThrowWithPreviousExceptionRector::class,
UseIdenticalOverEqualWithSameTypeRector::class,
])
;
4 changes: 2 additions & 2 deletions api/src/Controller/CevidbController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CevidbController extends AbstractController {
* Link to this controller to start the "connect" process.
*/
#[Route('/auth/cevidb', name: 'connect_cevidb_start')]
public function connectAction(Request $request, ClientRegistry $clientRegistry) {
public function connect(Request $request, ClientRegistry $clientRegistry) {
return $clientRegistry
->getClient('cevidb') // key used in config/packages/knpu_oauth2_client.yaml
->redirect([], ['additionalData' => ['callback' => $request->get('callback')]])
Expand All @@ -25,7 +25,7 @@ public function connectAction(Request $request, ClientRegistry $clientRegistry)
* in config/packages/knpu_oauth2_client.yaml.
*/
#[Route('/auth/cevidb/callback', name: 'connect_cevidb_check')]
public function connectCheckAction(Request $request, ClientRegistry $clientRegistry) {
public function connectCheck(ClientRegistry $clientRegistry) {
// ** if you want to *authenticate* the user, then
// leave this method blank and create a custom authenticator
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/Controller/GoogleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GoogleController extends AbstractController {
* Link to this controller to start the "connect" process.
*/
#[Route('/auth/google', name: 'connect_google_start')]
public function connectAction(Request $request, ClientRegistry $clientRegistry) {
public function connect(Request $request, ClientRegistry $clientRegistry) {
return $clientRegistry
->getClient('google') // key used in config/packages/knpu_oauth2_client.yaml
->redirect([], ['additionalData' => ['callback' => $request->get('callback')]])
Expand All @@ -25,7 +25,7 @@ public function connectAction(Request $request, ClientRegistry $clientRegistry)
* in config/packages/knpu_oauth2_client.yaml.
*/
#[Route('/auth/google/callback', name: 'connect_google_check')]
public function connectCheckAction(Request $request, ClientRegistry $clientRegistry) {
public function connectCheck(ClientRegistry $clientRegistry) {
// ** if you want to *authenticate* the user, then
// leave this method blank and create a custom authenticator
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/Controller/JubladbController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class JubladbController extends AbstractController {
* Link to this controller to start the "connect" process.
*/
#[Route('/auth/jubladb', name: 'connect_jubladb_start')]
public function connectAction(Request $request, ClientRegistry $clientRegistry) {
public function connect(Request $request, ClientRegistry $clientRegistry) {
return $clientRegistry
->getClient('jubladb') // key used in config/packages/knpu_oauth2_client.yaml
->redirect([], ['additionalData' => ['callback' => $request->get('callback')]])
Expand All @@ -25,7 +25,7 @@ public function connectAction(Request $request, ClientRegistry $clientRegistry)
* in config/packages/knpu_oauth2_client.yaml.
*/
#[Route('/auth/jubladb/callback', name: 'connect_jubladb_check')]
public function connectCheckAction(Request $request, ClientRegistry $clientRegistry) {
public function connectCheck(ClientRegistry $clientRegistry) {
// ** if you want to *authenticate* the user, then
// leave this method blank and create a custom authenticator
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/Controller/PbsmidataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PbsmidataController extends AbstractController {
* Link to this controller to start the "connect" process.
*/
#[Route('/auth/pbsmidata', name: 'connect_pbsmidata_start')]
public function connectAction(Request $request, ClientRegistry $clientRegistry) {
public function connect(Request $request, ClientRegistry $clientRegistry) {
return $clientRegistry
->getClient('pbsmidata') // key used in config/packages/knpu_oauth2_client.yaml
->redirect([], ['additionalData' => ['callback' => $request->get('callback')]])
Expand All @@ -25,7 +25,7 @@ public function connectAction(Request $request, ClientRegistry $clientRegistry)
* in config/packages/knpu_oauth2_client.yaml.
*/
#[Route('/auth/pbsmidata/callback', name: 'connect_pbsmidata_check')]
public function connectCheckAction(Request $request, ClientRegistry $clientRegistry) {
public function connectCheck(ClientRegistry $clientRegistry) {
// ** if you want to *authenticate* the user, then
// leave this method blank and create a custom authenticator
}
Expand Down
7 changes: 2 additions & 5 deletions api/src/Doctrine/Filter/ContentNodeCampFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ public function __construct(

// This function is only used to hook in documentation generators (supported by Swagger and Hydra)
public function getDescription(string $resourceClass): array {
$description = [];
$description['camp'] = [
return ['camp' => [
'property' => self::CAMP_QUERY_NAME,
'type' => Type::BUILTIN_TYPE_STRING,
'required' => false,
];

return $description;
]];
}

protected function filterProperty(
Expand Down
7 changes: 2 additions & 5 deletions api/src/Doctrine/Filter/ContentNodeIsRootFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ public function __construct(

// This function is only used to hook in documentation generators (supported by Swagger and Hydra)
public function getDescription(string $resourceClass): array {
$description = [];
$description['isRoot'] = [
return ['isRoot' => [
'property' => self::IS_ROOT_QUERY_NAME,
'type' => Type::BUILTIN_TYPE_BOOL,
'required' => false,
];

return $description;
]];
}

protected function filterProperty(
Expand Down
7 changes: 2 additions & 5 deletions api/src/Doctrine/Filter/ContentNodePeriodFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@ public function __construct(

// This function is only used to hook in documentation generators (supported by Swagger and Hydra)
public function getDescription(string $resourceClass): array {
$description = [];
$description['period'] = [
return ['period' => [
'property' => self::PERIOD_QUERY_NAME,
'type' => Type::BUILTIN_TYPE_STRING,
'required' => false,
];

return $description;
]];
}

protected function filterProperty(
Expand Down
7 changes: 2 additions & 5 deletions api/src/Doctrine/Filter/MaterialItemPeriodFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ public function __construct(

// This function is only used to hook in documentation generators (supported by Swagger and Hydra)
public function getDescription(string $resourceClass): array {
$description = [];
$description['period'] = [
return ['period' => [
'property' => self::PERIOD_QUERY_NAME,
'type' => Type::BUILTIN_TYPE_STRING,
'required' => false,
];

return $description;
]];
}

protected function filterProperty(
Expand Down
3 changes: 1 addition & 2 deletions api/src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,8 @@ private function getAlphaNum($num): string {
if ($num >= 26) {
$alphaNum .= $this->getAlphaNum(floor($num / 26));
}
$alphaNum .= chr(97 + ($num % 26));

return $alphaNum;
return $alphaNum.chr(97 + ($num % 26));
}

private function getRomanNum($num): string {
Expand Down
2 changes: 1 addition & 1 deletion api/src/Entity/ChecklistItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function getSubtreeDepth(): int {
return 1 + $this->children->reduce(function (int $max, ChecklistItem $child): int {
$depth = $child->getSubtreeDepth();

return ($depth > $max) ? $depth : $max;
return max($depth, $max);
}, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/Entity/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public function removeMaterialItem(MaterialItem $materialItem): self {
* (based on start and end date).
*/
public function getPeriodLength(): ?int {
if (isset($this->start, $this->end)) {
if (null !== $this->start && null !== $this->end) {
$length = $this->end->getTimestamp() - $this->start->getTimestamp();

return intval(floor($length / 86400)) + 1;
Expand Down
2 changes: 1 addition & 1 deletion api/src/Metadata/Resource/Factory/UriTemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function getIdParameter(ResourceMetadataCollection $resourceMetadataCo
protected function getQueryParameters(string $resourceClass, ResourceMetadataCollection $resourceMetadataCollection): string {
$parameters = array_merge($this->getFilterParameters($resourceClass, $resourceMetadataCollection), $this->getPaginationParameters($resourceMetadataCollection));

return empty($parameters) ? '' : '{?'.implode(',', $parameters).'}';
return [] === $parameters ? '' : '{?'.join(',', $parameters).'}';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/src/OAuth/Hitobito.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function fetchResourceOwnerDetails(AccessToken $token): mixed {

$separator = $this->getScopeSeparator();
$headers = [
'X-Scope' => implode($separator, $this->getDefaultScopes()),
'X-Scope' => join($separator, $this->getDefaultScopes()),
];

$request = $this->getAuthenticatedRequest(self::METHOD_GET, $url, $token, ['headers' => $headers]);
Expand Down
2 changes: 1 addition & 1 deletion api/src/Serializer/Normalizer/ContentTypeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function supportsNormalization($data, $format = null, array $context = []
public function normalize($data, $format = null, array $context = []): null|array|\ArrayObject|bool|float|int|string {
$normalized_data = $this->decorated->normalize($data, $format, $context);

if ($data instanceof ContentType && isset($data->entityClass)) {
if ($data instanceof ContentType && null !== $data->entityClass) {
// get uri for the respective ContentNode entity and add ContentType as query parameter
[$uriTemplate, $templated] = $this->uriTemplateFactory->createFromResourceClass($data->entityClass);
$uri = $this->uriTemplate->expand($uriTemplate, ['contentType' => $this->iriConverter->getIriFromResource($data)]);
Expand Down
2 changes: 1 addition & 1 deletion api/src/State/ActivityCreateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function onBefore($data, Operation $operation, array $uriVariables = [],
if (!isset($data->category?->rootContentNode)) {
throw new \UnexpectedValueException('Property rootContentNode of provided category is null. Object of type '.ColumnLayout::class.' expected.');
}
if (!is_a($data->category->rootContentNode, ColumnLayout::class)) {
if (!$data->category->rootContentNode instanceof ColumnLayout) {
throw new \UnexpectedValueException('Property rootContentNode of provided category is of wrong type. Object of type '.ColumnLayout::class.' expected.');
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/State/CampCreateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function onBefore($data, Operation $operation, array $uriVariables = [],
$data->owner = $user;

// copy from prototype, if given
if (isset($data->campPrototype)) {
if (null !== $data->campPrototype) {
$entityMap = new EntityMap($data);
$data->copyFromPrototype($data->campPrototype, $entityMap);
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/State/PeriodPersistProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function removeExtraDays(Period $period) {
$days = $period->getDays();

foreach ($days as $day) {
if ($day->dayOffset < 0 or $day->dayOffset >= $length) {
if ($day->dayOffset < 0 || $day->dayOffset >= $length) {
$period->removeDay($day);
}
}
Expand Down
8 changes: 4 additions & 4 deletions api/src/State/ProfileUpdateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public function onBefore($data, Operation $operation, array $uriVariables = [],
$this->emailAddressVerificationPerformed = false;

/** @var Profile $data */
if (isset($data->newEmail)) {
if (null !== $data->newEmail) {
$verificationKey = IdGenerator::generateRandomHexString(64);
$data->untrustedEmail = $data->newEmail;
$data->untrustedEmailKey = $verificationKey;
$data->untrustedEmailKeyHash = $this->getResetKeyHasher()->hash($verificationKey);
} elseif (isset($data->untrustedEmailKey)) {
if (!isset($data->untrustedEmailKeyHash)) {
} elseif (null !== $data->untrustedEmailKey) {
if (null === $data->untrustedEmailKeyHash) {
throw new HttpException(422, 'Email verification failed A');
}

Expand All @@ -70,7 +70,7 @@ public function onBefore($data, Operation $operation, array $uriVariables = [],

public function onAfter($data, Operation $operation, array $uriVariables = [], array $context = []): void {
/** @var Profile $data */
if (isset($data->untrustedEmailKey)) {
if (null !== $data->untrustedEmailKey) {
$this->mailService->sendEmailVerificationMail($data->user, $data);
$data->untrustedEmailKey = null;
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/Validator/AssertBelongsToSameCampValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function validate($value, Constraint $constraint): void {
}

$object = $this->context->getObject();
if (!($object instanceof BelongsToCampInterface || $object instanceof BelongsToContentNodeTreeInterface)) {
if (!$object instanceof BelongsToCampInterface && !$object instanceof BelongsToContentNodeTreeInterface) {
throw new UnexpectedValueException($value, BelongsToCampInterface::class.' or '.BelongsToContentNodeTreeInterface::class);
}

if (!($value instanceof BelongsToCampInterface || $value instanceof BelongsToContentNodeTreeInterface)) {
if (!$value instanceof BelongsToCampInterface && !$value instanceof BelongsToContentNodeTreeInterface) {
throw new UnexpectedValueException($value, BelongsToCampInterface::class.' or '.BelongsToContentNodeTreeInterface::class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function validate($value, Constraint $constraint): void {
return;
}
$supportedSlotNames = $parent->getSupportedSlotNames();
if (0 === sizeof($supportedSlotNames)) {
if (0 === count($supportedSlotNames)) {
$this->context->buildViolation($constraint->parentDoesNotSupportChildrenMessage)->addViolation();

return;
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Api/Activities/CreateActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function testCreateActivityCopiesContentFromCategory() {
$response = static::createClientWithCredentials()->request('POST', '/activities', ['json' => $this->getExampleWritePayload()]);

$id = $response->toArray()['id'];
$newActivity = $this->getEntityManager()->getRepository(Activity::class)->find($id);
$this->getEntityManager()->getRepository(Activity::class)->find($id);

$this->assertResponseStatusCodeSame(201);
$this->assertJsonContains(['_embedded' => [
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Api/Activities/ListActivitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testListActivitiesAsCampSubresourceIsAllowedForCollaborator() {

public function testListActivitiesAsCampSubresourceIsDeniedForUnrelatedUser() {
$camp = static::getFixture('camp1');
$response = static::createClientWithCredentials(['email' => static::$fixtures['user4unrelated']->getEmail()])->request('GET', "/camps/{$camp->getId()}/activities");
static::createClientWithCredentials(['email' => static::$fixtures['user4unrelated']->getEmail()])->request('GET', "/camps/{$camp->getId()}/activities");
$this->assertResponseStatusCodeSame(404);
}

Expand Down
2 changes: 1 addition & 1 deletion api/tests/Api/Activities/ReadActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testGetSingleActivityIsAllowedForMember() {
]);

$data = $result->toArray();
$this->assertEquals(12, count($data['_embedded']['contentNodes']));
$this->assertCount(12, $data['_embedded']['contentNodes']);
}

public function testGetSingleActivityIsAllowedForManager() {
Expand Down
Loading
Loading