Skip to content

Commit

Permalink
Fix PHP 8.2 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Aug 15, 2023
1 parent 5486275 commit 9b9dcc0
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
setup: ['lowest', 'stable', 'next']

name: PHP ${{ matrix.php }} - ${{ matrix.setup }}
Expand Down
8 changes: 4 additions & 4 deletions src/Phug/Phug/Phug/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,21 @@ protected function convertToKebabCase($string)
{
return preg_replace_callback('/[A-Z]/', function ($match) {
return '-'.strtolower($match[0]);
}, $string);
}, (string) $string);
}

protected function convertToCamelCase($string)
{
return preg_replace_callback('/-([a-z])/', function ($match) {
return strtoupper($match[1]);
}, $string);
}, (string) $string);
}

protected function execute($facade, $method, $arguments, $outputFile)
{
$callable = [$facade, $method];
$arguments = array_map(function ($argument) {
return in_array(substr($argument, 0, 1), ['[', '{'])
return in_array(substr((string) $argument, 0, 1), ['[', '{'])
? json_decode($argument, true)
: $argument;
}, $arguments);
Expand Down Expand Up @@ -206,7 +206,7 @@ protected function getNamedArgumentBySpaceDelimiter(array &$arguments, $index, $

protected function getNamedArgumentByEqualOperator(array &$arguments, $index, $name)
{
if (preg_match('/^'.preg_quote($name).'=(.*)$/', $arguments[$index], $match)) {
if (preg_match('/^'.preg_quote($name).'=(.*)$/', (string) $arguments[$index], $match)) {
array_splice($arguments, $index, 1);

return $match[1];
Expand Down
4 changes: 2 additions & 2 deletions tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function testNestedYield()
$expected = file_get_contents(__DIR__.'/../../../templates/yield-in-sub-include.html');

$this->assertCompileFile(
str_replace("\n", '', $expected),
str_replace(["\r", "\n"], '', $expected),
__DIR__.'/../../../templates/yield-in-sub-include.pug'
);
}
Expand All @@ -193,7 +193,7 @@ public function testMixinsPropagation()
$expected = file_get_contents(__DIR__.'/../../../templates/inheritance.extend.mixins.html');

$this->assertRenderFile(
preg_replace('/\n\s*/', '', $expected),
preg_replace('/\r?\n\s*/', '', $expected),
__DIR__.'/../../../templates/inheritance.extend.mixins.pug'
);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Phug/Format/FakeFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ public function __invoke(ElementInterface $element)
return $helper($element->getName());
}

#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return strpos($offset, 'non_existing') === false;
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $offset;
}

#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
}

#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Phug/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public function testTransformExpression()
self::assertSame(
'<?= (is_array($_pug_temp = $foo->bar) || is_object($_pug_temp) && '.
'!method_exists($_pug_temp, "__toString") ? json_encode($_pug_temp) : strval($_pug_temp)) ?>',
$formatter->format($expression, HtmlFormat::class)
preg_replace('/\s+/', ' ', $formatter->format($expression, HtmlFormat::class))
);

$attribute = new AttributeElement('class', new ExpressionElement('$foo.bar'));
Expand Down
1 change: 1 addition & 0 deletions tests/Phug/ProfilerModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function testMemoryLimitOptions()
* @covers ::renderProfile
* @covers ::recordDisplayEvent
* @covers ::getException
* @covers \Phug\Renderer\Partial\Debug\DebuggerTrait::getRendererException
*/
public function testExecutionMaxTime()
{
Expand Down
4 changes: 0 additions & 4 deletions tests/Phug/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1283,10 +1283,6 @@ public function testConsecutiveStringRenders()
*/
public function testCacheDirectoryPreserveDependencies()
{
if (version_compare(PHP_VERSION, '8.1.0-dev', '>=')) {
$this->markTestSkipped('Not compatible with PHP 8.1');
}

$cacheDirectory = sys_get_temp_dir().'/pug-test'.mt_rand(0, 999999);
$this->createEmptyDirectory($cacheDirectory);

Expand Down
2 changes: 1 addition & 1 deletion tests/Phug/Utils/AssertRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function implodeLines($str)
sort($attributes);

return ' '.implode(' ', $attributes);
}, is_string($str) ? $str : implode('', $str));
}, str_replace("\r", '', is_string($str) ? $str : implode('', $str)));
}

protected function assertSameLines($expected, $actual)
Expand Down

0 comments on commit 9b9dcc0

Please sign in to comment.