Skip to content

Commit

Permalink
Bump psalm to level 3
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and jordisala1991 committed Mar 12, 2023
1 parent 0357c5e commit c239b3c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion psalm.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="4" findUnusedPsalmSuppress="true" findUnusedBaselineEntry="true" findUnusedCode="false" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="3" findUnusedPsalmSuppress="true" findUnusedBaselineEntry="true" findUnusedCode="false" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand Down
5 changes: 5 additions & 0 deletions src/DependencyInjection/Configuration.php
Expand Up @@ -37,6 +37,11 @@ public function __construct(private array $defaultContainerTemplates)
{
}

/**
* @psalm-suppress PossiblyUndefinedMethod
*
* @see https://github.com/psalm/psalm-plugin-symfony/issues/174
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sonata_block');
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/Strategy/StrategyManager.php
Expand Up @@ -88,7 +88,7 @@ public function handleException(\Throwable $exception, BlockInterface $block, ?R

// Convert throwable to exception
if (!$exception instanceof \Exception) {
$exception = new \Exception($exception->getMessage(), $exception->getCode(), $exception);
$exception = new \Exception($exception->getMessage(), (int) $exception->getCode(), $exception);
}

$response = $renderer->render($exception, $block, $response);
Expand Down
26 changes: 14 additions & 12 deletions src/Templating/Helper/BlockHelper.php
Expand Up @@ -39,10 +39,10 @@
* cache: array{
* keys: mixed[],
* contextual_keys: mixed[],
* handler: false,
* from_cache: false,
* handler: string|false,
* from_cache: bool,
* ttl: int,
* created_at: false,
* created_at: int|false,
* lifetime: int,
* age: int,
* },
Expand Down Expand Up @@ -415,7 +415,7 @@ public function render($block, array $options = []): string
$blockContext->getSetting('extra_cache_keys')
);

if (null !== $this->stopwatch) {
if (null !== $stats) {
$stats['cache']['keys'] = $cacheKeys;
}

Expand All @@ -425,16 +425,17 @@ public function render($block, array $options = []): string
if ($cacheService->has($cacheKeys)) {
$cacheElement = $cacheService->get($cacheKeys);

if (null !== $this->stopwatch) {
if (null !== $stats) {
$stats['cache']['from_cache'] = false;
}

if (!$cacheElement->isExpired() && $cacheElement->getData() instanceof Response) {
if (null !== $this->stopwatch) {
$cacheData = $cacheElement->getData();
if (!$cacheElement->isExpired() && $cacheData instanceof Response) {
if (null !== $stats) {
$stats['cache']['from_cache'] = true;
}

$response = $cacheElement->getData();
$response = $cacheData;
}
}
}
Expand All @@ -451,7 +452,7 @@ public function render($block, array $options = []): string
$response = $this->blockRenderer->render($blockContext);
$contextualKeys = null !== $recorder ? $recorder->pop() : [];

if (null !== $this->stopwatch) {
if (null !== $stats) {
$stats['cache']['contextual_keys'] = $contextualKeys;
}

Expand All @@ -460,10 +461,10 @@ public function render($block, array $options = []): string
}
}

if (null !== $this->stopwatch) {
if (null !== $stats) {
// avoid \DateTime because of serialize/unserialize issue in PHP7.3 (https://bugs.php.net/bug.php?id=77302)
$responseDate = $response->getDate();
$stats['cache']['created_at'] = null === $responseDate ? null : $responseDate->getTimestamp();
$stats['cache']['created_at'] = null === $responseDate ? false : $responseDate->getTimestamp();
$stats['cache']['ttl'] = $response->getTtl() ?? 0;
$stats['cache']['age'] = $response->getAge();
$stats['cache']['lifetime'] = $stats['cache']['age'] + $stats['cache']['ttl'];
Expand All @@ -474,7 +475,8 @@ public function render($block, array $options = []): string
$this->cacheHandler->updateMetadata($response, $blockContext);
}

if (null !== $this->stopwatch) {
if (null !== $stats) {
/** @psalm-suppress ArgumentTypeCoercion https://github.com/vimeo/psalm/issues/9150 */
$this->stopTracing($blockContext->getBlock(), $stats);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Util/RecursiveBlockIterator.php
Expand Up @@ -24,7 +24,7 @@
final class RecursiveBlockIterator extends \RecursiveArrayIterator
{
/**
* @param ReadableCollection<array-key, BlockInterface>|array<BlockInterface> $array
* @param ReadableCollection<int, BlockInterface>|array<BlockInterface> $array
*/
public function __construct($array)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Util/RecursiveBlockIteratorIterator.php
Expand Up @@ -23,7 +23,7 @@
final class RecursiveBlockIteratorIterator extends \RecursiveIteratorIterator
{
/**
* @param array<mixed>|ReadableCollection<array-key, mixed> $array
* @param array<mixed>|ReadableCollection<int, mixed> $array
*/
public function __construct($array)
{
Expand Down

0 comments on commit c239b3c

Please sign in to comment.