Skip to content

Commit bcee624

Browse files
[TASK] fix / suppress phpmd violations
Relates: https://projekte.in2code.de/issues/74304
1 parent c07f65f commit bcee624

6 files changed

Lines changed: 56 additions & 25 deletions

File tree

.phpmd.xml

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,33 @@
55
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
66
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
77
>
8-
<description>
9-
Adapted the phpmd default config.
10-
* Import all rule sets
11-
* Allow variables as long as 25 chars
12-
</description>
8+
<description>
9+
Adapted the phpmd default config.
10+
* Import all rule sets
11+
* Allow variables as long as 25 chars
12+
</description>
1313

14-
<rule ref="rulesets/codesize.xml" />
15-
<rule ref="rulesets/controversial.xml" />
16-
<rule ref="rulesets/design.xml" />
17-
<rule ref="rulesets/naming.xml">
18-
<exclude name="LongVariable" />
19-
</rule>
20-
<rule ref="rulesets/naming.xml/LongVariable">
21-
<properties>
22-
<property name="maximum" value="30" />
23-
</properties>
24-
</rule>
25-
<rule ref="rulesets/unusedcode.xml" />
26-
<rule ref="rulesets/cleancode.xml">
27-
<exclude name="StaticAccess" />
28-
<exclude name="ElseExpression" />
29-
<exclude name="StaticAccess"/>
30-
</rule>
14+
<rule ref="rulesets/codesize.xml"/>
15+
<rule ref="rulesets/controversial.xml"/>
16+
<rule ref="rulesets/design.xml"/>
17+
<rule ref="rulesets/naming.xml">
18+
<exclude name="LongVariable"/>
19+
<exclude name="LongClassName"/>
20+
</rule>
21+
<rule ref="rulesets/naming.xml/LongVariable">
22+
<properties>
23+
<property name="maximum" value="50"/>
24+
</properties>
25+
</rule>
26+
<rule ref="rulesets/naming.xml/LongVariable">
27+
<properties>
28+
<property name="maximum" value="30"/>
29+
</properties>
30+
</rule>
31+
<rule ref="rulesets/unusedcode.xml"/>
32+
<rule ref="rulesets/cleancode.xml">
33+
<exclude name="StaticAccess"/>
34+
<exclude name="ElseExpression"/>
35+
<exclude name="StaticAccess"/>
36+
</rule>
3137
</ruleset>

Classes/Service/FilterService.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use In2code\In2studyfinder\Domain\Model\StudyCourse;
88
use In2code\In2studyfinder\Settings\ExtensionSettingsInterface;
9+
use Psr\Http\Message\ServerRequestInterface;
910
use Psr\Log\LoggerInterface;
1011
use TYPO3\CMS\Core\Context\LanguageAspect;
1112
use TYPO3\CMS\Core\Utility\ClassNamingUtility;
@@ -16,6 +17,12 @@
1617
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
1718
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
1819

20+
/**
21+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
22+
* @todo refactor:
23+
* - services should be stateless (see: https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/PhpArchitecture/Services.html)
24+
* - reduce complexity
25+
*/
1926
class FilterService
2027
{
2128
protected array $settings = [];
@@ -85,10 +92,10 @@ public function resolveFilterPropertyPath(array $searchOptions): array
8592
public function loadOrSetPersistedFilter(array $searchOptions): array
8693
{
8794
if ($searchOptions !== []) {
88-
$GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user')
95+
$this->getRequest()->getAttribute('frontend.user')
8996
->setAndSaveSessionData('tx_in2studycourse_filter', array_filter($searchOptions));
9097
} else {
91-
$sessionData = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user')
98+
$sessionData = $this->getRequest()->getAttribute('frontend.user')
9299
->getSessionData('tx_in2studycourse_filter');
93100
if (!empty($sessionData)) {
94101
return (array)$sessionData;
@@ -287,4 +294,12 @@ protected function getTypoScriptFilterConfiguration(): array
287294

288295
return [];
289296
}
297+
298+
/**
299+
* @SuppressWarnings(PHPMD.Superglobals)
300+
*/
301+
private function getRequest(): ServerRequestInterface
302+
{
303+
return $GLOBALS['TYPO3_REQUEST'];
304+
}
290305
}

Classes/Settings/ExtensionSettings.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function getStoragePidsByConfiguration(array $configuration): array
9696
{
9797
$storagePids = [];
9898

99-
foreach ($configuration as $type => $typeConfiguration) {
99+
foreach ($configuration as $typeConfiguration) {
100100
$pids = GeneralUtility::intExplode(',', $typeConfiguration['pids']);
101101

102102
if (array_key_exists('recursive', $typeConfiguration) && $typeConfiguration['recursive'] > 0) {
@@ -115,6 +115,9 @@ protected function getStoragePidsByConfiguration(array $configuration): array
115115
return array_unique($storagePids);
116116
}
117117

118+
/**
119+
* @SuppressWarnings(PHPMD.Superglobals)
120+
*/
118121
protected function getRequest(): ServerRequestInterface
119122
{
120123
return $GLOBALS['TYPO3_REQUEST'];

Classes/Utility/CacheUtility.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class CacheUtility
2020
*
2121
* Following cache tags will be added to tsfe:
2222
* "tx_in2studyfinder_uid_[course:uid]"
23+
*
24+
* @SuppressWarnings(PHPMD.Superglobals)
2325
*/
2426
public static function addCacheTags(QueryResultInterface|array $records): void
2527
{

Classes/Utility/FrontendUtility.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
class FrontendUtility
1414
{
15+
/**
16+
* @SuppressWarnings(PHPMD.Superglobals)
17+
*/
1518
public static function getCurrentPageIdentifier(): int
1619
{
1720
return $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.page.information')->getId();

Classes/ViewHelpers/Form/SelectViewHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @todo refactor
1414
*
1515
* this is currently the default select viewHelper with additional functionality
16+
*
17+
* @SuppressWarnings(PHPMD.NPathComplexity)
1618
*/
1719
class SelectViewHelper extends AbstractSelectViewHelper
1820
{

0 commit comments

Comments
 (0)