Skip to content

Commit

Permalink
refactor: fix coding standards after upgrade to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
twojtylak committed Jun 16, 2023
1 parent 6f2127c commit 323e1d8
Show file tree
Hide file tree
Showing 36 changed files with 84 additions and 21 deletions.
1 change: 1 addition & 0 deletions Classes/Command/Traits/AsIsResourceDataCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function withAsIsResourceData(?array $asIsResourceData): AsIsResourceData
{
$target = clone $this;
$target->asIsResourceData = $asIsResourceData;

return $target;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function withIncludedResourcesData(array $includedResourceData): Included
{
$target = clone $this;
$target->includedResourcesData = $includedResourceData;

return $target;
}
}
1 change: 1 addition & 0 deletions Classes/Command/Traits/ResourceDataCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function withResourceData(array $resourceData): ResourceDataCommand
{
$target = clone $this;
$target->resourceData = $resourceData;

return $target;
}
}
1 change: 1 addition & 0 deletions Classes/Command/Traits/ResourceRelationsCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function withResourceRelations(array $resourceRelations): ResourceRelatio
{
$target = clone $this;
$target->resourceRelations = $resourceRelations;

return $target;
}
}
1 change: 1 addition & 0 deletions Classes/Command/Traits/TcaRecordDataCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function withRecordData(array $recordData): TcaRecordDataCommand
{
$target = clone $this;
$target->recordData = $recordData;

return $target;
}
}
1 change: 1 addition & 0 deletions Classes/CommandBus/CommandBusFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static function createFromCommandConfiguration(): CommandBus
if (\is_array($target) && isset($target['__class__'])) {
$constructorArgs = $target;
unset($constructorArgs['__class__']);

return (new Cascader())->create($target['__class__'], $constructorArgs);
}

Expand Down
1 change: 1 addition & 0 deletions Classes/CommandBus/CommandHandlerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function get($id)
if (!$this->commandHandlers[$id]) {
throw new CommandHandlerNotFoundException('The command handler "' . $id . '" could not be found.', 1564490855);
}

return $this->commandHandlers[$id];
}

Expand Down
1 change: 1 addition & 0 deletions Classes/Configuration/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function getConfigurationFromPackages(string $configType): array
if (\file_exists($resourcesFileNameForPackage)) {
return require $resourcesFileNameForPackage;
}

return [];
}, \array_values($packages)));

Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/JsonApiCollectionCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function canHandleOperation(Operation $operation): bool
{
return $operation->equals(Operation::READ);
// TODO implement creation on collection without given identifier
// || $operation->equals(Operation::CREATE);
// || $operation->equals(Operation::CREATE);
}

public function read(ServerRequestInterface $request): ResponseInterface
Expand Down
10 changes: 5 additions & 5 deletions Classes/Controller/JsonApiItemCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function getMandatoryFields(): array

public function canHandleOperation(Operation $operation): bool
{
return $operation->equals(Operation::READ)
|| $operation->equals(Operation::CREATE)
|| $operation->equals(Operation::REPLACE)
|| $operation->equals(Operation::UPDATE)
|| $operation->equals(Operation::DELETE);
return $operation->equals(Operation::READ) ||
$operation->equals(Operation::CREATE) ||
$operation->equals(Operation::REPLACE) ||
$operation->equals(Operation::UPDATE) ||
$operation->equals(Operation::DELETE);
}

public function read(ServerRequestInterface $request): ResponseInterface
Expand Down
3 changes: 3 additions & 0 deletions Classes/Controller/ResourceControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public static function createFromRouteDefintinion(string $routeIdentifier, array
switch ($routeDefinition['numerus']) {
case Numerus::ITEM:
$controllerName = JsonApiItemCommandController::class;

break;
case Numerus::COLLECTION:
$controllerName = JsonApiCollectionCommandController::class;

break;
default:
throw new \InvalidArgumentException('The resource route "' . $routeIdentifier . '" does contain an invalid "numerus" definition "' . $routeDefinition['numerus'] . '" of type "' . Numerus::class . '".', 1562676282);
Expand All @@ -57,6 +59,7 @@ public static function createFromRouteDefintinion(string $routeIdentifier, array

/** @var AbstractResourceCommandController $controller */
$controller = (new Cascader())->create($controllerName, $controllerOptions);

return $controller;
}
}
2 changes: 1 addition & 1 deletion Classes/Database/Query/Restriction/SiteRestriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SiteRestriction implements QueryRestrictionInterface
/** @var QueryGenerator */
private $queryGenerator;

/** @var null|int[] */
/** @var int[]|null */
private $cachedSitePids;

public function __construct(QueryGenerator $queryGenerator)
Expand Down
1 change: 1 addition & 0 deletions Classes/Deserializer/JsonApiDeserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function collection(array $data, int $options = 0): array
return $this->item(['data' => $data], $options);
}, $data['data']));
}

