Skip to content

Commit

Permalink
NEXT-25051 - Run rector Core
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Jan 25, 2023
1 parent 0cb6d8d commit 4f0cc98
Show file tree
Hide file tree
Showing 2,586 changed files with 8,381 additions and 24,451 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parameters:
treatPhpDocTypesAsCertain: false
checkMissingIterableValueType: true
inferPrivatePropertyTypeFromConstructor: true
reportUnmatchedIgnoredErrors: true # Could be set to false if necessary during PHPStan update
reportUnmatchedIgnoredErrors: false # Could be set to false if necessary during PHPStan update
tmpDir: var/cache/phpstan
paths:
- src
Expand Down
5 changes: 1 addition & 4 deletions src/Core/Checkout/Cart/Address/AddressValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*/
class AddressValidator implements CartValidatorInterface, ResetInterface
{
private EntityRepository $repository;

/**
* @var array<string, bool>
*/
Expand All @@ -31,9 +29,8 @@ class AddressValidator implements CartValidatorInterface, ResetInterface
/**
* @internal
*/
public function __construct(EntityRepository $repository)
public function __construct(private readonly EntityRepository $repository)
{
$this->repository = $repository;
}

public function validate(Cart $cart, ErrorCollection $errors, SalesChannelContext $context): void
Expand Down
14 changes: 1 addition & 13 deletions src/Core/Checkout/Cart/Address/Error/AddressValidationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,8 @@ class AddressValidationError extends Error
{
private const KEY = 'address-invalid';

/**
* @var bool
*/
private $isBillingAddress;

/**
* @var ConstraintViolationList
*/
private $violations;

public function __construct(bool $isBillingAddress, ConstraintViolationList $violations)
public function __construct(private readonly bool $isBillingAddress, private readonly ConstraintViolationList $violations)
{
$this->isBillingAddress = $isBillingAddress;
$this->violations = $violations;
$this->message = sprintf(
'Please check your %s address for missing or invalid values.',
$isBillingAddress ? 'billing' : 'shipping'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@ class BillingAddressBlockedError extends Error
{
private const KEY = 'billing-address-blocked';

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

public function __construct(string $name)
public function __construct(private readonly string $name)
{
$this->name = $name;

$this->message = sprintf(
'Billings to billing address %s are not possible.',
$name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@ class ShippingAddressBlockedError extends Error
{
private const KEY = 'shipping-address-blocked';

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

public function __construct(string $name)
public function __construct(private readonly string $name)
{
$this->name = $name;

$this->message = sprintf(
'Shippings to shipping address %s are not possible.',
$name
Expand Down
8 changes: 1 addition & 7 deletions src/Core/Checkout/Cart/ApiOrderCartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
*/
class ApiOrderCartService
{
protected CartService $cartService;

protected SalesChannelContextPersister $contextPersister;

/**
* @internal
*/
public function __construct(CartService $cartService, SalesChannelContextPersister $contextPersister)
public function __construct(protected CartService $cartService, protected SalesChannelContextPersister $contextPersister)
{
$this->cartService = $cartService;
$this->contextPersister = $contextPersister;
}

public function updateShippingCosts(CalculatedPrice $calculatedPrice, SalesChannelContext $context): Cart
Expand Down
14 changes: 3 additions & 11 deletions src/Core/Checkout/Cart/CachedRuleLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@
*/
class CachedRuleLoader extends AbstractRuleLoader
{
public const CACHE_KEY = 'cart_rules';

private AbstractRuleLoader $decorated;

private CacheInterface $cache;
final public const CACHE_KEY = 'cart_rules';

/**
* @internal
*/
public function __construct(AbstractRuleLoader $decorated, CacheInterface $cache)
public function __construct(private readonly AbstractRuleLoader $decorated, private readonly CacheInterface $cache)
{
$this->decorated = $decorated;
$this->cache = $cache;
}

public function getDecorated(): AbstractRuleLoader
Expand All @@ -33,8 +27,6 @@ public function getDecorated(): AbstractRuleLoader

public function load(Context $context): RuleCollection
{
return $this->cache->get(self::CACHE_KEY, function () use ($context): RuleCollection {
return $this->decorated->load($context);
});
return $this->cache->get(self::CACHE_KEY, fn (): RuleCollection => $this->decorated->load($context));
}
}
16 changes: 2 additions & 14 deletions src/Core/Checkout/Cart/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,11 @@
*/
class Calculator
{
private QuantityPriceCalculator $quantityPriceCalculator;

private PercentagePriceCalculator $percentagePriceCalculator;

private AbsolutePriceCalculator $absolutePriceCalculator;

/**
* @internal
*/
public function __construct(
QuantityPriceCalculator $quantityPriceCalculator,
PercentagePriceCalculator $percentagePriceCalculator,
AbsolutePriceCalculator $absolutePriceCalculator
) {
$this->quantityPriceCalculator = $quantityPriceCalculator;
$this->percentagePriceCalculator = $percentagePriceCalculator;
$this->absolutePriceCalculator = $absolutePriceCalculator;
public function __construct(private readonly QuantityPriceCalculator $quantityPriceCalculator, private readonly PercentagePriceCalculator $percentagePriceCalculator, private readonly AbsolutePriceCalculator $absolutePriceCalculator)
{
}

public function calculate(LineItemCollection $lineItems, SalesChannelContext $context, CartBehavior $behavior): LineItemCollection
Expand Down
5 changes: 1 addition & 4 deletions src/Core/Checkout/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class Cart extends Struct
{
use StateAwareTrait;

protected string $token;

protected CartPrice $price;

protected LineItemCollection $lineItems;
Expand Down Expand Up @@ -55,9 +53,8 @@ class Cart extends Struct
/**
* @internal
*/
public function __construct(string $token)
public function __construct(protected string $token)
{
$this->token = $token;
$this->lineItems = new LineItemCollection();
$this->transactions = new TransactionCollection();
$this->errors = new ErrorCollection();
Expand Down
11 changes: 1 addition & 10 deletions src/Core/Checkout/Cart/CartBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@
*/
class CartBehavior extends Struct
{
/**
* @var array<mixed>
*/
private array $permissions = [];

private bool $hookAware;

/**
* @param array<mixed> $permissions
*/
public function __construct(array $permissions = [], bool $hookAware = true)
public function __construct(private readonly array $permissions = [], private bool $hookAware = true)
{
$this->permissions = $permissions;
$this->hookAware = $hookAware;
}

public function hasPermission(string $permission): bool
Expand Down
8 changes: 1 addition & 7 deletions src/Core/Checkout/Cart/CartCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@
*/
class CartCalculator
{
/**
* @var CartRuleLoader
*/
private $cartRuleLoader;

public function __construct(CartRuleLoader $cartRuleLoader)
public function __construct(private readonly CartRuleLoader $cartRuleLoader)
{
$this->cartRuleLoader = $cartRuleLoader;
}

public function calculate(Cart $cart, SalesChannelContext $context): Cart
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Checkout/Cart/CartEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class CartEvents
/**
* @Event("Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent")
*/
public const CHECKOUT_ORDER_PLACED = 'checkout.order.placed';
final public const CHECKOUT_ORDER_PLACED = 'checkout.order.placed';
}
18 changes: 3 additions & 15 deletions src/Core/Checkout/Cart/CartPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,11 @@
*/
class CartPersister extends AbstractCartPersister
{
private Connection $connection;

private EventDispatcherInterface $eventDispatcher;

private CartSerializationCleaner $cartSerializationCleaner;

private bool $compress;

/**
* @internal
*/
public function __construct(Connection $connection, EventDispatcherInterface $eventDispatcher, CartSerializationCleaner $cartSerializationCleaner, bool $compress)
public function __construct(private readonly Connection $connection, private readonly EventDispatcherInterface $eventDispatcher, private readonly CartSerializationCleaner $cartSerializationCleaner, private readonly bool $compress)
{
$this->connection = $connection;
$this->eventDispatcher = $eventDispatcher;
$this->cartSerializationCleaner = $cartSerializationCleaner;
$this->compress = $compress;
}

public function getDecorated(): AbstractCartPersister
Expand Down Expand Up @@ -73,7 +61,7 @@ public function load(string $token, SalesChannelContext $context): Cart
}

$cart->setToken($token);
$cart->setRuleIds(json_decode((string) $content['rule_ids'], true) ?? []);
$cart->setRuleIds(json_decode((string) $content['rule_ids'], true, 512, \JSON_THROW_ON_ERROR) ?? []);

return $cart;
}
Expand Down Expand Up @@ -123,7 +111,7 @@ public function save(Cart $cart, SalesChannelContext $context): void
'price' => $cart->getPrice()->getTotalPrice(),
'line_item_count' => $cart->getLineItems()->count(),
'payload' => $this->serializeCart($cart, $payloadExists),
'rule_ids' => json_encode($context->getRuleIds()),
'rule_ids' => json_encode($context->getRuleIds(), \JSON_THROW_ON_ERROR),
'now' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
];

Expand Down
38 changes: 3 additions & 35 deletions src/Core/Checkout/Cart/CartRuleLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,8 @@ class CartRuleLoader implements ResetInterface
{
private const MAX_ITERATION = 7;

private AbstractCartPersister $cartPersister;

private ?RuleCollection $rules = null;

private Processor $processor;

private LoggerInterface $logger;

private CacheInterface $cache;

private AbstractRuleLoader $ruleLoader;

private TaxDetector $taxDetector;

private EventDispatcherInterface $dispatcher;

private Connection $connection;

/**
* @var array<string, float>
*/
Expand All @@ -56,24 +40,8 @@ class CartRuleLoader implements ResetInterface
/**
* @internal
*/
public function __construct(
AbstractCartPersister $cartPersister,
Processor $processor,
LoggerInterface $logger,
CacheInterface $cache,
AbstractRuleLoader $loader,
TaxDetector $taxDetector,
Connection $connection,
EventDispatcherInterface $dispatcher
) {
$this->cartPersister = $cartPersister;
$this->processor = $processor;
$this->logger = $logger;
$this->cache = $cache;
$this->ruleLoader = $loader;
$this->taxDetector = $taxDetector;
$this->dispatcher = $dispatcher;
$this->connection = $connection;
public function __construct(private readonly AbstractCartPersister $cartPersister, private readonly Processor $processor, private readonly LoggerInterface $logger, private readonly CacheInterface $cache, private readonly AbstractRuleLoader $ruleLoader, private readonly TaxDetector $taxDetector, private readonly Connection $connection, private readonly EventDispatcherInterface $dispatcher)
{
}

public function loadByToken(SalesChannelContext $context, string $cartToken): RuleLoaderResult
Expand All @@ -82,7 +50,7 @@ public function loadByToken(SalesChannelContext $context, string $cartToken): Ru
$cart = $this->cartPersister->load($cartToken, $context);

return $this->load($context, $cart, new CartBehavior($context->getPermissions()), false);
} catch (CartTokenNotFoundException $e) {
} catch (CartTokenNotFoundException) {
$cart = new Cart($cartToken);
$this->dispatcher->dispatch(new CartCreatedEvent($cart));

Expand Down
8 changes: 1 addition & 7 deletions src/Core/Checkout/Cart/CartSerializationCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@
*/
class CartSerializationCleaner
{
private Connection $connection;

private EventDispatcherInterface $eventDispatcher;

/**
* @internal
*/
public function __construct(Connection $connection, EventDispatcherInterface $eventDispatcher)
public function __construct(private readonly Connection $connection, private readonly EventDispatcherInterface $eventDispatcher)
{
$this->connection = $connection;
$this->eventDispatcher = $eventDispatcher;
}

public function cleanupCart(Cart $cart): void
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Checkout/Cart/Cleanup/CleanupCartTaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ final class CleanupCartTaskHandler extends ScheduledTaskHandler
*/
public function __construct(
EntityRepository $repository,
private Connection $connection,
private int $days
private readonly Connection $connection,
private readonly int $days
) {
parent::__construct($repository);
}
Expand Down
Loading

0 comments on commit 4f0cc98

Please sign in to comment.