Skip to content

Commit

Permalink
🐛 fix grumphp
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti committed Oct 2, 2024
1 parent d885953 commit 123fac6
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 27 deletions.
14 changes: 12 additions & 2 deletions Classes/DataProcessing/LazyDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ public function __construct()
$this->contentDataProcessor = GeneralUtility::makeInstance(ContentDataProcessor::class);
}

public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
/**
* Process content object data
*
* @param ContentObjectRenderer $cObj The data of the content element or page
* @param array<mixed> $contentObjectConfiguration The configuration of Content Object
* @param array<mixed> $processorConfiguration The configuration of this processor
* @param array<mixed> $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
* @return array<mixed> the processed data as key/value store
*/
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData): array
{
$realProcessedData = 'LazyDataProcessor $realProcessedData';
$variables = $processorConfiguration['variables']; // given variable names to proxy
Expand All @@ -41,11 +50,12 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
]];
$realProcessedData = $this->contentDataProcessor->process($cObj, $configuration, $processedData);
}

return $realProcessedData[$variableName] ?? null;
});
}
}

return $processedData;
}
}

34 changes: 9 additions & 25 deletions Classes/Proxy/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@

namespace AUS\SsiInclude\Proxy;

/**
* @template TKey
* @template-covariant TValue
* @template-implements \Traversable<TKey, TValue>
*/
final class Proxy implements \Iterator, \Countable
use Iterator;
use Countable;
use Stringable;
use Closure;

final class Proxy implements Iterator, Countable, Stringable
{
private ?\Closure $callback = null;

/** @var mixed */
private $value;

public function __construct(\Closure $callback)
public function __construct(private ?Closure $callback)
{
$this->callback = $callback;
}

private function processRealInstance(): void
{
$callback = $this->callback;
Expand All @@ -28,79 +25,66 @@ private function processRealInstance(): void
$this->value = $callback();
}
}

public function __call($name, $arguments): mixed
{
$this->processRealInstance();
return call_user_func([$this->value, $name], $arguments);
}

public function __invoke(...$arguments): mixed
{
$this->processRealInstance();
return call_user_func($this->value, $arguments);
}

public function __isset($name): bool
{
$this->processRealInstance();
return isset($this->value[$name]);
}

public function __get($name): mixed
{
$this->processRealInstance();
return $this->value[$name];
}

public function __set($name, $value): void
{
$this->processRealInstance();
$this->value[$name] = $value;
}

public function __unset($name): void
{
$this->processRealInstance();
unset($this->value[$name]);
}

public function __toString(): string
{
$this->processRealInstance();
return $this->value . '';
}

public function current(): mixed
{
$this->processRealInstance();
return current($this->value);
}

public function next(): void
{
$this->processRealInstance();
next($this->value);
}

public function key(): mixed
{
$this->processRealInstance();
return key($this->value);
}

public function valid(): bool
{
return $this->current() !== false;
}

public function rewind(): void
{
$this->processRealInstance();
reset($this->value);
}

public function count()
public function count(): int
{
$this->processRealInstance();
return is_countable($this->value) ? count($this->value) : (isset($this->value) ? 1 : 0);
Expand Down
3 changes: 3 additions & 0 deletions Classes/ViewHelpers/RenderIncludeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
class RenderIncludeViewHelper extends RenderViewHelper
{
public const SSI_INCLUDE_DIR = '/typo3temp/tx_ssiinclude/';

public const METHOD_SSI = 'ssi';

public const METHOD_ESI = 'esi';

protected static function getContext(): Context
Expand Down Expand Up @@ -73,6 +75,7 @@ public static function renderStatic(array $arguments, Closure $renderChildrenClo
if ($method === self::METHOD_ESI) {
return '<esi:include src="' . $reqUrl . '" />';
}

return '<!--# include wait="yes" virtual="' . $reqUrl . '" -->';
}

Expand Down
50 changes: 50 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
parameters:
ignoreErrors:
-
message: "#^Class AUS\\\\SsiInclude\\\\Proxy\\\\Proxy implements generic interface Iterator but does not specify its types\\: TKey, TValue$#"
count: 1
path: Classes/Proxy/Proxy.php

-
message: "#^Method AUS\\\\SsiInclude\\\\Proxy\\\\Proxy\\:\\:__call\\(\\) has parameter \\$arguments with no type specified\\.$#"
count: 1
path: Classes/Proxy/Proxy.php

-
message: "#^Method AUS\\\\SsiInclude\\\\Proxy\\\\Proxy\\:\\:__call\\(\\) has parameter \\$name with no type specified\\.$#"
count: 1
path: Classes/Proxy/Proxy.php

-
message: "#^Method AUS\\\\SsiInclude\\\\Proxy\\\\Proxy\\:\\:__get\\(\\) has parameter \\$name with no type specified\\.$#"
count: 1
path: Classes/Proxy/Proxy.php

-
message: "#^Method AUS\\\\SsiInclude\\\\Proxy\\\\Proxy\\:\\:__invoke\\(\\) has parameter \\$arguments with no type specified\\.$#"
count: 1
path: Classes/Proxy/Proxy.php

-
message: "#^Method AUS\\\\SsiInclude\\\\Proxy\\\\Proxy\\:\\:__isset\\(\\) has parameter \\$name with no type specified\\.$#"
count: 1
path: Classes/Proxy/Proxy.php

-
message: "#^Method AUS\\\\SsiInclude\\\\Proxy\\\\Proxy\\:\\:__set\\(\\) has parameter \\$name with no type specified\\.$#"
count: 1
path: Classes/Proxy/Proxy.php

-
message: "#^Method AUS\\\\SsiInclude\\\\Proxy\\\\Proxy\\:\\:__set\\(\\) has parameter \\$value with no type specified\\.$#"
count: 1
path: Classes/Proxy/Proxy.php

-
message: "#^Method AUS\\\\SsiInclude\\\\Proxy\\\\Proxy\\:\\:__unset\\(\\) has parameter \\$name with no type specified\\.$#"
count: 1
path: Classes/Proxy/Proxy.php

-
message: "#^Parameter \\#1 \\$callback of function call_user_func expects callable\\(\\)\\: mixed, array\\{mixed, mixed\\} given\\.$#"
count: 1
path: Classes/Proxy/Proxy.php

0 comments on commit 123fac6

Please sign in to comment.