Skip to content

Commit

Permalink
Merge pull request #28 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 12, 2022
2 parents 3b9b04d + 963b7e5 commit ac47b19
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 40 deletions.
5 changes: 1 addition & 4 deletions src/ServerUrlMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

class ServerUrlMiddleware implements MiddlewareInterface
{
private ServerUrlHelper $helper;

public function __construct(ServerUrlHelper $helper)
public function __construct(private ServerUrlHelper $helper)
{
$this->helper = $helper;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Template/TemplateVariableContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ public function has(string $key): bool
}

/**
* @param mixed $value
* @return self Returns a new instance that contains the given key/value pair
*/
public function with(string $key, $value): self
public function with(string $key, mixed $value): self
{
$new = clone $this;
$new->variables[$key] = $value;
Expand Down
6 changes: 1 addition & 5 deletions src/UrlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ class UrlHelper

private ?ServerRequestInterface $request = null;

private RouterInterface $router;

public function __construct(RouterInterface $router)
public function __construct(private RouterInterface $router)
{
$this->router = $router;
}

/**
Expand Down Expand Up @@ -226,7 +223,6 @@ private function mergeParams(string $route, RouteResult $result, array $params):
* @param string $route Route name
* @param RouteResult $result RouteResult instance
* @param array $params Params to be merged with request params
* @return array
*/
private function mergeQueryParams(string $route, RouteResult $result, array $params): array
{
Expand Down
15 changes: 6 additions & 9 deletions src/UrlHelperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@

class UrlHelperFactory
{
/** @var string Base path for the URL helper */
private string $basePath;

private string $routerServiceName;

/**
* Allow serialization
*/
Expand All @@ -31,11 +26,13 @@ public static function __set_state(array $data): self
* Allows varying behavior per-instance.
*
* Defaults to '/' for the base path, and the FQCN of the RouterInterface.
*
* @param string $basePath Base path for the URL helper
*/
public function __construct(string $basePath = '/', string $routerServiceName = RouterInterface::class)
{
$this->basePath = $basePath;
$this->routerServiceName = $routerServiceName;
public function __construct(
private string $basePath = '/',
private string $routerServiceName = RouterInterface::class
) {
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/UrlHelperMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
*/
class UrlHelperMiddleware implements MiddlewareInterface
{
private UrlHelper $helper;

public function __construct(UrlHelper $helper)
public function __construct(private UrlHelper $helper)
{
$this->helper = $helper;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/UrlHelperMiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

class UrlHelperMiddlewareFactory
{
private string $urlHelperServiceName;

/**
* Allow serialization
*/
Expand All @@ -25,9 +23,8 @@ public static function __set_state(array $data): self
/**
* Allow varying behavior based on URL helper service name.
*/
public function __construct(string $urlHelperServiceName = UrlHelper::class)
public function __construct(private string $urlHelperServiceName = UrlHelper::class)
{
$this->urlHelperServiceName = $urlHelperServiceName;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions test/AttributeAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@

trait AttributeAssertionsTrait
{
/** @param mixed $expected */
public static function assertAttributeSame($expected, string $attribute, object $object): void
public static function assertAttributeSame(mixed $expected, string $attribute, object $object): void
{
$r = new ReflectionProperty($object, $attribute);
$r->setAccessible(true);

self::assertSame($expected, $r->getValue($object));
}

/** @param mixed $expected */
public static function assertAttributeEquals($expected, string $attribute, object $object): void
public static function assertAttributeEquals(mixed $expected, string $attribute, object $object): void
{
$r = new ReflectionProperty($object, $attribute);
$r->setAccessible(true);

self::assertEquals($expected, $r->getValue($object));
}

/** @param mixed $expected */
public static function assertAttributeContains($expected, string $attribute, object $object): void
public static function assertAttributeContains(mixed $expected, string $attribute, object $object): void
{
$r = new ReflectionProperty($object, $attribute);
$r->setAccessible(true);
Expand Down
5 changes: 1 addition & 4 deletions test/ContentLengthMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ protected function setUp(): void
private function handlerWillReturnResponse(ResponseInterface $response): RequestHandlerInterface
{
return new class ($response) implements RequestHandlerInterface {
public ResponseInterface $response;

public function __construct(ResponseInterface $response)
public function __construct(public ResponseInterface $response)
{
$this->response = $response;
}

public function handle(ServerRequestInterface $request): ResponseInterface
Expand Down
3 changes: 1 addition & 2 deletions test/UrlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,8 @@ public function invalidBasePathProvider(): array

/**
* @dataProvider invalidBasePathProvider
* @param mixed $basePath
*/
public function testThrowsExceptionWhenSettingInvalidBasePaths($basePath): void
public function testThrowsExceptionWhenSettingInvalidBasePaths(mixed $basePath): void
{
$this->expectException(TypeError::class);

Expand Down

0 comments on commit ac47b19

Please sign in to comment.