Skip to content

Commit 5b767b0

Browse files
Backward compatibility
1 parent 2ce093a commit 5b767b0

26 files changed

+36
-29
lines changed

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ parameters:
162162
- '#^Call to an undefined method Latte\\Engine\:\:addExtension\(\)\.$#'
163163
- '#^Parameter \#1 \$phpContent of method Efabrica\\PHPStanLatte\\Compiler\\Compiler\\Latte3Compiler::fixLines\(\) expects string, mixed given\.#'
164164
- '#^PHPDoc tag @var with type array<string, callable> is not subtype of type array<string>\.#'
165+
- '#^Parameter \#1 \$object of function get_class expects object, mixed given\.#'
166+
- '#^Call to function is_array\(\) with array<Latte\\Extension> will always evaluate to true\.#'
167+
- '#^Call to function is_object\(\) with Latte\\Extension will always evaluate to true\.#'
165168
path: src/Compiler/Compiler/Latte3Compiler.php
166169
reportUnmatched: false
167170

src/Analyser/LatteContextAnalyser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private function saveLatteContextDataToCache(string $file, LatteContextData $fil
235235
}
236236
Filesystem::write(
237237
$cacheFile,
238-
Json::encode($cacheData, true)
238+
Json::encode($cacheData, JSON_PRETTY_PRINT)
239239
);
240240
}
241241

@@ -247,8 +247,8 @@ private function loadLatteContextDataFromCache(string $file): ?LatteContextData
247247
}
248248

249249
try {
250-
$cacheData = Json::decode(Filesystem::read($cacheFile), true);
251-
} catch (Exception) {
250+
$cacheData = Json::decode(Filesystem::read($cacheFile), JSON_OBJECT_AS_ARRAY);
251+
} catch (Exception $e) {
252252
FileSystem::delete($cacheFile);
253253
return null;
254254
}
@@ -299,7 +299,7 @@ private function loadLatteContextDataFromCache(string $file): ?LatteContextData
299299

300300
try {
301301
return LatteContextData::fromJson($data, $this->typeStringResolver);
302-
} catch (Exception) {
302+
} catch (Exception $e) {
303303
FileSystem::delete($cacheFile);
304304
return null;
305305
}

src/Analyser/LatteContextData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function jsonSerialize(): array
127127
/**
128128
* @param array{items: array{class: class-string<CollectedLatteContextObject>, data: mixed}[]} $data
129129
*/
130-
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): static
130+
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): self
131131
{
132132
$collectedData = [];
133133
foreach ($data['items'] as $item) {

src/Compiler/Compiler/Latte3Compiler.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ public function __construct(
3131

3232
public function getCacheKey(): string
3333
{
34+
$extensions = $this->engine->getExtensions();
35+
if (!is_array($extensions)) {
36+
$extensions = [];
37+
}
3438
return md5(
3539
implode('', array_keys($this->getFilters())) .
3640
implode('', array_keys($this->getFunctions())) .
3741
implode('', array_map(function ($extension) {
38-
return get_class($extension);
39-
}, $this->engine->getExtensions()))
42+
return is_object($extension) ? get_class($extension) : null;
43+
}, $extensions))
4044
);
4145
}
4246

src/LatteContext/CollectedData/CollectedComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function jsonSerialize(): array
9999
/**
100100
* @param array{class: string, className: string, methodName: string, component: array<string, mixed>, declared: bool} $data
101101
*/
102-
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): static
102+
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): self
103103
{
104104

105105
return new self(

src/LatteContext/CollectedData/CollectedError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function jsonSerialize(): array
6464
/**
6565
* @param array{message: string, file: string, line?: int|null} $data
6666
*/
67-
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): static
67+
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): self
6868
{
6969
return new self(
7070
$data['message'],

src/LatteContext/CollectedData/CollectedFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function jsonSerialize(): array
5454
/**
5555
* @param array{className: string, methodName: string, filter: array<string, mixed>} $data
5656
*/
57-
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): static
57+
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): self
5858
{
5959
return new self(
6060
$data['className'],

src/LatteContext/CollectedData/CollectedLatteContextObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ abstract class CollectedLatteContextObject implements JsonSerializable
1212
/**
1313
* @param array<mixed> $data
1414
*/
15-
abstract public static function fromJson(array $data, TypeStringResolver $typeStringResolver): static;
15+
abstract public static function fromJson(array $data, TypeStringResolver $typeStringResolver): self;
1616
}

src/LatteContext/CollectedData/CollectedMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function jsonSerialize(): array
8787
/**
8888
* @param array{className: string, methodName: string, alwaysTerminated?: bool, returnType?: string|null} $data
8989
*/
90-
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): static
90+
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): self
9191
{
9292
return new self(
9393
$data['className'],

src/LatteContext/CollectedData/CollectedMethodCall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function jsonSerialize(): array
203203
/**
204204
* @param array{callerClassName?: ?class-string, callerMethodName?: string, calledClassName?: ?class-string, calledMethodName?: string, isCalledConditionally?: bool, type?: string, params?: array<string, string|int|float|bool>, currentClassName?: ?class-string} $data
205205
*/
206-
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): static
206+
public static function fromJson(array $data, TypeStringResolver $typeStringResolver): self
207207
{
208208
return new self(
209209
$data['callerClassName'] ?? null,

0 commit comments

Comments
 (0)