Skip to content

Use PHP 7.4 syntax in Sylius components#13012

Merged
GSadee merged 2 commits intoSylius:1.10from
Zales0123:php7.4-syntax-components
Sep 3, 2021
Merged

Use PHP 7.4 syntax in Sylius components#13012
GSadee merged 2 commits intoSylius:1.10from
Zales0123:php7.4-syntax-components

Conversation

@Zales0123
Copy link
Copy Markdown
Contributor

Q A
Branch? 1.10
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets related to #12891
License MIT

I know, it's probably unreviewable (but bundles will be worse 😄). In tests we trust 🖖 🚀

@Zales0123 Zales0123 added the Maintenance CI configurations, READMEs, releases, etc. label Aug 26, 2021
@Zales0123 Zales0123 requested a review from a team as a code owner August 26, 2021 23:35
@Zales0123 Zales0123 mentioned this pull request Aug 26, 2021
10 tasks
@Zales0123 Zales0123 force-pushed the php7.4-syntax-components branch from ee33acb to 79fbdf6 Compare August 27, 2021 05:31
protected ?string $type = TextAttributeType::TYPE;

/** @var array */
protected $configuration = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $configuration = [];
protected array $configuration = [];

protected $type = TextAttributeType::TYPE;
protected ?string $type = TextAttributeType::TYPE;

/** @var array */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var array */

private RequestStack $requestStack;

/** @var \SplObjectStorage<Request, ChannelInterface> */
private $requestToChannelMap;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private $requestToChannelMap;
private \SplObjectStorage $requestToChannelMap;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also private \SplObjectStorage $requestToExceptionMap; below, but can't suggest a change there...


/** @var ChannelInterface */
private $channel;
private ?ChannelInterface $channel;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private ?ChannelInterface $channel;
private ChannelInterface $channel;


/** @var OrderInterface|null */
private $cart;
private ?\Sylius\Component\Core\Model\OrderInterface $cart = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private ?\Sylius\Component\Core\Model\OrderInterface $cart = null;
private ?OrderInterface $cart = null;

{
/** @var EntityRepository */
private $orderRepository;
private EntityRepository $orderRepository;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but why an interface is not used here and in the constructor?

{
/** @var int|null */
protected $id;
protected ?int $id = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected ?int $id = null;
protected $id;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert and change /** @var int|null */ to /** @var mixed */

protected $addresses;
protected Collection $addresses;

/** @var ShopUserInterface|null */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var ShopUserInterface|null */

protected Collection $addresses;

/** @var ShopUserInterface|null */
protected $user;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $user;
protected ?ShopUserInterface $user = null;

{
/** @var mixed */
protected $id;
/** @var mixed|null */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var mixed|null */
/** @var mixed*/

/** @var mixed */
protected $id;
/** @var mixed|null */
protected $id = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $channel;
protected ?ChannelInterface $channel = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $promotionCoupon;
protected ?BaseCouponInterface $promotionCoupon = null;

protected $localeCode;
protected ?string $localeCode = null;

/** @var BaseCouponInterface|null */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var BaseCouponInterface|null */


/** @var BaseTaxonInterface */
protected $mainTaxon;
protected ?\Sylius\Component\Core\Model\TaxonInterface $mainTaxon = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected ?\Sylius\Component\Core\Model\TaxonInterface $mainTaxon = null;
protected ?TaxonInterface $mainTaxon = null;

@vvasiloi
Copy link
Copy Markdown
Contributor

@Zales0123 is it useful or shall I stop? 😄
For some reason I chose to add single comments instead of starting a review, so you've probably received a ton of notifications... sorry.

Comment on lines -20 to +26
/** @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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no null before (in annotation) but now you are adding it. May I ask why?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The truth is, these fields were nullable due to setters definition

protected Collection $reviews;

/** @var float */
protected $averageRating = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $averageRating = 0;
protected float $averageRating = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $onHand = 0;
protected ?int $onHand = 0;

protected $onHold = 0;
protected ?int $onHold = 0;

/** @var int */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var int */


/** @var Collection */
protected $channelPricings;
protected Collection $channelPricings;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably have a @psalm-var Collection<array-key, ChannelPricingInterface> annotation

{
/** @var int|null */
protected $id;
protected ?int $id = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert and change annotation to mixed.

protected $calculator;
protected ?string $calculator = null;

/** @var array */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var array */

protected ?string $calculator = null;

/** @var array */
protected $configuration = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $configuration = [];
protected array $configuration = [];

protected $type;
protected ?string $type = null;

/** @var array */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var array */

protected ?string $type = null;

/** @var array */
protected $configuration = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $configuration = [];
protected array $configuration = [];

protected ?\DateTimeInterface $credentialsExpireAt = null;

/**
* We need at least one role to be able to authenticate
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one.

protected ?string $code = null;

/**
* @var Collection|ProvinceInterface[]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var Collection|ProvinceInterface[]

Comment on lines -20 to +26
/** @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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The truth is, these fields were nullable due to setters definition

protected Collection $reviews;

/** @var float */
protected $averageRating = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected $averageRating = 0;
protected float $averageRating = 0;

protected $reviews;
protected Collection $reviews;

/** @var float */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var float */

Comment on lines 29 to 30
/** @var int */
protected $onHand = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var int */
protected $onHand = 0;
protected ?int $onHand = 0;

Comment on lines 30 to 34
/**
* @var Collection|ChannelInterface[]
*
* @psalm-var Collection<array-key, ChannelInterface>
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* @var Collection|ChannelInterface[]
*
* @psalm-var Collection<array-key, ChannelInterface>
*/
/** @psalm-var Collection<array-key, ChannelInterface> */

Comment on lines 23 to 24
/** @var array */
protected $configuration = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var array */
protected $configuration = [];
protected array $configuration = [];

Comment on lines 32 to 33
* @var Collection|ShipmentUnitInterface[]
*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var Collection|ShipmentUnitInterface[]
*

Comment on lines 45 to 46
/** @var array */
protected $configuration = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var array */
protected $configuration = [];
protected array $configuration = [];

Comment on lines 34 to 35
* @var Collection|TaxRateInterface[]
*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var Collection|TaxRateInterface[]
*

Comment on lines 40 to 41
* @var Collection|TaxonInterface[]
*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var Collection|TaxonInterface[]
*

@Zales0123
Copy link
Copy Markdown
Contributor Author

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! 🎉

@GSadee GSadee merged commit e4b7c8a into Sylius:1.10 Sep 3, 2021
@GSadee
Copy link
Copy Markdown
Member

GSadee commented Sep 3, 2021

Thanks, Mateusz! 🥇

@Zales0123 Zales0123 deleted the php7.4-syntax-components branch September 3, 2021 13:35
@Zales0123 Zales0123 restored the php7.4-syntax-components branch September 30, 2021 13:26
@Zales0123 Zales0123 deleted the php7.4-syntax-components branch September 30, 2021 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Maintenance CI configurations, READMEs, releases, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants