Skip to content

Commit

Permalink
PHP 8.1 Language features
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Aug 28, 2023
1 parent 16aa1bc commit b47c6c7
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 49 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2022 (c) Jeroen van den Enden
Copyright 2023 (c) Jeroen van den Enden

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions src/CacheAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
final class CacheAsset extends AbstractAsset
{
public function __construct(
private AssetInterface $asset,
private CacheItemPoolInterface $cache,
private string $key,
private readonly AssetInterface $asset,
private readonly CacheItemPoolInterface $cache,
private readonly string $key,
/** @var array<string> */
private array $tags = [],
private int $expiresAfter = 0,
private bool $clear = false
private readonly array $tags = [],
private readonly int $expiresAfter = 0,
private readonly bool $clear = false
) {
}

Expand Down
10 changes: 4 additions & 6 deletions src/CallbackAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

final class CallbackAsset extends AbstractAsset
{
/** @var callable */
private $callable;

public function __construct(callable $callable)
{
$this->callable = $callable;
public function __construct(
/** @var callable */
private readonly mixed $callable
) {
}

public function getData(): string
Expand Down
16 changes: 8 additions & 8 deletions src/ControllerAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
final class ControllerAsset extends AbstractAsset
{
public function __construct(
private HttpKernelInterface $kernel,
private RequestStack $requestStack,
private string $controller,
private readonly HttpKernelInterface $kernel,
private readonly RequestStack $requestStack,
private readonly string $controller,
/** @var array<mixed> */
private array $controllerParameters = []
private readonly array $controllerParameters = []
) {
}

Expand All @@ -29,12 +29,12 @@ public function getData(): string
throw new InvalidRequestException('Could not determine current request');
}

$this->controllerParameters['_forwarded'] = $request->attributes;
$this->controllerParameters['_controller'] = $this->controller;
$subRequest = $request->duplicate([], null, $this->controllerParameters);
$subRequest = $request->duplicate([], null, $this->controllerParameters + [
'_forwarded' => $request->attributes,
'_controller' => $this->controller,
]);

$response = $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
/** @psalm-suppress ReservedWord */
$data = $response->getContent();

if (!is_string($data)) {
Expand Down
2 changes: 1 addition & 1 deletion src/DataAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
final class DataAsset extends AbstractAsset
{
public function __construct(
private string $data
private readonly string $data
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Factory/Adapter/AbstractFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
abstract class AbstractFactoryAdapter implements FactoryAdapterInterface
{
public function __construct(
public int $guesserPriority = 1
public readonly int $guesserPriority = 1
) {
}

Expand All @@ -24,7 +24,7 @@ public function isValidGuess(array $options): bool
{
try {
$this->getOptionsResolver()->resolve($options);
} catch (\Exception $exception) {
} catch (\Exception) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Factory/Adapter/CacheAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
final class CacheAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function __construct(
private CacheItemPoolInterface $cache,
private AssetFactory $assetFactory
private readonly CacheItemPoolInterface $cache,
private readonly AssetFactory $assetFactory
) {
parent::__construct(0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/Adapter/ControllerAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
final class ControllerAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function __construct(
private HttpKernelInterface $kernel,
private RequestStack $requestStack
private readonly HttpKernelInterface $kernel,
private readonly RequestStack $requestStack
) {
parent::__construct(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Adapter/TemplateAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
final class TemplateAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function __construct(
private Environment $renderer
private readonly Environment $renderer
) {
parent::__construct(1);
}
Expand Down
16 changes: 6 additions & 10 deletions src/Factory/AssetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
use Endroid\Asset\Factory\Adapter\FactoryAdapterInterface;
use Endroid\Asset\Guesser\ClassGuesser;

class AssetFactory
final class AssetFactory
{
private ClassGuesser $classGuesser;

/** @var array<string, FactoryAdapterInterface> */
private array $factories;

public function __construct(ClassGuesser $classGuesser = null)
{
$this->classGuesser = $classGuesser instanceof ClassGuesser ? $classGuesser : new ClassGuesser();
$this->factories = [];
public function __construct(
private readonly ClassGuesser $classGuesser = new ClassGuesser(),
/** @var array<string, FactoryAdapterInterface> */
private array $factories = []
) {
}

/** @param iterable<FactoryAdapterInterface> $factories */
Expand Down
2 changes: 1 addition & 1 deletion src/FileAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
final class FileAsset extends AbstractAsset
{
public function __construct(
private string $path
private readonly string $path
) {
}

Expand Down
7 changes: 5 additions & 2 deletions src/Guesser/ClassGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

final class ClassGuesser
{
/** @var array<string, FactoryAdapterInterface> */
private array $factories = [];
public function __construct(
/** @var array<string, FactoryAdapterInterface> */
private array $factories = []
) {
}

public function addFactory(FactoryAdapterInterface $factory): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/MultiUrlAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class MultiUrlAsset extends AbstractAsset
{
public function __construct(
/** @var array<string> */
private array $urls
private readonly array $urls
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/TemplateAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
final class TemplateAsset extends AbstractAsset
{
public function __construct(

Check failure on line 11 in src/TemplateAsset.php

View workflow job for this annotation

GitHub Actions / build (8.1)

Method Endroid\Asset\TemplateAsset::__construct() has parameter $parameters with no value type specified in iterable type array.

Check failure on line 11 in src/TemplateAsset.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Method Endroid\Asset\TemplateAsset::__construct() has parameter $parameters with no value type specified in iterable type array.

Check failure on line 11 in src/TemplateAsset.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Method Endroid\Asset\TemplateAsset::__construct() has parameter $parameters with no value type specified in iterable type array.
private Environment $templating,
private string $template,
/** @var array<string> */
private array $parameters = []
private readonly Environment $templating,
private readonly string $template,
/** @param array<mixed> */
private readonly array $parameters = []
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/UrlAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
final class UrlAsset extends AbstractAsset
{
public function __construct(
private string $url
private readonly string $url
) {
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Factory/AssetFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Endroid\Asset\Factory\AssetFactory;
use PHPUnit\Framework\TestCase;

class AssetFactoryTest extends TestCase
final class AssetFactoryTest extends TestCase
{
/**
* @testdox Create data asset via factory
Expand Down

0 comments on commit b47c6c7

Please sign in to comment.