Use PHP 7.4 syntax in Sylius components#13012
Conversation
ee33acb to
79fbdf6
Compare
| protected ?string $type = TextAttributeType::TYPE; | ||
|
|
||
| /** @var array */ | ||
| protected $configuration = []; |
There was a problem hiding this comment.
| protected $configuration = []; | |
| protected array $configuration = []; |
| protected $type = TextAttributeType::TYPE; | ||
| protected ?string $type = TextAttributeType::TYPE; | ||
|
|
||
| /** @var array */ |
There was a problem hiding this comment.
| /** @var array */ |
| private RequestStack $requestStack; | ||
|
|
||
| /** @var \SplObjectStorage<Request, ChannelInterface> */ | ||
| private $requestToChannelMap; |
There was a problem hiding this comment.
| private $requestToChannelMap; | |
| private \SplObjectStorage $requestToChannelMap; |
There was a problem hiding this comment.
There's also private \SplObjectStorage $requestToExceptionMap; below, but can't suggest a change there...
|
|
||
| /** @var ChannelInterface */ | ||
| private $channel; | ||
| private ?ChannelInterface $channel; |
There was a problem hiding this comment.
| private ?ChannelInterface $channel; | |
| private ChannelInterface $channel; |
|
|
||
| /** @var OrderInterface|null */ | ||
| private $cart; | ||
| private ?\Sylius\Component\Core\Model\OrderInterface $cart = null; |
There was a problem hiding this comment.
| private ?\Sylius\Component\Core\Model\OrderInterface $cart = null; | |
| private ?OrderInterface $cart = null; |
| { | ||
| /** @var EntityRepository */ | ||
| private $orderRepository; | ||
| private EntityRepository $orderRepository; |
There was a problem hiding this comment.
Unrelated, but why an interface is not used here and in the constructor?
| { | ||
| /** @var int|null */ | ||
| protected $id; | ||
| protected ?int $id = null; |
There was a problem hiding this comment.
| protected ?int $id = null; | |
| protected $id; |
There was a problem hiding this comment.
Revert and change /** @var int|null */ to /** @var mixed */
| protected $addresses; | ||
| protected Collection $addresses; | ||
|
|
||
| /** @var ShopUserInterface|null */ |
There was a problem hiding this comment.
| /** @var ShopUserInterface|null */ |
| protected Collection $addresses; | ||
|
|
||
| /** @var ShopUserInterface|null */ | ||
| protected $user; |
There was a problem hiding this comment.
| protected $user; | |
| protected ?ShopUserInterface $user = null; |
| { | ||
| /** @var mixed */ | ||
| protected $id; | ||
| /** @var mixed|null */ |
There was a problem hiding this comment.
| /** @var mixed|null */ | |
| /** @var mixed*/ |
| /** @var mixed */ | ||
| protected $id; | ||
| /** @var mixed|null */ | ||
| protected $id = null; |
There was a problem hiding this comment.
Is null here necessary if there's no type-hint?
| @@ -35,56 +35,47 @@ class Order extends BaseOrder implements OrderInterface | |||
| /** @var ChannelInterface|null */ | |||
| protected $channel; | |||
There was a problem hiding this comment.
| protected $channel; | |
| protected ?ChannelInterface $channel = null; |
There was a problem hiding this comment.
It also missed the $customer above.
Looks like it ignores the cases when the class/interface is not explicitly imported because it's in the same namespace.
| protected ?string $localeCode = null; | ||
|
|
||
| /** @var BaseCouponInterface|null */ | ||
| protected $promotionCoupon; |
There was a problem hiding this comment.
| protected $promotionCoupon; | |
| protected ?BaseCouponInterface $promotionCoupon = null; |
| protected $localeCode; | ||
| protected ?string $localeCode = null; | ||
|
|
||
| /** @var BaseCouponInterface|null */ |
There was a problem hiding this comment.
| /** @var BaseCouponInterface|null */ |
|
|
||
| /** @var BaseTaxonInterface */ | ||
| protected $mainTaxon; | ||
| protected ?\Sylius\Component\Core\Model\TaxonInterface $mainTaxon = null; |
There was a problem hiding this comment.
| protected ?\Sylius\Component\Core\Model\TaxonInterface $mainTaxon = null; | |
| protected ?TaxonInterface $mainTaxon = null; |
|
@Zales0123 is it useful or shall I stop? 😄 |
| /** @var string */ | ||
| protected $firstName; | ||
| protected ?string $firstName = null; | ||
|
|
||
| /** @var string */ | ||
| protected $lastName; | ||
| protected ?string $lastName = null; | ||
|
|
||
| /** @var string */ | ||
| protected $localeCode; | ||
| protected ?string $localeCode = null; | ||
|
|
||
| /** @var ImageInterface */ | ||
| protected $avatar; | ||
| protected ?ImageInterface $avatar = null; |
There was a problem hiding this comment.
There was no null before (in annotation) but now you are adding it. May I ask why?
There was a problem hiding this comment.
There was no null before (in annotation) but now you are adding it. May I ask why?
@arti0090 The annotation was wrong. Both the getter and the setter allow null values, it's not initialized in the constructor and there's no default value, therefore it can be null in a lot of scenarios.
There was a problem hiding this comment.
The truth is, these fields were nullable due to setters definition
| protected Collection $reviews; | ||
|
|
||
| /** @var float */ | ||
| protected $averageRating = 0; |
There was a problem hiding this comment.
| protected $averageRating = 0; | |
| protected float $averageRating = 0; |
There was a problem hiding this comment.
The setter doesn't allow null values, but the getter has ?float as return type, so I'm not sure if it should be nullable.
| protected ?int $onHold = 0; | ||
|
|
||
| /** @var int */ | ||
| protected $onHand = 0; |
There was a problem hiding this comment.
| protected $onHand = 0; | |
| protected ?int $onHand = 0; |
| protected $onHold = 0; | ||
| protected ?int $onHold = 0; | ||
|
|
||
| /** @var int */ |
There was a problem hiding this comment.
| /** @var int */ |
|
|
||
| /** @var Collection */ | ||
| protected $channelPricings; | ||
| protected Collection $channelPricings; |
There was a problem hiding this comment.
This should probably have a @psalm-var Collection<array-key, ChannelPricingInterface> annotation
| { | ||
| /** @var int|null */ | ||
| protected $id; | ||
| protected ?int $id = null; |
There was a problem hiding this comment.
Revert and change annotation to mixed.
| protected $calculator; | ||
| protected ?string $calculator = null; | ||
|
|
||
| /** @var array */ |
There was a problem hiding this comment.
| /** @var array */ |
| protected ?string $calculator = null; | ||
|
|
||
| /** @var array */ | ||
| protected $configuration = []; |
There was a problem hiding this comment.
| protected $configuration = []; | |
| protected array $configuration = []; |
| protected $type; | ||
| protected ?string $type = null; | ||
|
|
||
| /** @var array */ |
There was a problem hiding this comment.
| /** @var array */ |
| protected ?string $type = null; | ||
|
|
||
| /** @var array */ | ||
| protected $configuration = []; |
There was a problem hiding this comment.
| protected $configuration = []; | |
| protected array $configuration = []; |
| protected ?\DateTimeInterface $credentialsExpireAt = null; | ||
|
|
||
| /** | ||
| * We need at least one role to be able to authenticate |
| protected ?string $code = null; | ||
|
|
||
| /** | ||
| * @var Collection|ProvinceInterface[] |
There was a problem hiding this comment.
| * @var Collection|ProvinceInterface[] |
| /** @var string */ | ||
| protected $firstName; | ||
| protected ?string $firstName = null; | ||
|
|
||
| /** @var string */ | ||
| protected $lastName; | ||
| protected ?string $lastName = null; | ||
|
|
||
| /** @var string */ | ||
| protected $localeCode; | ||
| protected ?string $localeCode = null; | ||
|
|
||
| /** @var ImageInterface */ | ||
| protected $avatar; | ||
| protected ?ImageInterface $avatar = null; |
There was a problem hiding this comment.
The truth is, these fields were nullable due to setters definition
| protected Collection $reviews; | ||
|
|
||
| /** @var float */ | ||
| protected $averageRating = 0; |
There was a problem hiding this comment.
| protected $averageRating = 0; | |
| protected float $averageRating = 0; |
| protected $reviews; | ||
| protected Collection $reviews; | ||
|
|
||
| /** @var float */ |
There was a problem hiding this comment.
| /** @var float */ |
| /** @var int */ | ||
| protected $onHand = 0; |
There was a problem hiding this comment.
| /** @var int */ | |
| protected $onHand = 0; | |
| protected ?int $onHand = 0; |
| /** | ||
| * @var Collection|ChannelInterface[] | ||
| * | ||
| * @psalm-var Collection<array-key, ChannelInterface> | ||
| */ |
There was a problem hiding this comment.
| /** | |
| * @var Collection|ChannelInterface[] | |
| * | |
| * @psalm-var Collection<array-key, ChannelInterface> | |
| */ | |
| /** @psalm-var Collection<array-key, ChannelInterface> */ |
| /** @var array */ | ||
| protected $configuration = []; |
There was a problem hiding this comment.
| /** @var array */ | |
| protected $configuration = []; | |
| protected array $configuration = []; |
| * @var Collection|ShipmentUnitInterface[] | ||
| * |
There was a problem hiding this comment.
| * @var Collection|ShipmentUnitInterface[] | |
| * |
| /** @var array */ | ||
| protected $configuration = []; |
There was a problem hiding this comment.
| /** @var array */ | |
| protected $configuration = []; | |
| protected array $configuration = []; |
| * @var Collection|TaxRateInterface[] | ||
| * |
There was a problem hiding this comment.
| * @var Collection|TaxRateInterface[] | |
| * |
| * @var Collection|TaxonInterface[] | ||
| * |
There was a problem hiding this comment.
| * @var Collection|TaxonInterface[] | |
| * |
|
Thank you @vvasiloi for the review! I would never believe someone would be determined enough to take a look at it. I'm impressed 👏 I've fixed (hopefully) most of the comments, I've just left those about collection type hints, as I'm not 100% sure how the IDE would handle these types without them 🤷 . Still, can be improved later 🖖 Thank you! 🎉 |
|
Thanks, Mateusz! 🥇 |
I know, it's probably unreviewable (but bundles will be worse 😄). In tests we trust 🖖 🚀