return [];
}

Expand Down
1 change: 1 addition & 0 deletions Classes/Domain/Command/UnitOfWorkTcaResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function withUnitOfWorkCommands(array $unitOfWorkCommands): UnitOfWorkCom
$target->unitOfWorkCommands = \array_map(function (TcaRecordReferencingCommand $command) {
return $command;
}, $unitOfWorkCommands);

return $target;
}
}
4 changes: 4 additions & 0 deletions Classes/Domain/CommandHandler/ConvergenceCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ public function handleReplaceTcaResourceCommand(ReplaceTcaResourceCommand $repla
case $operation instanceof AddResource:
[$commandName, $commandArguments] = $this->resourceOperationToCommandMap->getCommandConfigForResourceTypeAndOperation($resource['type'], $convergenceOperationsToApiOperationsMap[AddResource::class]);
$commandArguments['resourceData'] = $resource['attributes'];

break;
case $operation instanceof UpdateResource:
[$commandName, $commandArguments] = $this->resourceOperationToCommandMap->getCommandConfigForResourceTypeAndOperation($resource['type'], $convergenceOperationsToApiOperationsMap[UpdateResource::class]);
$commandArguments['resourceData'] = $operation->getResourceUpdates()['attributes'];

break;
case $operation instanceof RemoveResource:
[$commandName, $commandArguments] = $this->resourceOperationToCommandMap->getCommandConfigForResourceTypeAndOperation($resource['type'], $convergenceOperationsToApiOperationsMap[RemoveResource::class]);
$commandArguments['resourceData'] = $resource['attributes'];

break;
default:
throw new \BadMethodCallException('The given operation "' . \get_class($operation) . '" is not supported yet', 1564062825);
Expand Down Expand Up @@ -96,6 +99,7 @@ protected function getSchemaForResourceType(string $resourceType): Schema

/** @var Schema $schema */
$schema = $this->objectFactory->create($schemaClassName, $schemaArguments);

return $schema;
}
}
3 changes: 3 additions & 0 deletions Classes/Domain/CommandHandler/DataHandlerCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ protected function addCommandToDataOrCommandMap(TcaRecordReferencingCommand $com
case $command instanceof CreateTcaResourceCommand:
case $command instanceof UpdateTcaResourceCommand:
$datamap[$command->getTableName()][$command->getUid()] = $command->getRecordData();

break;
case $command instanceof DeleteTcaResourceCommand:
$commandmap[$command->getTableName()][$command->getUid()]['delete'] = 1;

break;
default:
throw new \BadMethodCallException('The given command "' . \get_class($command) . '" is not supported yet', 1564476754);
Expand Down Expand Up @@ -100,6 +102,7 @@ protected function process(array $datamap = [], array $commandmap = []): array
if (!empty($this->dataHandler->errorLog)) {
throw new DataHandlerCommandException($this->dataHandler->errorLog);
}

return $this->dataHandler->substNEWwithIDs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function addFiltersToQuery(array $filters, QueryBuilder $queryBuilder): Q
foreach ($filters as $key => $value) {
if (!\is_array($value)) {
$constraints[] = $queryBuilder->expr()->in($key, $queryBuilder->createNamedParameter($value));

continue;
}

Expand All @@ -71,6 +72,7 @@ public function addFiltersToQuery(array $filters, QueryBuilder $queryBuilder): Q
}

$queryBuilder->andWhere(...$constraints);

return $queryBuilder;
}

