Skip to content

Use constructor property promotion in module UrlRewriteGraphQl #37026

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

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
*/
class EntityDataProviderComposite implements EntityDataProviderInterface
{
/**
* @var EntityDataProviderInterface[]
*/
private $dataProviders;

/**
* @param EntityDataProviderInterface[] $dataProviders
*/
public function __construct(array $dataProviders = [])
{
$this->dataProviders = $dataProviders;
public function __construct(
private readonly array $dataProviders = []
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,16 @@

abstract class AbstractEntityUrl implements ResolverInterface
{
/**
* @var UrlFinderInterface
*/
private $urlFinder;

/**
* @var CustomUrlLocatorInterface
*/
private $customUrlLocator;

/**
* @var Uid
*/
private $idEncoder;

/**
* @param UrlFinderInterface $urlFinder
* @param CustomUrlLocatorInterface $customUrlLocator
* @param Uid $idEncoder
*/
public function __construct(
UrlFinderInterface $urlFinder,
CustomUrlLocatorInterface $customUrlLocator,
Uid $idEncoder
private readonly UrlFinderInterface $urlFinder,
private readonly CustomUrlLocatorInterface $customUrlLocator,
private readonly Uid $idEncoder
) {
$this->urlFinder = $urlFinder;
$this->customUrlLocator = $customUrlLocator;
$this->idEncoder = $idEncoder;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions app/code/Magento/UrlRewriteGraphQl/Model/Resolver/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

class Route extends AbstractEntityUrl implements ResolverInterface
{
/**
* @var EntityDataProviderComposite
*/
private $entityDataProviderComposite;

/**
* @param UrlFinderInterface $urlFinder
* @param CustomUrlLocatorInterface $customUrlLocator
Expand All @@ -31,11 +26,10 @@ class Route extends AbstractEntityUrl implements ResolverInterface
public function __construct(
UrlFinderInterface $urlFinder,
CustomUrlLocatorInterface $customUrlLocator,
EntityDataProviderComposite $entityDataProviderComposite,
private readonly EntityDataProviderComposite $entityDataProviderComposite,
Uid $idEncoder
) {
parent::__construct($urlFinder, $customUrlLocator, $idEncoder);
$this->entityDataProviderComposite = $entityDataProviderComposite;
}

/**
Expand Down
32 changes: 4 additions & 28 deletions app/code/Magento/UrlRewriteGraphQl/Model/Resolver/UrlRewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,18 @@
*/
class UrlRewrite implements ResolverInterface
{
/**
* @var UrlFinderInterface
*/
private $urlFinder;

/**
* @var array
*/
private $entityTypeMapping;

/**
* @var MetadataPool
*/
private $metadataPool;

/**
* @var TypeResolver
*/
private $typeResolver;

/**
* @param UrlFinderInterface $urlFinder
* @param TypeResolver $typeResolver
* @param MetadataPool $metadataPool
* @param array $entityTypeMapping
*/
public function __construct(
UrlFinderInterface $urlFinder,
TypeResolver $typeResolver,
MetadataPool $metadataPool,
array $entityTypeMapping = []
private readonly UrlFinderInterface $urlFinder,
private readonly TypeResolver $typeResolver,
private readonly MetadataPool $metadataPool,
private readonly array $entityTypeMapping = []
) {
$this->urlFinder = $urlFinder;
$this->typeResolver = $typeResolver;
$this->metadataPool = $metadataPool;
$this->entityTypeMapping = $entityTypeMapping;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@
*/
class CustomUrlLocator implements CustomUrlLocatorInterface
{
/**
* @var CustomUrlLocatorInterface[]
*/
private $urlLocators;

/**
* @param CustomUrlLocatorInterface[] $urlLocators
*/
public function __construct(array $urlLocators = [])
{
$this->urlLocators = $urlLocators;
public function __construct(
private readonly array $urlLocators = []
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@
*/
class UrlResolverIdentity implements IdentityInterface
{
/**
* @var IdentityInterface[]
*/
private $urlResolverIdentities = [];

/**
* @param IdentityInterface[] $urlResolverIdentities
*/
public function __construct(
array $urlResolverIdentities
private readonly array $urlResolverIdentities = []
) {
$this->urlResolverIdentities = $urlResolverIdentities;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,14 @@ class RoutableInterfaceTypeResolver implements TypeResolverInterface
{
private const DEFAULT_TYPE = 'RoutableUrl';

/**
* @var TypeResolverInterface[]
*/
private array $productTypeNameResolvers;

/**
* @var string
*/
private string $defaultType;

/**
* @param TypeResolverInterface[] $productTypeNameResolvers
* @param string $defaultType
*/
public function __construct(
array $productTypeNameResolvers = [],
string $defaultType = self::DEFAULT_TYPE
private readonly array $productTypeNameResolvers = [],
private readonly string $defaultType = self::DEFAULT_TYPE
) {
$this->productTypeNameResolvers = $productTypeNameResolvers;
$this->defaultType = $defaultType;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/UrlRewriteGraphQl/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_UrlRewriteGraphQl', __DIR__);
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Magento_UrlRewriteGraphQl',
__DIR__
);