Skip to content

Commit 1177059

Browse files
authored
Merge pull request #55 from evoWeb/feature/cleanup-and-improvements
Feature/cleanup and improvements
2 parents 4784919 + 8f0448a commit 1177059

80 files changed

Lines changed: 694 additions & 1090 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Build/config/sites/main/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ languages:
2424
flag: de
2525
rootPageId: 1
2626
websiteTitle: ''
27+
imports:
28+
- { resource: "EXT:sessionplaner/Configuration/Routes/Default.yaml" }

Build/php-cs-fixer/config.php

Lines changed: 87 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,42 +40,100 @@
4040
->exclude('var')
4141
)
4242
->setRules([
43-
'@PSR2' => true,
44-
'header_comment' => [
45-
'header' => $header,
43+
'@DoctrineAnnotation' => true,
44+
// @todo: Switch to @PER-CS2x0 once php-cs-fixer's todo list is
45+
// done: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7247
46+
'@PER-CS1x0' => true,
47+
'array_indentation' => true,
48+
'array_syntax' => ['syntax' => 'short'],
49+
'cast_spaces' => ['space' => 'none'],
50+
// @todo: Can be dropped once we enable @PER-CS2x0
51+
'concat_space' => ['spacing' => 'one'],
52+
'declare_equal_normalize' => ['space' => 'none'],
53+
'declare_parentheses' => true,
54+
'dir_constant' => true,
55+
// @todo: Can be dropped once we enable @PER-CS2x0
56+
'function_declaration' => [
57+
'closure_fn_spacing' => 'none',
4658
],
47-
'general_phpdoc_annotation_remove' => [
48-
'annotations' => [
49-
'author',
50-
],
59+
'function_to_constant' => [
60+
'functions' => [
61+
'get_called_class',
62+
'get_class',
63+
'get_class_this',
64+
'php_sapi_name',
65+
'phpversion',
66+
'pi',
67+
]
5168
],
52-
'no_leading_import_slash' => true,
53-
'no_trailing_comma_in_singleline' => true,
54-
'no_singleline_whitespace_before_semicolons' => true,
55-
'no_unused_imports' => true,
56-
'concat_space' => ['spacing' => 'one'],
57-
'no_whitespace_in_blank_line' => true,
58-
'ordered_imports' => true,
59-
'single_quote' => true,
60-
'no_empty_statement' => true,
61-
'no_extra_blank_lines' => true,
62-
'phpdoc_no_package' => true,
63-
'phpdoc_scalar' => true,
64-
'no_blank_lines_after_phpdoc' => true,
65-
'array_syntax' => ['syntax' => 'short'],
66-
'whitespace_after_comma_in_array' => true,
6769
'type_declaration_spaces' => true,
68-
'single_line_comment_style' => true,
70+
'global_namespace_import' => [
71+
'import_classes' => false,
72+
'import_constants' => false,
73+
'import_functions' => false,
74+
],
75+
'list_syntax' => ['syntax' => 'short'],
76+
// @todo: Can be dropped once we enable @PER-CS2x0
77+
'method_argument_space' => true,
78+
'modernize_strpos' => true,
79+
'modernize_types_casting' => true,
80+
'native_function_casing' => true,
6981
'no_alias_functions' => true,
70-
'lowercase_cast' => true,
82+
'no_blank_lines_after_phpdoc' => true,
83+
'no_empty_phpdoc' => true,
84+
'no_empty_statement' => true,
85+
'no_extra_blank_lines' => true,
7186
'no_leading_namespace_whitespace' => true,
72-
'native_function_casing' => true,
73-
'self_accessor' => true,
87+
'no_null_property_initialization' => true,
7488
'no_short_bool_cast' => true,
89+
'no_singleline_whitespace_before_semicolons' => true,
90+
'no_superfluous_elseif' => true,
91+
'no_trailing_comma_in_singleline' => true,
7592
'no_unneeded_control_parentheses' => true,
76-
'trailing_comma_in_multiline' => [
77-
'elements' => [
78-
'arrays',
93+
'no_unused_imports' => true,
94+
'no_useless_else' => true,
95+
'no_useless_nullsafe_operator' => true,
96+
'nullable_type_declaration' => [
97+
'syntax' => 'question_mark',
98+
],
99+
'nullable_type_declaration_for_default_null_value' => true,
100+
'ordered_class_elements' => ['order' => ['use_trait', 'case', 'constant', 'property']],
101+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
102+
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
103+
'php_unit_mock_short_will_return' => true,
104+
'php_unit_test_case_static_method_calls' => ['call_type' => 'self',
105+
'methods' => [
106+
'any' => 'this',
107+
'atLeast' => 'this',
108+
'atLeastOnce' => 'this',
109+
'atMost' => 'this',
110+
'exactly' => 'this',
111+
'never' => 'this',
112+
'onConsecutiveCalls' => 'this',
113+
'once' => 'this',
114+
'returnArgument' => 'this',
115+
'returnCallback' => 'this',
116+
'returnSelf' => 'this',
117+
'returnValue' => 'this',
118+
'returnValueMap' => 'this',
119+
'throwException' => 'this',
79120
],
80121
],
122+
'phpdoc_no_access' => true,
123+
'phpdoc_no_empty_return' => true,
124+
'phpdoc_no_package' => true,
125+
'phpdoc_scalar' => true,
126+
'phpdoc_trim' => true,
127+
'phpdoc_types' => true,
128+
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
129+
'protected_to_private' => true,
130+
'return_type_declaration' => ['space_before' => 'none'],
131+
'single_quote' => true,
132+
'single_space_around_construct' => true,
133+
'single_line_comment_style' => ['comment_types' => ['hash']],
134+
// @todo: Can be dropped once we enable @PER-CS2x0
135+
'single_line_empty_body' => true,
136+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
137+
'whitespace_after_comma_in_array' => ['ensure_single_space' => true],
138+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
81139
]);

Classes/Constants.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
declare(strict_types = 1);
2+
3+
declare(strict_types=1);
34

45
/*
56
* This file is part of the package evoweb/sessionplaner.

Classes/Controller/AjaxController.php

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,28 @@
2121
use Evoweb\Sessionplaner\Domain\Repository\SlotRepository;
2222
use Psr\Http\Message\ResponseInterface;
2323
use Psr\Http\Message\ServerRequestInterface;
24+
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
2425
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
2526
use TYPO3\CMS\Core\Http\JsonResponse;
2627
use TYPO3\CMS\Core\Utility\GeneralUtility;
27-
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
2828
use TYPO3\CMS\Extbase\Error\Result;
2929
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
3030
use TYPO3\CMS\Extbase\Validation\ValidatorResolver;
3131

32+
#[Autoconfigure(public: true)]
3233
final class AjaxController
3334
{
34-
protected BackendUserAuthentication $backendUser;
35-
protected ConfigurationManager $configurationManager;
36-
protected SessionRepository $sessionRepository;
37-
protected DayRepository $dayRepository;
38-
protected RoomRepository $roomRepository;
39-
protected SlotRepository $slotRepository;
40-
protected PersistenceManager $persistenceManager;
35+
private BackendUserAuthentication $backendUser;
4136

4237
public function __construct(
43-
ConfigurationManager $configurationManager,
44-
SessionRepository $sessionRepository,
45-
DayRepository $dayRepository,
46-
RoomRepository $roomRepository,
47-
SlotRepository $slotRepository,
48-
PersistenceManager $persistenceManager
38+
private readonly ValidatorResolver $validatorResolver,
39+
private readonly SessionRepository $sessionRepository,
40+
private readonly DayRepository $dayRepository,
41+
private readonly RoomRepository $roomRepository,
42+
private readonly SlotRepository $slotRepository,
43+
private readonly PersistenceManager $persistenceManager,
4944
) {
5045
$this->backendUser = $GLOBALS['BE_USER'];
51-
$this->configurationManager = $configurationManager;
52-
$this->sessionRepository = $sessionRepository;
53-
$this->dayRepository = $dayRepository;
54-
$this->roomRepository = $roomRepository;
55-
$this->slotRepository = $slotRepository;
56-
$this->persistenceManager = $persistenceManager;
5746
}
5847

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

6857
$data = $this->getParameter($request)['session'] ?? [];
69-
$session = $this->sessionRepository->findAnyByUid((int)$data['uid']);
58+
$uid = (int)($data['uid'] ?? 0);
59+
unset($data['uid']);
60+
61+
$session = $this->sessionRepository->findAnyByUid($uid);
7062
if ($session === null) {
7163
return $this->renderResponse([
7264
'status' => 'error',
@@ -94,31 +86,24 @@ public function updateSessionAction(ServerRequestInterface $request): ResponseIn
9486
]);
9587
}
9688

97-
protected function validateSession(Session $session): Result
89+
private function validateSession(Session $session): Result
9890
{
99-
/** @var ValidatorResolver $validationResolver */
100-
$validationResolver = GeneralUtility::makeInstance(ValidatorResolver::class);
101-
$validator = $validationResolver->getBaseValidatorConjunction(Session::class);
102-
return $validator->validate($session);
91+
return $this->validatorResolver->getBaseValidatorConjunction(Session::class)->validate($session);
10392
}
10493

105-
protected function updateSession(Session $session, array $data = []): void
94+
private function updateSession(Session $session, array $data = []): void
10695
{
107-
unset($data['uid']);
10896
foreach ($data as $field => $value) {
10997
switch ($field) {
11098
case 'room':
111-
/** @var Room $room */
11299
$room = $this->roomRepository->findByUid((int)$value);
113100
$session->setRoom($room);
114101
break;
115102
case 'slot':
116-
/** @var Slot $slot */
117103
$slot = $this->slotRepository->findByUid((int)$value);
118104
$session->setSlot($slot);
119105
break;
120106
case 'day':
121-
/** @var Day $day */
122107
$day = $this->dayRepository->findByUid((int)$value);
123108
$session->setDay($day);
124109
break;
@@ -132,26 +117,23 @@ protected function updateSession(Session $session, array $data = []): void
132117
}
133118
}
134119

135-
protected function hasAccess(): bool
120+
private function hasAccess(): bool
136121
{
137-
if (!($this->backendUser->isAdmin() || $this->backendUser->check('modules', 'web_SessionplanerSessionplanerMain'))) {
138-
return false;
139-
}
140-
141-
return true;
122+
return $this->backendUser->isAdmin()
123+
|| $this->backendUser->check('modules', 'web_SessionplanerSessionplanerMain');
142124
}
143125

144-
protected function getParameter(ServerRequestInterface $request): array
126+
private function getParameter(ServerRequestInterface $request): array
145127
{
146128
try {
147-
$payload = json_decode((string) $request->getBody(), true, 512, JSON_THROW_ON_ERROR);
129+
$payload = json_decode((string)$request->getBody(), true, 512, JSON_THROW_ON_ERROR);
148130
return is_array($payload) ? $payload : [];
149-
} catch (\JsonException $exception) {
131+
} catch (\JsonException) {
150132
return [];
151133
}
152134
}
153135

154-
protected function renderResponse(array $data): ResponseInterface
136+
private function renderResponse(array $data): ResponseInterface
155137
{
156138
return new JsonResponse(
157139
[

0 commit comments

Comments
 (0)