Expand Down Expand Up @@ -147,6 +149,7 @@ public function findByPageIdentifier($pageIdentifier): array
protected function createDeduplicator(): \Closure
{
$countPerId = [];

return function (array $resource) use (&$countPerId): array {
$identifier = $resource[$this->identifier];
$countPerId[$identifier] = isset($countPerId[$identifier]) ? $countPerId[$identifier] + 1 : 0;
Expand All @@ -162,6 +165,7 @@ protected function createDeduplicator(): \Closure
protected function createMetaMapper(): \Closure
{
$tableName = $this->tableName;

return function (array $resource) use ($tableName): array {
$resource[static::META_ATTRIBUTE] = [
static::META_UID => $resource[static::DEFAULT_IDENTIFIER],
Expand All @@ -188,6 +192,7 @@ protected function createOverlayMapper(?Context $context): \Closure
);
$overlayResult = $pageRepository->getLanguageOverlay($this->tableName, $resource);
}

return $overlayResult ?? $resource;
};
}
Expand Down
1 change: 1 addition & 0 deletions Classes/Domain/Repository/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function findOneByIdentifier($identifier, $context = null): ?array

if ($file) {
$fileProperties = $file->toArray();

return $this->createMetaMapper()($fileProperties);
}

Expand Down
3 changes: 2 additions & 1 deletion Classes/Domain/Repository/TcaResourceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ protected function createQuery(): QueryBuilder
{
$queryBuilder = parent::createQuery();
foreach ($this->orderBy as $orderPair) {
list($fieldName, $order) = $orderPair;
[$fieldName, $order] = $orderPair;
$queryBuilder->addOrderBy($fieldName, $order);
}

return $queryBuilder;
}
}
1 change: 1 addition & 0 deletions Classes/Domain/Transformer/FileReferenceTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function transform(array $fileReference): array
} catch (\InvalidArgumentException $exception) {
$file = null;
}

return [
'id' => (string) $fileReference[$this->identifier],
'meta' => $fileReference[FileReferenceRepository::META_ATTRIBUTE],
Expand Down
4 changes: 3 additions & 1 deletion Classes/ErrorFormatter/JsonApiFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ protected function serializeError(Throwable $error)
'message' => $error->getMessage(),
];

if (($previous = $error->getPrevious()) !== null) {
$previous = $error->getPrevious();

if (null !== $previous) {
$data['previous'] = $this->serializeError($previous);
}

Expand Down
9 changes: 5 additions & 4 deletions Classes/Form/DatabaseRowDateTimeFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ public function addData(array $result)
$dateTimeFormats = QueryHelper::getDateTimeFormats();

foreach ($result['processedTca']['columns'] as $column => $columnConfig) {
if (isset($columnConfig['config']['dbType'])
&& \in_array($columnConfig['config']['dbType'], $dateTimeTypes, true)
if (isset($columnConfig['config']['dbType']) &&
\in_array($columnConfig['config']['dbType'], $dateTimeTypes, true)
) {
if (!empty($result['databaseRow'][$column])
&& $result['databaseRow'][$column] !== $dateTimeFormats[$columnConfig['config']['dbType']]['empty']
if (!empty($result['databaseRow'][$column]) &&
$result['databaseRow'][$column] !== $dateTimeFormats[$columnConfig['config']['dbType']]['empty']
) {
$result['databaseRow'][$column] = \date($dateTimeFormats[$columnConfig['config']['dbType']]['format'], \strtotime($result['databaseRow'][$column] . ' UTC'));
} else {
$result['databaseRow'][$column] = null;
}
}
}

return $result;
}
}
5 changes: 4 additions & 1 deletion Classes/Http/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RequestHandler implements RequestHandlerInterface
public function handle(ServerRequestInterface $request): ResponseInterface
{
$handler = $this->getCallableFromHandler($request->getAttribute('handler'));

return \call_user_func_array($handler, [$request]);
}

Expand Down Expand Up @@ -48,13 +49,15 @@ protected function getCallableFromHandler($target)
if (!\method_exists($targetObject, '__invoke')) {
throw new \InvalidArgumentException('Object "' . $target . '" doesn\'t implement an __invoke() method and cannot be used as target.', 1442431631);
}

return $targetObject;
}

