Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP 8 support #5

Merged
merged 2 commits into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.phpcs-cache
/.phpunit.result.cache
/clover.xml
/composer.lock
/coveralls-upload.json
Expand Down
1 change: 1 addition & 0 deletions .phpcs-cache

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ cache:

env:
global:
- COMPOSER_ARGS="--no-interaction"
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"
- COVERAGE_DEPS="php-coveralls/php-coveralls"

matrix:
fast_finish: true
include:
- php: 7.1
- php: 7.3
env:
- DEPS=lowest
- php: 7.1
- php: 7.3
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
- php: 7.4
env:
- DEPS=lowest
- php: 7.2
- php: 7.4
env:
- DEPS=latest
- php: 7.3
- CS_CHECK=true
- TEST_COVERAGE=true
- php: nightly
env:
- DEPS=lowest
- php: 7.3
- php: nightly
env:
- DEPS=latest

Expand Down
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
"config": {
"sort-packages": true
},
"extra": {
},
"require": {
"php": "^7.1",
"php": "^7.3 || ~8.0.0",
"laminas/laminas-zendframework-bridge": "^1.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "~1.0.0",
"laminas/laminas-coding-standard": "~2.1.0",
"malukenho/docheader": "^0.1.6",
"phpunit/phpunit": "^7.0.2"
"phpunit/phpunit": "^9.3"
},
"suggest": {
"mezzio/mezzio-laminasviewrenderer": "^2.0 to use the laminas-view PhpRenderer template renderer",
Expand Down
16 changes: 14 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<?xml version="1.0"?>
<ruleset name="Laminas coding standard">
<rule ref="./vendor/laminas/laminas-coding-standard/ruleset.xml"/>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
26 changes: 11 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Mezzio Tests">
<directory>./test</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="mezzio-template">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
7 changes: 3 additions & 4 deletions src/ArrayParametersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Traversable;

use function get_class;
use function gettype;
use function is_array;
use function is_object;
Expand All @@ -36,9 +35,9 @@ trait ArrayParametersTrait
* - scalar values result in an exception
*
* @param mixed $params
* @throws Exception\InvalidArgumentException for non-array, non-object parameters.
* @throws Exception\InvalidArgumentException
*/
private function normalizeParams($params) : array
private function normalizeParams($params): array
{
if (null === $params) {
return [];
Expand All @@ -65,7 +64,7 @@ private function normalizeParams($params) : array
throw new Exception\InvalidArgumentException(sprintf(
'%s template adapter can only handle arrays, Traversables, and objects '
. 'when rendering; received %s',
get_class($this),
static::class,
gettype($params)
));
}
Expand Down
12 changes: 5 additions & 7 deletions src/DefaultParamsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
*/
trait DefaultParamsTrait
{
/**
* @var array
*/
/** @var array */
private $defaultParams = [];

/**
Expand All @@ -39,10 +37,10 @@ trait DefaultParamsTrait
* @param string $templateName Name of template to which the param applies;
* use TEMPLATE_ALL to apply to all templates.
* @param string $param Param name.
* @param mixed $value
* @param mixed $value
* @throws Exception\InvalidArgumentException
*/
public function addDefaultParam(string $templateName, string $param, $value) : void
public function addDefaultParam(string $templateName, string $param, $value): void
{
if (! $templateName) {
throw new Exception\InvalidArgumentException('$templateName must be a non-empty string');
Expand All @@ -62,9 +60,9 @@ public function addDefaultParam(string $templateName, string $param, $value) : v
/**
* Returns merged global, template-specific and given params
*/
private function mergeParams(string $template, array $params) : array
private function mergeParams(string $template, array $params): array
{
$globalDefaults = $this->defaultParams[TemplateRendererInterface::TEMPLATE_ALL] ?? [];
$globalDefaults = $this->defaultParams[TemplateRendererInterface::TEMPLATE_ALL] ?? [];
$templateDefaults = $this->defaultParams[$template] ?? [];

return array_replace_recursive($globalDefaults, $templateDefaults, $params);
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Mezzio\Template\Exception;

class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
use InvalidArgumentException as SplInvalidArgumentException;

class InvalidArgumentException extends SplInvalidArgumentException implements ExceptionInterface
{
}
16 changes: 6 additions & 10 deletions src/TemplatePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@

class TemplatePath
{
/**
* @var string
*/
/** @var string */
protected $path;

/**
* @var null|string
*/
/** @var null|string */
protected $namespace;

public function __construct(string $path, string $namespace = null)
public function __construct(string $path, ?string $namespace = null)
{
$this->path = $path;
$this->namespace = $namespace;
Expand All @@ -31,23 +27,23 @@ public function __construct(string $path, string $namespace = null)
/**
* Casts to string by returning the path only.
*/
public function __toString() : string
public function __toString(): string
{
return $this->path;
}

/**
* Get the namespace
*/
public function getNamespace() : ?string
public function getNamespace(): ?string
{
return $this->namespace;
}

/**
* Get the path
*/
public function getPath() : string
public function getPath(): string
{
return $this->path;
}
Expand Down
10 changes: 5 additions & 5 deletions src/TemplateRendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ interface TemplateRendererInterface
*
* @param array|object $params
*/
public function render(string $name, $params = []) : string;
public function render(string $name, $params = []): string;

/**
* Add a template path to the engine.
*
* Adds a template path, with optional namespace the templates in that path
* provide.
*/
public function addPath(string $path, string $namespace = null) : void;
public function addPath(string $path, ?string $namespace = null): void;

/**
* Retrieve configured paths from the engine.
*
* @return TemplatePath[]
*/
public function getPaths() : array;
public function getPaths(): array;

/**
* Add a default parameter to use with a template.
Expand All @@ -62,7 +62,7 @@ public function getPaths() : array;
* @param string $templateName Name of template to which the param applies;
* use TEMPLATE_ALL to apply to all templates.
* @param string $param Param name.
* @param mixed $value
* @param mixed $value
*/
public function addDefaultParam(string $templateName, string $param, $value) : void;
public function addDefaultParam(string $templateName, string $param, $value): void;
}
5 changes: 2 additions & 3 deletions test/ArrayParametersTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ArrayParametersTraitTest extends TestCase
/** @var TestAsset\ArrayParameters */
private $subject;

public function setUp()
protected function setUp(): void
{
$this->subject = new TestAsset\ArrayParameters();
}
Expand Down Expand Up @@ -74,8 +74,7 @@ public function nonNullScalarParameters()

/**
* @dataProvider nonNullScalarParameters
*
* @param mixed $scalar
* @param mixed $scalar
* @param string $expectedString
*/
public function testNonNullScalarsRaiseAnException($scalar, $expectedString)
Expand Down
10 changes: 3 additions & 7 deletions test/DefaultParamsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@

class DefaultParamsTraitTest extends TestCase
{
/**
* @var ArrayParameters
*/
/** @var ArrayParameters */
private $arrayParams;

/**
* @var DefaultParameters
*/
/** @var DefaultParameters */
private $defaultParams;

protected function setUp()
protected function setUp(): void
{
$this->arrayParams = new ArrayParameters();
$this->defaultParams = new DefaultParameters();
Expand Down
6 changes: 3 additions & 3 deletions test/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class ExceptionTest extends TestCase
{
public function exception() : Generator
public function exception(): Generator
{
$namespace = substr(ExceptionInterface::class, 0, strrpos(ExceptionInterface::class, '\\') + 1);

Expand All @@ -37,9 +37,9 @@ public function exception() : Generator
/**
* @dataProvider exception
*/
public function testExceptionIsInstanceOfExceptionInterface(string $exception) : void
public function testExceptionIsInstanceOfExceptionInterface(string $exception): void
{
self::assertContains('Exception', $exception);
self::assertStringContainsString('Exception', $exception);
self::assertTrue(is_a($exception, ExceptionInterface::class, true));
}
}
16 changes: 10 additions & 6 deletions test/TemplatePathAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@

trait TemplatePathAssertionsTrait
{
public function assertTemplatePath($path, TemplatePath $templatePath, $message = null)
/** @param mixed $path */
public function assertTemplatePath($path, TemplatePath $templatePath, ?string $message = null)
{
$message = $message ?: sprintf('Failed to assert TemplatePath contained path %s', $path);
$this->assertEquals($path, $templatePath->getPath(), $message);
}

public function assertTemplatePathString($path, TemplatePath $templatePath, $message = null)
/** @param mixed $path */
public function assertTemplatePathString($path, TemplatePath $templatePath, ?string $message = null)
{
$message = $message ?: sprintf('Failed to assert TemplatePath casts to string path %s', $path);
$this->assertEquals($path, (string) $templatePath, $message);
}

public function assertTemplatePathNamespace($namespace, TemplatePath $templatePath, $message = null)
/** @param mixed $namespace */
public function assertTemplatePathNamespace($namespace, TemplatePath $templatePath, ?string $message = null)
{
$message = $message ?: sprintf(
'Failed to assert TemplatePath namespace matched %s',
Expand All @@ -38,16 +41,17 @@ public function assertTemplatePathNamespace($namespace, TemplatePath $templatePa
$this->assertEquals($namespace, $templatePath->getNamespace(), $message);
}

public function assertEmptyTemplatePathNamespace(TemplatePath $templatePath, $message = null)
public function assertEmptyTemplatePathNamespace(TemplatePath $templatePath, ?string $message = null)
{
$message = $message ?: 'Failed to assert TemplatePath namespace was empty';
$this->assertEmpty($templatePath->getNamespace(), $message);
}

public function assertEqualTemplatePath(TemplatePath $expected, TemplatePath $received, $message = null)
public function assertEqualTemplatePath(TemplatePath $expected, TemplatePath $received, ?string $message = null)
{
$message = $message ?: 'Failed to assert TemplatePaths are equal';
if ($expected->getPath() !== $received->getPath()
if (
$expected->getPath() !== $received->getPath()
|| $expected->getNamespace() !== $received->getNamespace()
) {
$this->fail($message);
Expand Down
3 changes: 2 additions & 1 deletion test/TestAsset/ArrayParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ArrayParameters
{
use ArrayParametersTrait;

public function normalize($params)
/** @param mixed $params */
public function normalize($params): array
{
return $this->normalizeParams($params);
}
Expand Down
Loading