Skip to content

Commit

Permalink
[TASK] Fix phpstan level 8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Oct 23, 2022
1 parent 72cfb9f commit ba00693
Show file tree
Hide file tree
Showing 40 changed files with 238 additions and 140 deletions.
6 changes: 5 additions & 1 deletion Classes/Content/ContentTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public function registerTypeDefinition(ContentTypeDefinitionInterface $typeDefin

public function determineContentTypeForTypeString(string $contentTypeName): ?ContentTypeDefinitionInterface
{
return $this->types[$contentTypeName] ?? ($this->types[$contentTypeName] = $this->loadSingleDefinitionFromCache($contentTypeName));
$definition = $this->loadSingleDefinitionFromCache($contentTypeName);
if ($definition === null) {
return null;
}
return $this->types[$contentTypeName] ?? ($this->types[$contentTypeName] = $definition);
}

public function determineContentTypeForRecord(array $record): ?ContentTypeDefinitionInterface
Expand Down
4 changes: 2 additions & 2 deletions Classes/Content/RuntimeDefinedContentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function trigger(array $row, $table, $field, $extensionKey = null)

public function getControllerExtensionKeyFromRecord(array $row)
{
return ExtensionNamingUtility::getExtensionKey($this->getExtensionKey($row));
return ExtensionNamingUtility::getExtensionKey((string) $this->getExtensionKey($row));
}

public function getControllerActionFromRecord(array $row)
Expand Down Expand Up @@ -129,7 +129,7 @@ protected function getContentTypeDefinition(array $row): FluidRenderingContentTy
'Content type definition for %s must implement interface %s, class %s does not.',
$row['CType'],
FluidRenderingContentTypeDefinitionInterface::class,
get_class($definition)
$definition !== null ? get_class($definition) : '(unknown)'
),
1556109085
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,18 @@ public function getForm(array $record = []): Form
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var ProviderResolver $providerResolver */
$providerResolver = $objectManager->get(ProviderResolver::class);
return $providerResolver->resolvePrimaryConfigurationProvider(
$provider = $providerResolver->resolvePrimaryConfigurationProvider(
'tt_content',
'pi_flexform',
$record
)->getForm($record);
);
/** @var Form $defaultForm */
$defaultForm = Form::create();

if ($provider === null) {
return $defaultForm;
}
return $provider->getForm($record) ?? $defaultForm;
}

public function getGrid(array $record = []): Form\Container\Grid
Expand All @@ -90,11 +97,15 @@ public function getGrid(array $record = []): Form\Container\Grid
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var ProviderResolver $providerResolver */
$providerResolver = $objectManager->get(ProviderResolver::class);
return $providerResolver->resolvePrimaryConfigurationProvider(
$provider = $providerResolver->resolvePrimaryConfigurationProvider(
'tt_content',
'pi_flexform',
$record
)->getGrid($record);
);
if ($provider === null) {
return Form\Container\Grid::create();
}
return $provider->getGrid($record);
}

