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
2 changes: 2 additions & 0 deletions Build/config/sites/main/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ languages:
flag: de
rootPageId: 1
websiteTitle: ''
imports:
- { resource: "EXT:sessionplaner/Configuration/Routes/Default.yaml" }
116 changes: 87 additions & 29 deletions Build/php-cs-fixer/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,100 @@
->exclude('var')
)
->setRules([
'@PSR2' => true,
'header_comment' => [
'header' => $header,
'@DoctrineAnnotation' => true,
// @todo: Switch to @PER-CS2x0 once php-cs-fixer's todo list is
// done: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7247
'@PER-CS1x0' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'cast_spaces' => ['space' => 'none'],
// @todo: Can be dropped once we enable @PER-CS2x0
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'declare_parentheses' => true,
'dir_constant' => true,
// @todo: Can be dropped once we enable @PER-CS2x0
'function_declaration' => [
'closure_fn_spacing' => 'none',
],
'general_phpdoc_annotation_remove' => [
'annotations' => [
'author',
],
'function_to_constant' => [
'functions' => [
'get_called_class',
'get_class',
'get_class_this',
'php_sapi_name',
'phpversion',
'pi',
]
],
'no_leading_import_slash' => true,
'no_trailing_comma_in_singleline' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_unused_imports' => true,
'concat_space' => ['spacing' => 'one'],
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'single_quote' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'no_blank_lines_after_phpdoc' => true,
'array_syntax' => ['syntax' => 'short'],
'whitespace_after_comma_in_array' => true,
'type_declaration_spaces' => true,
'single_line_comment_style' => true,
'global_namespace_import' => [
'import_classes' => false,
'import_constants' => false,
'import_functions' => false,
],
'list_syntax' => ['syntax' => 'short'],
// @todo: Can be dropped once we enable @PER-CS2x0
'method_argument_space' => true,
'modernize_strpos' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
'no_alias_functions' => true,
'lowercase_cast' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_namespace_whitespace' => true,
'native_function_casing' => true,
'self_accessor' => true,
'no_null_property_initialization' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline' => true,
'no_unneeded_control_parentheses' => true,
'trailing_comma_in_multiline' => [
'elements' => [
'arrays',
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_nullsafe_operator' => true,
'nullable_type_declaration' => [
'syntax' => 'question_mark',
],
'nullable_type_declaration_for_default_null_value' => true,
'ordered_class_elements' => ['order' => ['use_trait', 'case', 'constant', 'property']],
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
'php_unit_mock_short_will_return' => true,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self',
'methods' => [
'any' => 'this',
'atLeast' => 'this',
'atLeastOnce' => 'this',
'atMost' => 'this',
'exactly' => 'this',
'never' => 'this',
'onConsecutiveCalls' => 'this',
'once' => 'this',
'returnArgument' => 'this',
'returnCallback' => 'this',
'returnSelf' => 'this',
'returnValue' => 'this',
'returnValueMap' => 'this',
'throwException' => 'this',
],
],
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'protected_to_private' => true,
'return_type_declaration' => ['space_before' => 'none'],
'single_quote' => true,
'single_space_around_construct' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
// @todo: Can be dropped once we enable @PER-CS2x0
'single_line_empty_body' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
]);
3 changes: 2 additions & 1 deletion Classes/Constants.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

/*
* This file is part of the package evoweb/sessionplaner.
Expand Down
64 changes: 23 additions & 41 deletions Classes/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,28 @@
use Evoweb\Sessionplaner\Domain\Repository\SlotRepository;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Error\Result;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Validation\ValidatorResolver;

#[Autoconfigure(public: true)]
final class AjaxController
{
protected BackendUserAuthentication $backendUser;
protected ConfigurationManager $configurationManager;
protected SessionRepository $sessionRepository;
protected DayRepository $dayRepository;
protected RoomRepository $roomRepository;
protected SlotRepository $slotRepository;
protected PersistenceManager $persistenceManager;
private BackendUserAuthentication $backendUser;

public function __construct(
ConfigurationManager $configurationManager,
SessionRepository $sessionRepository,
DayRepository $dayRepository,
RoomRepository $roomRepository,
SlotRepository $slotRepository,
PersistenceManager $persistenceManager
private readonly ValidatorResolver $validatorResolver,
private readonly SessionRepository $sessionRepository,
private readonly DayRepository $dayRepository,
private readonly RoomRepository $roomRepository,
private readonly SlotRepository $slotRepository,
private readonly PersistenceManager $persistenceManager,
) {
$this->backendUser = $GLOBALS['BE_USER'];
$this->configurationManager = $configurationManager;
$this->sessionRepository = $sessionRepository;
$this->dayRepository = $dayRepository;
$this->roomRepository = $roomRepository;
$this->slotRepository = $slotRepository;
$this->persistenceManager = $persistenceManager;
}

public function updateSessionAction(ServerRequestInterface $request): ResponseInterface
Expand All @@ -66,7 +55,10 @@ public function updateSessionAction(ServerRequestInterface $request): ResponseIn
}

$data = $this->getParameter($request)['session'] ?? [];
$session = $this->sessionRepository->findAnyByUid((int)$data['uid']);
$uid = (int)($data['uid'] ?? 0);
unset($data['uid']);

$session = $this->sessionRepository->findAnyByUid($uid);
if ($session === null) {
return $this->renderResponse([
'status' => 'error',
Expand Down Expand Up @@ -94,31 +86,24 @@ public function updateSessionAction(ServerRequestInterface $request): ResponseIn
]);
}

protected function validateSession(Session $session): Result
private function validateSession(Session $session): Result
{
/** @var ValidatorResolver $validationResolver */
$validationResolver = GeneralUtility::makeInstance(ValidatorResolver::class);
$validator = $validationResolver->getBaseValidatorConjunction(Session::class);
return $validator->validate($session);
return $this->validatorResolver->getBaseValidatorConjunction(Session::class)->validate($session);
}

protected function updateSession(Session $session, array $data = []): void
private function updateSession(Session $session, array $data = []): void
{
unset($data['uid']);
foreach ($data as $field => $value) {
switch ($field) {
case 'room':
/** @var Room $room */
$room = $this->roomRepository->findByUid((int)$value);
$session->setRoom($room);
break;
case 'slot':
/** @var Slot $slot */
$slot = $this->slotRepository->findByUid((int)$value);
$session->setSlot($slot);
break;
case 'day':
/** @var Day $day */
$day = $this->dayRepository->findByUid((int)$value);
$session->setDay($day);
break;
Expand All @@ -132,26 +117,23 @@ protected function updateSession(Session $session, array $data = []): void
}
}

protected function hasAccess(): bool
private function hasAccess(): bool
{
if (!($this->backendUser->isAdmin() || $this->backendUser->check('modules', 'web_SessionplanerSessionplanerMain'))) {
return false;
}

return true;
return $this->backendUser->isAdmin()
|| $this->backendUser->check('modules', 'web_SessionplanerSessionplanerMain');
}

protected function getParameter(ServerRequestInterface $request): array
private function getParameter(ServerRequestInterface $request): array
{
try {
$payload = json_decode((string) $request->getBody(), true, 512, JSON_THROW_ON_ERROR);
$payload = json_decode((string)$request->getBody(), true, 512, JSON_THROW_ON_ERROR);
return is_array($payload) ? $payload : [];
} catch (\JsonException $exception) {
} catch (\JsonException) {
return [];
}
}

protected function renderResponse(array $data): ResponseInterface
private function renderResponse(array $data): ResponseInterface
{
return new JsonResponse(
[
Expand Down
Loading