Skip to content

Commit 53ea37b

Browse files
committed
Fix level 3 type errors
1 parent e194a0d commit 53ea37b

8 files changed

+60
-63
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "devtheorem/php-handlebars",
3-
"description": "An extremely fast PHP implementation of Handlebars.",
3+
"description": "A fast, spec-compliant PHP implementation of Handlebars.",
44
"keywords": [
55
"Handlebars",
66
"PHP",
@@ -23,9 +23,9 @@
2323
"php": ">=8.2"
2424
},
2525
"require-dev": {
26-
"friendsofphp/php-cs-fixer": "^3.74",
26+
"friendsofphp/php-cs-fixer": "^3.75",
2727
"jbboehr/handlebars-spec": "dev-master",
28-
"phpstan/phpstan": "^2.1.11",
28+
"phpstan/phpstan": "^2.1.12",
2929
"phpunit/phpunit": "^11.5"
3030
},
3131
"autoload": {

composer.lock

+32-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

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

src/Compiler.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected static function getVariableName(Context $context, array $var, ?array $
216216
/**
217217
* Return compiled PHP code for a handlebars token
218218
*
219-
* @param array<string,array|bool> $info parsed information
219+
* @param array{bool, array, array, string} $info parsed information
220220
*/
221221
protected static function compileToken(Context $context, array $info): string
222222
{
@@ -240,7 +240,7 @@ protected static function compileToken(Context $context, array $info): string
240240
return static::compileLookup($context, $vars, $raw);
241241
}
242242
if ($vars[0][0] === 'log') {
243-
return static::compileLog($context, $vars, $raw);
243+
return static::compileLog($context, $vars);
244244
}
245245
}
246246

@@ -326,7 +326,7 @@ protected static function blockCustomHelper(Context $context, array $vars, bool
326326
* @param array $vars parsed arguments list
327327
* @param string|null $match should also match to this operator
328328
*/
329-
protected static function blockEnd(Context $context, array &$vars, ?string $match = null): string
329+
protected static function blockEnd(Context $context, array $vars, ?string $match = null): string
330330
{
331331
$pop = $context->stack[count($context->stack) - 1];
332332

@@ -475,9 +475,8 @@ protected static function doElse(Context $context, array $vars)
475475
* Return compiled PHP code for a handlebars log token
476476
*
477477
* @param array<bool|int|string|array> $vars parsed arguments list
478-
* @param bool $raw is this {{{ token or not
479478
*/
480-
protected static function compileLog(Context $context, array &$vars, bool $raw): string
479+
protected static function compileLog(Context $context, array &$vars): string
481480
{
482481
array_shift($vars);
483482
$v = static::getVariableNames($context, $vars);

src/HelperOptions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function __construct(
1010
public readonly \Closure $fn,
1111
public readonly \Closure $inverse,
1212
public readonly int $blockParams,
13-
public array|string|null &$scope,
13+
public mixed &$scope,
1414
public array &$data,
1515
) {}
1616

src/Parser.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ protected static function getExpression(string $v, Context $context, int|string
144144
*
145145
* @param array<string> $token preg_match results
146146
*
147-
* @return array<bool|int|array> Return parsed result
147+
* @return array{bool,array} Return parsed result
148148
*/
149-
public static function parse(array &$token, Context $context): array
149+
public static function parse(array $token, Context $context): array
150150
{
151151
$vars = static::analyze($token[Token::POS_INNERTAG], $context);
152152
if ($token[Token::POS_OP] === '>') {
@@ -171,25 +171,26 @@ public static function parse(array &$token, Context $context): array
171171
/**
172172
* Get partial name from "foo" or [foo] or \'foo\'
173173
*
174-
* @param array<bool|int|array> $vars parsed token
174+
* @param array<bool|int|string> $vars parsed token
175175
* @param int $pos position of partial name
176176
*
177177
* @return array<string>|null Return one element partial name array
178178
*/
179-
public static function getPartialName(array &$vars, int $pos = 0): ?array
179+
public static function getPartialName(array $vars, int $pos = 0): ?array
180180
{
181-
if (!isset($vars[$pos])) {
181+
if (!isset($vars[$pos]) || preg_match(SafeString::IS_SUBEXP_SEARCH, $vars[$pos])) {
182182
return null;
183183
}
184-
return preg_match(SafeString::IS_SUBEXP_SEARCH, $vars[$pos]) ? null : [preg_replace('/^("(.+)")|(\\[(.+)\\])|(\\\\\'(.+)\\\\\')$/', '$2$4$6', $vars[$pos])];
184+
assert(is_string($vars[$pos]));
185+
return [preg_replace('/^("(.+)")|(\\[(.+)\\])|(\\\\\'(.+)\\\\\')$/', '$2$4$6', $vars[$pos])];
185186
}
186187

187188
/**
188189
* Parse a subexpression then return parsed result.
189190
*
190191
* @param string $expression the full string of a sub expression
191192
*
192-
* @return array<bool|int|array> Return parsed result
193+
* @return array<string|int|array> Return parsed result
193194
*/
194195
public static function subexpression(string $expression, Context $context): array
195196
{
@@ -332,7 +333,7 @@ protected static function detectQuote(string $string): ?array
332333
*
333334
* @param string $token preg_match results
334335
*
335-
* @return array<bool|int|array> Return parsed result
336+
* @return list<string> Return parsed result
336337
*/
337338
protected static function analyze(string $token, Context $context): array
338339
{

0 commit comments

Comments
 (0)