public static function fetchContentTypes(): iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use FluidTYPO3\Flux\Content\ContentGridForm;
use FluidTYPO3\Flux\Content\ContentTypeManager;
use FluidTYPO3\Flux\Content\TypeDefinition\ContentTypeDefinitionInterface;
use FluidTYPO3\Flux\Form\Container\Grid;
use FluidTYPO3\Flux\Provider\AbstractProvider;
use FluidTYPO3\Flux\Provider\Interfaces\GridProviderInterface;
Expand Down Expand Up @@ -91,6 +92,10 @@ public function getForm(array $row)
*/
public function getGrid(array $row)
{
return $this->contentTypeDefinitions->determineContentTypeForRecord($row)->getGrid() ?? parent::getGrid($row);
$contentTypeDefinition = $this->contentTypeDefinitions->determineContentTypeForRecord($row);
if (!($contentTypeDefinition instanceof ContentTypeDefinitionInterface)) {
return parent::getGrid($row);
}
return $contentTypeDefinition->getGrid() ?? parent::getGrid($row);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ public function getTemplateSource(): string
$columnTemplateChunk = '<flux:content.render area="%d" />' . PHP_EOL;

$grid = $this->getGrid();
if (!($grid instanceof Grid)) {
return '';
}
$template = '<div class="flux-grid">' . PHP_EOL;
foreach ($grid->getRows() as $row) {
$template .= '<div class="flux-grid-row">' . PHP_EOL;
Expand Down
34 changes: 24 additions & 10 deletions Classes/Controller/AbstractFluxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Form\FormInterface;
use FluidTYPO3\Flux\Hooks\HookHandler;
use FluidTYPO3\Flux\Integration\NormalizedData\DataAccessTrait;
use FluidTYPO3\Flux\Provider\Interfaces\ControllerProviderInterface;
Expand All @@ -28,6 +30,7 @@
use TYPO3\CMS\Extbase\Mvc\Response;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Fluid\View\TemplatePaths;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

/**
Expand Down Expand Up @@ -164,16 +167,16 @@ protected function initializeOverriddenSettings()
protected function initializeProvider()
{
$row = $this->getRecord();
$table = $this->getFluxTableName();
$table = (string) $this->getFluxTableName();
$field = $this->getFluxRecordField();
$this->provider = $this->configurationService->resolvePrimaryConfigurationProvider(
$provider = $this->configurationService->resolvePrimaryConfigurationProvider(
$table,
$field,
$row,
null,
ControllerProviderInterface::class
);
if (!$this->provider) {
if ($provider === null) {
throw new \RuntimeException(
'Unable to resolve a ConfigurationProvider, but controller indicates it is a Flux-enabled ' .
'Controller - this is a grave error and indicates that EXT: ' . $this->extensionName . ' itself is ' .
Expand All @@ -182,6 +185,7 @@ protected function initializeProvider()
1377458581
);
}
$this->provider = $provider;
}

/**
Expand Down Expand Up @@ -354,6 +358,7 @@ protected function performSubRendering($extensionName, $controllerName, $actionN

$shouldRelay = $this->hasSubControllerActionOnForeignController($extensionName, $controllerName, $actionName);
$foreignControllerClass = null;
$content = null;
if (!$shouldRelay) {
if ($this->provider instanceof FluidProviderInterface) {
$templatePathAndFilename = $this->provider->getTemplatePathAndFilename($this->getRecord());
Expand Down Expand Up @@ -385,7 +390,7 @@ protected function performSubRendering($extensionName, $controllerName, $actionN
);
$content = $this->callSubControllerAction(
$extensionName,
$foreignControllerClass,
$foreignControllerClass ?? static::class,
$actionName,
$pluginSignature
);
Expand Down Expand Up @@ -512,15 +517,15 @@ protected function getData()
}

/**
* @return string
* @return string|null
*/
protected function getFluxRecordField()
{
return $this->fluxRecordField;
}

/**
* @return string
* @return string|null
*/
protected function getFluxTableName()
{
Expand All @@ -532,7 +537,11 @@ protected function getFluxTableName()
*/
public function getRecord()
{
return $this->configurationManager->getContentObject()->data;
$contentObject = $this->configurationManager->getContentObject();
if ($contentObject === null) {
throw new \UnexpectedValueException("Record of table " . $this->getFluxTableName() . ' not found', 1666538343);
}
return $contentObject->data;
}

/**
Expand All @@ -541,18 +550,23 @@ public function getRecord()
public function outletAction()
{
$record = $this->getRecord();
$form = $this->provider->getForm($record);
$input = $this->request->getArguments();
$targetConfiguration = $this->request->getInternalArguments()['__outlet'];
if ($this->provider->getTableName($record) !== $targetConfiguration['table']
&& $record['uid'] !== (integer) $targetConfiguration['recordUid']
if ($form === null
||
($this->provider->getTableName($record) !== $targetConfiguration['table']
&& $record['uid'] !== (integer) $targetConfiguration['recordUid']
)
) {
// This instance does not match the instance that rendered the form. Forward the request
// to the default "render" action.
$this->forward('render');
}
$input['settings'] = $this->settings;
try {
$outlet = $this->provider->getForm($record)->getOutlet();
/** @var Form $form */
$outlet = $form->getOutlet();
$outlet->setView($this->view);
$outlet->fill($input);
if (!$outlet->isValid()) {
Expand Down
8 changes: 7 additions & 1 deletion Classes/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Provider\Interfaces\BasicProviderInterface;
use FluidTYPO3\Flux\Service\FluxService;
use FluidTYPO3\Flux\Service\PageService;
use TYPO3\CMS\Extbase\Mvc\Web\Response;
Expand Down Expand Up @@ -69,7 +70,12 @@ public function injectPageConfigurationService(FluxService $pageConfigurationSer
*/
protected function initializeProvider()
{
$this->provider = $this->pageConfigurationService->resolvePageProvider($this->getRecord());
$record = $this->getRecord();
if ($record !== null) {
$provider = $this->pageConfigurationService->resolvePageProvider($record);
if ($provider instanceof BasicProviderInterface)
$this->provider = $provider;
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Classes/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function initializeObject()

/**
* @param array $settings
* @return FormInterface
* @return static
*/
public static function create(array $settings = [])
{
Expand All @@ -129,7 +129,7 @@ public function add(Form\FormInterface $child)
$this->children->rewind();
/** @var FormInterface|null $firstChild */
$firstChild = $this->children->count() > 0 ? $this->children->current() : null;
if ($this->children->count() === 1 && $firstChild->getName() === 'options' && !$firstChild->hasChildren()) {
if ($firstChild instanceof FormInterface && $this->children->count() === 1 && $firstChild->getName() === 'options' && !$firstChild->hasChildren()) {
// Form has a single sheet, it's the default sheet and it has no fields. Replace it.
$this->children->detach($this->children->current());
}
Expand Down
16 changes: 11 additions & 5 deletions Classes/Form/AbstractFormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class AbstractFormComponent implements FormInterface
protected $enabled = true;

/**
* @var string
* @var string|null
*/
protected $label = null;

Expand Down Expand Up @@ -170,7 +170,7 @@ public function createWizard($type, $name, $label = null)
* @param string $namespace
* @param string|class-string $type
* @param string $name
* @param string|NULL $label
* @param string|null $label
* @return FormInterface
*/
public function createComponent($namespace, $type, $name, $label = null)
Expand Down Expand Up @@ -266,7 +266,7 @@ public function getExtensionName()
}

/**
* @param string $label
* @param string|null $label
* @return $this
*/
public function setLabel($label)
Expand Down Expand Up @@ -304,7 +304,7 @@ public function getPath()
}

/**
* @return string
* @return string|null
*/
public function getLabel()
{
Expand Down Expand Up @@ -334,7 +334,7 @@ protected function resolveLocalLanguageValueOfLabel($label, $path = null)
$relativeFilePath = $this->getLocalLanguageFileRelativePath();
$relativeFilePath = ltrim($relativeFilePath, '/');
$filePrefix = 'LLL:EXT:' . $extensionKey . '/' . $relativeFilePath;
if (strpos($label ?? '', 'LLL:') === 0) {
if (strpos($label ?? '', 'LLL:') === 0 && strpos($label ?? '', ':') !== false) {
// Shorthand LLL:name.of.index reference, expand
list (, $labelIdentifier) = explode(':', $label, 2);
return $filePrefix . ':' . $labelIdentifier;
Expand Down Expand Up @@ -535,6 +535,12 @@ public function modify(array $structure)
unset($structure['options']);
}
foreach ($structure as $propertyName => $propertyValue) {
if ($propertyName === 'children') {
foreach ($propertyValue as $child) {
$this->add($child);
}
continue;
}
$setterMethodName = 'set' . ucfirst($propertyName);
if (true === method_exists($this, $setterMethodName)) {
ObjectAccess::setProperty($this, $propertyName, $propertyValue);
Expand Down
23 changes: 12 additions & 11 deletions Classes/Form/AbstractFormContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function getChildren()
}

/**
* @return FormInterface|FALSE
* @return FormInterface|null
*/
public function last()
{
Expand All @@ -173,20 +173,21 @@ public function modify(array $structure)
{
if (isset($structure['fields']) || isset($structure['children'])) {
$data = isset($structure['children']) ? $structure['children'] : $structure['fields'];
foreach ((array) $data as $index => $fieldData) {
$fieldName = true === isset($fieldData['name']) ? $fieldData['name'] : $index;
foreach ((array) $data as $index => $childData) {
$childName = true === isset($childData['name']) ? $childData['name'] : $index;
// check if field already exists - if it does, modify it. If it does not, create it.

if (true === $this->has($fieldName)) {
/** @var FieldInterface|null $field */
$field = $this->get($fieldName);
if (true === $this->has($childName)) {
/** @var FormInterface $child */
$child = $this->get($childName);
} else {
/** @var class-string $fieldType */
$fieldType = true === isset($fieldData['type']) ? $fieldData['type'] : 'None';
/** @var FieldInterface|null $field */
$field = $this->createField($fieldType, $fieldName);
/** @var class-string $type */
$type = true === isset($childData['type']) ? $childData['type'] : 'None';
/** @var FormInterface $child */
$child = $this->createField($type, $childName);
}
$field->modify($fieldData);

$child->modify($childData);
}
unset($structure['children'], $structure['fields']);
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Form/AbstractInlineFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public function getOverrideChildTca()
*/
public function setForeignTypes($foreignTypes)
{
$this->foreignTypes = true === is_array($foreignTypes) ? $foreignTypes : null;
$this->foreignTypes = $foreignTypes ?? [];
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Form/AbstractMultiValueFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function getSelectedListStyle()
}

/**
* @return string
* @return string|null
*/
public function getRenderType()
{
Expand Down
6 changes: 3 additions & 3 deletions Classes/Form/Container/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ public function buildBackendLayout(int $parentRecordUid): BackendLayout

$typoScriptString = '';
$root = $this->getRoot();
$label = $root->getLabel();
$label = (string) $root->getLabel();
foreach ($this->flattenSetup($configuration, 'backend_layout.') as $name => $value) {
$typoScriptString .= $name . ' = ' . $value . LF;
}
return new BackendLayout(
$this->getRoot()->getName(),
LocalizationUtility::translate($label)
(string) $this->getRoot()->getName(),
(string) LocalizationUtility::translate($label)
? $label
: 'LLL:EXT:flux/Resources/Private/Language/locallang.xlf:flux.grid.grids.grid',
$typoScriptString
Expand Down
Loading

0 comments on commit ba00693

Please sign in to comment.