Skip to content

Commit aceb9ba

Browse files
committed
Fix level 4 type errors
1 parent 53ea37b commit aceb9ba

File tree

4 files changed

+10
-24
lines changed

4 files changed

+10
-24
lines changed

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 3
2+
level: 4
33
paths:
44
- src
55
- tests

src/Runtime.php

+6-20
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,10 @@ public static function isec(mixed $v): bool
5858
return $v === null || $v === false || (is_array($v) && count($v) === 0);
5959
}
6060

61-
/**
62-
* For {{var}} .
63-
*
64-
* @param array<array|string|int>|string|int|null $var value to be htmlencoded
65-
*/
66-
public static function enc($var): string
67-
{
68-
if ($var instanceof SafeString) {
69-
return (string) $var;
70-
}
71-
72-
return Encoder::enc($var);
73-
}
74-
7561
/**
7662
* For {{var}} , do html encode just like handlebars.js .
7763
*
78-
* @param array<array|string|int>|string|int|null $var value to be htmlencoded
64+
* @param array<array|string|int>|string|SafeString|int|null $var value to be htmlencoded
7965
*
8066
* @return string The htmlencoded value of the specified variable
8167
*/
@@ -91,7 +77,7 @@ public static function encq($var): string
9177
/**
9278
* Get string value
9379
*
94-
* @param array<array|string|int>|string|int|null $v value to be output
80+
* @param array<array|string|int>|string|int|bool|null $v value to be output
9581
* @param int $ex 1 to return untouched value, default is 0
9682
*
9783
* @return array<array|string|int>|string|int|null The raw value of the specified variable
@@ -128,7 +114,7 @@ public static function raw($v, int $ex = 0)
128114
/**
129115
* For {{#var}} or {{#each}} .
130116
*
131-
* @param array<array|string|int>|string|int|null|\Traversable $v value for the section
117+
* @param array<array|string|int>|string|int|bool|null|\Traversable $v value for the section
132118
* @param array<string>|null $bp block parameters
133119
* @param array<array|string|int>|string|int|null $in input data with current scope
134120
* @param bool $each true when rendering #each
@@ -239,7 +225,7 @@ public static function sec(RuntimeContext $cx, mixed $v, ?array $bp, mixed $in,
239225
/**
240226
* For {{#with}} .
241227
*
242-
* @param array<array|string|int>|string|int|null $v value to be the new context
228+
* @param array<array|string|int>|string|int|bool|null $v value to be the new context
243229
* @param array<array|string|int>|\stdClass|null $in input data with current scope
244230
* @param array<string>|null $bp block parameters
245231
* @param \Closure $cb callback function to render child context
@@ -266,13 +252,13 @@ public static function wi(RuntimeContext $cx, mixed $v, ?array $bp, array|\stdCl
266252
/**
267253
* Get merged context.
268254
*
269-
* @param array<array|string|int>|string|int|null $a the context to be merged
255+
* @param array<array|string|int>|object|string|int|null $a the context to be merged
270256
* @param array<array|string|int>|string|int|null $b the new context to overwrite
271257
*
272258
* @return array<array|string|int>|string|int the merged context object
273259
*
274260
*/
275-
public static function merge($a, $b)
261+
public static function merge(mixed $a, mixed $b)
276262
{
277263
if (is_array($b)) {
278264
if ($a === null) {

src/SafeString.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace DevTheorem\Handlebars;
44

5-
class SafeString
5+
class SafeString implements \Stringable
66
{
77
public const EXTENDED_COMMENT_SEARCH = '/{{!--.*?--}}/s';
88
public const IS_SUBEXP_SEARCH = '/^\(.+\)$/s';

tests/ErrorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public function testErrors($test)
104104
{
105105
if (!isset($test['expected'])) {
106106
// should compile without error
107-
Handlebars::precompile($test['template'], $test['options']);
108-
$this->assertTrue(true);
107+
$code = Handlebars::precompile($test['template'], $test['options']);
108+
$this->assertNotEmpty($code);
109109
return;
110110
}
111111

0 commit comments

Comments
 (0)