Skip to content

Commit

Permalink
Readonly classes
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Oct 19, 2024
1 parent 7b081ff commit 9bfc8e9
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Endroid\Asset;

abstract class AbstractAsset implements AssetInterface
abstract readonly class AbstractAsset implements AssetInterface
{
abstract public function getData(): string;

Expand Down
14 changes: 7 additions & 7 deletions src/CacheAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Contracts\Cache\ItemInterface;

final class CacheAsset extends AbstractAsset
final readonly class CacheAsset extends AbstractAsset
{
public function __construct(
private readonly AssetInterface $asset,
private readonly CacheItemPoolInterface $cache,
private readonly string $key,
private AssetInterface $asset,
private CacheItemPoolInterface $cache,
private string $key,
/** @var array<string> */
private readonly array $tags = [],
private readonly int $expiresAfter = 0,
private readonly bool $clear = false
private array $tags = [],
private int $expiresAfter = 0,
private bool $clear = false
) {
}

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

namespace Endroid\Asset;

final class CallbackAsset extends AbstractAsset
final readonly class CallbackAsset extends AbstractAsset
{
public function __construct(
/** @var callable */
private readonly mixed $callable
private mixed $callable
) {
}

Expand Down
10 changes: 5 additions & 5 deletions src/ControllerAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\HttpKernelInterface;

final class ControllerAsset extends AbstractAsset
final readonly class ControllerAsset extends AbstractAsset
{
public function __construct(
private readonly HttpKernelInterface $kernel,
private readonly RequestStack $requestStack,
private readonly string $controller,
private HttpKernelInterface $kernel,
private RequestStack $requestStack,
private string $controller,
/** @var array<mixed> */
private readonly array $controllerParameters = []
private array $controllerParameters = []
) {
}

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

namespace Endroid\Asset;

final class DataAsset extends AbstractAsset
final readonly class DataAsset extends AbstractAsset
{
public function __construct(
private readonly string $data
private 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 @@ -7,10 +7,10 @@
use Endroid\Asset\Exception\UndefinedAssetClassException;
use Symfony\Component\OptionsResolver\OptionsResolver;

abstract class AbstractFactoryAdapter implements FactoryAdapterInterface
abstract readonly class AbstractFactoryAdapter implements FactoryAdapterInterface
{
public function __construct(
public readonly int $guesserPriority = 1
public int $guesserPriority = 1
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Factory/Adapter/CacheAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class CacheAssetFactoryAdapter extends AbstractFactoryAdapter
final readonly class CacheAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function __construct(
private readonly CacheItemPoolInterface $cache,
private readonly AssetFactory $assetFactory
private CacheItemPoolInterface $cache,
private AssetFactory $assetFactory
) {
parent::__construct(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Adapter/CallbackAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Endroid\Asset\CallbackAsset;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class CallbackAssetFactoryAdapter extends AbstractFactoryAdapter
final readonly class CallbackAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function configureOptions(OptionsResolver $resolver): void
{
Expand Down
6 changes: 3 additions & 3 deletions src/Factory/Adapter/ControllerAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class ControllerAssetFactoryAdapter extends AbstractFactoryAdapter
final readonly class ControllerAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function __construct(
private readonly HttpKernelInterface $kernel,
private readonly RequestStack $requestStack
private HttpKernelInterface $kernel,
private RequestStack $requestStack
) {
parent::__construct(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Adapter/DataAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Endroid\Asset\DataAsset;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class DataAssetFactoryAdapter extends AbstractFactoryAdapter
final readonly class DataAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function configureOptions(OptionsResolver $resolver): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Adapter/FileAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Endroid\Asset\FileAsset;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class FileAssetFactoryAdapter extends AbstractFactoryAdapter
final readonly class FileAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function configureOptions(OptionsResolver $resolver): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Adapter/MultiUrlAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Endroid\Asset\MultiUrlAsset;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class MultiUrlAssetFactoryAdapter extends AbstractFactoryAdapter
final readonly class MultiUrlAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function configureOptions(OptionsResolver $resolver): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/Adapter/TemplateAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

final class TemplateAssetFactoryAdapter extends AbstractFactoryAdapter
final readonly class TemplateAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function __construct(
private readonly Environment $renderer
private Environment $renderer
) {
parent::__construct(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/Adapter/UrlAssetFactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Endroid\Asset\UrlAsset;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class UrlAssetFactoryAdapter extends AbstractFactoryAdapter
final readonly class UrlAssetFactoryAdapter extends AbstractFactoryAdapter
{
public function configureOptions(OptionsResolver $resolver): void
{
Expand Down
6 changes: 2 additions & 4 deletions src/Factory/AssetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function addFactory(FactoryAdapterInterface $factory): void
}

/** @param array<mixed> $options */
public function create(?string $className = null, array $options = []): AssetInterface
public function create(string $className = null, array $options = []): AssetInterface
{
if (null === $className) {
$className = $this->classGuesser->guessClassName($options);
Expand All @@ -43,8 +43,6 @@ public function create(?string $className = null, array $options = []): AssetInt
throw new UnsupportedAssetClassException(sprintf('Asset class "%s" is not supported', $className));
}

$asset = $this->factories[$className]->create($options);

return $asset;
return $this->factories[$className]->create($options);
}
}
4 changes: 2 additions & 2 deletions src/FileAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Endroid\Asset;

final class FileAsset extends AbstractAsset
final readonly class FileAsset extends AbstractAsset
{
public function __construct(
private readonly string $path
private string $path
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/MultiUrlAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Endroid\Asset;

final class MultiUrlAsset extends AbstractAsset
final readonly class MultiUrlAsset extends AbstractAsset
{
public function __construct(
/** @var array<string> */
private readonly array $urls
private 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 @@ -6,13 +6,13 @@

use Twig\Environment;

final class TemplateAsset extends AbstractAsset
final readonly class TemplateAsset extends AbstractAsset
{
public function __construct(
private readonly Environment $templating,
private readonly string $template,
private Environment $templating,
private string $template,
/** @var array<mixed> */
private readonly array $parameters = []
private array $parameters = []
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/UrlAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpFoundation\Request;

final class UrlAsset extends AbstractAsset
final readonly class UrlAsset extends AbstractAsset
{
public function __construct(
private readonly string $url
private string $url
) {
}

Expand Down

0 comments on commit 9bfc8e9

Please sign in to comment.