Skip to content

Commit

Permalink
Merge pull request #22 from samsonasik/apply-php80
Browse files Browse the repository at this point in the history
Apply PHP 8.0 Syntax and constructor promotion
  • Loading branch information
Ocramius authored Oct 10, 2022
2 parents 046519d + eeef357 commit ac7c34a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
3 changes: 1 addition & 2 deletions src/ArrayParametersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ trait ArrayParametersTrait
* using PHP's type casting
* - scalar values result in an exception
*
* @param mixed $params
* @throws Exception\InvalidArgumentException
*/
private function normalizeParams($params): array
private function normalizeParams(mixed $params): array
{
if (null === $params) {
return [];
Expand Down
3 changes: 1 addition & 2 deletions src/DefaultParamsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ 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
* @throws Exception\InvalidArgumentException
*/
public function addDefaultParam(string $templateName, string $param, $value): void
public function addDefaultParam(string $templateName, string $param, mixed $value): void
{
if (! $templateName) {
throw new Exception\InvalidArgumentException('$templateName must be a non-empty string');
Expand Down
14 changes: 4 additions & 10 deletions src/TemplatePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@

namespace Mezzio\Template;

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

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

public function __construct(string $path, ?string $namespace = null)
class TemplatePath implements Stringable
{
public function __construct(protected string $path, protected ?string $namespace = null)
{
$this->path = $path;
$this->namespace = $namespace;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/TemplateRendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ 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
*/
public function addDefaultParam(string $templateName, string $param, $value): void;
public function addDefaultParam(string $templateName, string $param, mixed $value): void;
}
3 changes: 1 addition & 2 deletions test/ArrayParametersTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ public function nonNullScalarParameters(): array

/**
* @dataProvider nonNullScalarParameters
* @param mixed $scalar
* @param string $expectedString
*/
public function testNonNullScalarsRaiseAnException($scalar, $expectedString): void
public function testNonNullScalarsRaiseAnException(mixed $scalar, $expectedString): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage($expectedString);
Expand Down
14 changes: 7 additions & 7 deletions test/TemplatePathAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@

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

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

/** @param mixed $namespace */
public function assertTemplatePathNamespace($namespace, TemplatePath $templatePath, ?string $message = null): void
{
public function assertTemplatePathNamespace(
mixed $namespace,
TemplatePath $templatePath,
?string $message = null
): void {
$message = $message ?: sprintf(
'Failed to assert TemplatePath namespace matched %s',
var_export($namespace, true)
Expand Down

0 comments on commit ac7c34a

Please sign in to comment.