// Check if the target is a concatenated string of "className::actionMethod"
if (\is_string($target) && false !== \strpos($target, '::')) {
list($className, $methodName) = \explode('::', $target, 2);
[$className, $methodName] = \explode('::', $target, 2);
$targetObject = GeneralUtility::makeInstance($className);

return [$targetObject, $methodName];
}

Expand Down
2 changes: 2 additions & 0 deletions Classes/IncludeHandler/PageRelationIncludeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public function __construct(array $includeToResourceMap = [])
if (isset($allResourceDefinitions[$resourceType])) {
$resourceDefinition = $allResourceDefinitions[$resourceType];
$resourceDefinition['resourceType'] = $resourceType;

return $resourceDefinition;
}

return null;
}, $includeToResourceMap));
}
Expand Down
9 changes: 8 additions & 1 deletion Classes/IncludeHandler/TcaResourceIncludeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ public function handleInclude(Scope $scope, string $includeName, $data, callable
$transformer = $cascader->create($resourceDefinition['transformer'][Cascader::ARGUMENT_CLASS], $resourceDefinition['transformer']);

if (Item::class === $resourceType) {
if ($data = $repository->findOneByIdentifier(\reset($result)['id'])) {
$data = $repository->findOneByIdentifier(\reset($result)['id']);
if ($data) {
return new $resourceType(
$data,
$transformer,
$resourceDefinition['resourceType']
);
}

return null;
}

Expand All @@ -120,11 +122,13 @@ protected function buildTcaIncludes($tableName): array
if (!empty($columnConfig['foreign_table'])) {
return \array_merge($columnConfig, [static::REFERENCE_TABLE_NAME => [$columnConfig['foreign_table']]]);
}

break;
case 'group':
if ('db' === $columnConfig['internal_type'] && !empty($columnConfig['allowed']) && false === \strpos($columnConfig['allowed'], ',')) {
return \array_merge($columnConfig, [static::REFERENCE_TABLE_NAME => GeneralUtility::trimExplode(',', $columnConfig['allowed'], true)]);
}

break;
}
}
Expand All @@ -136,12 +140,15 @@ protected function buildTcaIncludes($tableName): array
protected function buildResourceDefinitions(array $tableNameToResourceMap): array
{
$allResourceDefinitions = ConfigurationManager::getResourcesConfiguration();

return \array_filter(\array_map(function (string $resourceType) use ($allResourceDefinitions): ?array {
if (isset($allResourceDefinitions[$resourceType])) {
$resourceDefinition = $allResourceDefinitions[$resourceType];
$resourceDefinition['resourceType'] = $resourceType;

return $resourceDefinition;
}

return null;
}, $tableNameToResourceMap));
}
Expand Down
1 change: 1 addition & 0 deletions Classes/Middleware/ApiEntrypoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
if (!empty($apiPathPrefix) && \str_starts_with($request->getUri()->getPath(), '/' . $apiPathPrefix)) {
$request = $request->withUri($request->getUri()->withPath('/' . \substr($request->getUri()->getPath(), \strlen('/' . $apiPathPrefix))));
$middlewareDispatcher = $this->createMiddlewareDispatcher();

return $middlewareDispatcher->handle($request);
}

Expand Down
1 change: 1 addition & 0 deletions Classes/Middleware/CheckBeUserAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
if (!$tsfe->isBackendUserLoggedIn()) {
return new Response('php://temp', '401');
}

return $handler->handle($request);
}

Expand Down
2 changes: 2 additions & 0 deletions Classes/Middleware/LanguageResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct(Context $context)
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$request = $this->getLanguageAwareRequest($request);

return $handler->handle($request);
}

Expand All @@ -49,6 +50,7 @@ protected function getLanguageAwareRequest(ServerRequestInterface $request): Ser

if (\in_array($acceptLanguage, $languageKeys, true)) {
$usedSiteLanguage = $language;

break;
}
}
Expand Down
Loading

0 comments on commit 323e1d8

Please sign in to comment.