Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add phpstan and phpcs remind standard and adapt code style #36

Merged
merged 1 commit into from
Aug 8, 2024
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
46 changes: 0 additions & 46 deletions .build/phpcs.xml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: remindgmbh/[email protected]
phpcs:
static-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -18,4 +18,4 @@ jobs:
extensions: intl
tools: composer:v2
- run: composer install
- run: composer run-script phpcs
- run: composer run-script static-analysis
20 changes: 2 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
### IDE ###
nbproject/
.idea/

### Composer ###
composer.phar

### General ###
*.log
cache.properties

### CI ###
.build/bin/
.build/logs/
.build/var/
.build/vendor/
.build/web/
coverage.xml
/vendor
/public
8 changes: 3 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"phpCodeSniffer.exec.linux": "./.build/bin/phpcs",
"phpCodeSniffer.exec.linux": "./vendor/bin/phpcs",
"phpCodeSniffer.standard": "Custom",
"phpCodeSniffer.standardCustom": "./.build/phpcs.xml",
"phpCodeSniffer.exclude": [
"**/.build/vendor/**"
]
"phpCodeSniffer.standardCustom": "./phpcs.xml",
"phpCodeSniffer.exclude": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class AbstractBreadcrumbTitleProvider implements BreadcrumbTitleProviderInterface, SingletonInterface
{
protected $title = '';
protected string $title = '';

public function getTitle(): string
{
Expand Down
22 changes: 16 additions & 6 deletions Classes/BreadcrumbTitle/BreadcrumbTitleProviderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class BreadcrumbTitleProviderManager implements SingletonInterface, LoggerAwareI
{
use LoggerAwareTrait;

private $breadcrumbTitleCache = [];
/**
* @var string[]
*/
private array $breadcrumbTitleCache = [];

public function getTitle(): string
{
Expand All @@ -28,7 +31,7 @@ public function getTitle(): string
$orderedTitleProviders = GeneralUtility::makeInstance(DependencyOrderingService::class)
->orderByDependencies($titleProviders);

$this->logger->debug('Breadcrumb title providers ordered', [
$this->logger?->debug('Breadcrumb title providers ordered', [
'orderedTitleProviders' => $orderedTitleProviders,
]);

Expand All @@ -43,24 +46,28 @@ class_exists($configuration['provider']) &&
($breadcrumbTitle = $titleProviderObject->getTitle())
|| ($breadcrumbTitle = $this->breadcrumbTitleCache[$configuration['provider']] ?? '') !== ''
) {
$this->logger->debug('Breadcrumb title provider {provider} used on page {title}', [
'title' => $breadcrumbTitle,
$this->logger?->debug('Breadcrumb title provider {provider} used on page {title}', [
'provider' => $configuration['provider'],
'title' => $breadcrumbTitle,
]);
$this->breadcrumbTitleCache[$configuration['provider']] = $breadcrumbTitle;
break;
}
$this->logger->debug('Breadcrumb title provider {provider} skipped on page {title}', [
'title' => $breadcrumbTitle,
$this->logger?->debug('Breadcrumb title provider {provider} skipped on page {title}', [
'provider' => $configuration['provider'],
'providerUsed' => $configuration['provider'],
'title' => $breadcrumbTitle,
]);
}
}

return $breadcrumbTitle;
}

/**
* @param mixed[] $orderInformation
* @return mixed[]
*/
protected function setProviderOrder(array $orderInformation): array
{
foreach ($orderInformation as $provider => &$configuration) {
Expand Down Expand Up @@ -88,6 +95,9 @@ protected function setProviderOrder(array $orderInformation): array
return $orderInformation;
}

/**
* @return mixed[]
*/
private function getBreadcrumbTitleProviderConfiguration(): array
{
$typoscriptService = GeneralUtility::makeInstance(TypoScriptService::class);
Expand Down
47 changes: 27 additions & 20 deletions Classes/DataProcessing/FlexFormProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,32 @@
class FlexFormProcessor implements DataProcessorInterface
{
protected ContentObjectRenderer $cObj;

/**
* @var mixed[]
*/
protected array $processorConf;

/**
* @param ContentObjectRenderer $cObj The data of the content element or page
* @param array $contentObjectConf The configuration of Content Object
* @param array $processorConf The configuration of this processor
* @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
* @return array the processed data as key/value store
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter
* @param mixed[] $contentObjectConf
* @param mixed[] $processorConf
* @param mixed[] $processedData
* @return mixed[]
*/
public function process(
ContentObjectRenderer $cObj,
array $contentObjectConf,
array $processorConf,
array $processedData
): array {
$this->cObj = $cObj;
): array { $this->cObj = $cObj;
$this->processorConf = $processorConf;

$flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
$flexFormTools->reNumberIndexesOfSectionData = true;
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);

$fieldName = $cObj->stdWrapValue('fieldName', $processorConf);
$fieldName = (string) $cObj->stdWrapValue('fieldName', $processorConf);

// default flexform field name
if (empty($fieldName)) {
Expand Down Expand Up @@ -93,20 +96,20 @@ public function process(
if (!empty($targetVariableName)) {
$processedData[$targetVariableName] = $flexformData;
} else {
if ($processedData['data'][$fieldName]) {
$processedData['data'][$fieldName] = $flexformData;
} else {
$processedData[$fieldName] = $flexformData;
}
$processedData['data'][$fieldName] = $flexformData;
}

return $processedData;
}

/**
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter
* @param mixed[] $element
*/
public function parseElement(
array $element,
string $value,
$additionalParameters,
mixed $additionalParameters,
string $path,
FlexFormTools $flexFormTools
): void {
Expand All @@ -127,7 +130,7 @@ public function parseElement(
}

if ($type === 'text') {
$newValue = $this->cObj->parseFunc($value, [], '< lib.parseFunc_links');
$newValue = $this->cObj->parseFunc($value, null, '< lib.parseFunc_links');
}

if ($type === 'file') {
Expand All @@ -140,9 +143,13 @@ public function parseElement(
$fieldName = $element['config']['foreign_match_fields']['fieldname'];

try {
$overrule = ArrayUtility::getValueByPath($this->processorConf, ['filesConfiguration.', ...array_map(function ($value) {
return $value . '.';
}, explode('.', $fieldName))]);
$overrule = ArrayUtility::getValueByPath(
$this->processorConf,
['filesConfiguration.', ...array_map(function ($value) {
return $value . '.';
},
explode('.', $fieldName))]
);
ArrayUtility::mergeRecursiveWithOverrule($assetProcessingConfiguration, $overrule);
} catch (MissingArrayPathException $e) {
}
Expand All @@ -151,14 +158,14 @@ public function parseElement(
$as = 'file';
$processorConfiguration = [
'as' => $as,
'processingConfiguration.' => $assetProcessingConfiguration,
'references.' => [
'fieldName' => $fieldName,
],
'processingConfiguration.' => $assetProcessingConfiguration,
];
$processedData = [
'data' => $this->cObj->data,
'current' => null,
'data' => $this->cObj->data,
];
$processedData = $filesProcessor->process(
$this->cObj,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(
) {
}

public function __invoke(AfterCacheableContentIsGeneratedEvent $event)
public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void
{
try {
$content = json_decode($event->getController()->content, true, 512, JSON_THROW_ON_ERROR);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Remind\Headless\Event\Listener;

use PDO;
Expand Down Expand Up @@ -31,11 +33,11 @@ public function __invoke(AfterFlexFormDataStructureIdentifierInitializedEvent $e
if ($foreignUid) {
$isNew = !is_int($foreignUid) && str_starts_with($foreignUid, 'NEW');
if ($isNew) {
$body = $request->getParsedBody();
$body = (array) $request->getParsedBody();
$context = json_decode($body['ajax']['context'] ?? null, true);
$config = json_decode($context['config'] ?? null, true);
$queryParams = parse_url($config['originalReturnUrl'], PHP_URL_QUERY);
parse_str($queryParams, $queryParams);
parse_str($queryParams ?: '', $queryParams);
$type = $queryParams['defVals'][$foreignTable][$foreignField] ?? null;
} else {
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
Expand All @@ -54,7 +56,7 @@ public function __invoke(AfterFlexFormDataStructureIdentifierInitializedEvent $e
$type = $queryBuilder->executeQuery()->fetchOne();
}
} else {
$body = $request->getParsedBody();
$body = (array) $request->getParsedBody();
$foreignRow = current($body['data'][$foreignTable]);
$type = $foreignRow[$foreignField];
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Event/Listener/EnrichFileDataEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __invoke(EnrichFileDataEvent $event): void
{
$originalFile = $event->getOriginal();
$properties = $event->getProperties();
$properties['lazyLoading'] = (bool) $originalFile->getProperty('tx_headless_lazy_loading') ?? true;
$properties['lazyLoading'] = (bool) $originalFile->getProperty('tx_headless_lazy_loading');
$event->setProperties($properties);
}
}
18 changes: 14 additions & 4 deletions Classes/Form/AbstractModelDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
abstract class AbstractModelDecorator extends FormDefinitionDecorator
{
protected string $actionName = '';

protected string $controllerName = '';

protected string $valueName = '';

/**
* @param mixed[] $decorated
* @param mixed[] $definition
* @return mixed[]
*/
protected function overrideDefinition(array $decorated, array $definition, int $currentPage): array
{
$decorated = parent::overrideDefinition($decorated, $definition, $currentPage);
Expand All @@ -25,15 +32,18 @@ protected function overrideDefinition(array $decorated, array $definition, int $

$controllerArguments = $arguments[$this->controllerName] ?? null;

if ($controllerArguments) {
$uid = (int) $controllerArguments[$this->valueName] ?? null;
if (is_array($controllerArguments)) {
$uid = (int) $controllerArguments[$this->valueName];
$action = $controllerArguments['action'] ?? null;

if ($action === $this->actionName && $uid) {
if (
$action === $this->actionName &&
$uid
) {
$decorated['elements'][] = [
'type' => 'Hidden',
'defaultValue' => $uid,
'name' => $this->controllerName . '[' . $this->valueName . ']',
'type' => 'Hidden',
];
}
}
Expand Down
Loading