Skip to content

Convert Behat annotations to PHP attributes in Transform contexts#18846

Merged
NoResponseMate merged 1 commit intoSylius:2.3from
loic425:behat-annotations-to-attributes/transform
Feb 19, 2026
Merged

Convert Behat annotations to PHP attributes in Transform contexts#18846
NoResponseMate merged 1 commit intoSylius:2.3from
loic425:behat-annotations-to-attributes/transform

Conversation

@loic425
Copy link
Copy Markdown
Member

@loic425 loic425 commented Feb 18, 2026

Q A
Branch? 2.3
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets partially #18822
License MIT

Summary by CodeRabbit

  • Refactor
    • Modernized test framework context files across the test suite by migrating to PHP 8 native attributes syntax. This update improves code consistency and aligns with modern PHP standards while maintaining all existing test functionality. No changes to test behavior or observable functionality.

@loic425 loic425 requested review from a team as code owners February 18, 2026 16:55
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 18, 2026

📝 Walkthrough

Walkthrough

Systematically migrates Behat Transform annotations across 35 context files from PHPDoc-style @Transform docblocks to PHP 8 attribute syntax #[Transform(...)]. Each file adds a use Behat\Transformation\Transform; statement and decorates transformation methods with corresponding attributes. Method signatures and control flow remain unchanged; one file adds a return type. Behavior is functionally identical.

Changes

Cohort / File(s) Summary
Behat Transform Annotation Migration
src/Sylius/Behat/Context/Transform/AddressContext.php, AdminUserContext.php, CartContext.php, CatalogPromotionContext.php, ChannelContext.php, CountryContext.php, CouponContext.php, CurrencyContext.php, CustomerContext.php, CustomerGroupContext.php, DateTimeContext.php, ExchangeRateContext.php, LocaleContext.php, PaymentMethodContext.php, ProductAssociationTypeContext.php, ProductAttributeContext.php, ProductContext.php, ProductOptionContext.php, ProductOptionValueContext.php, ProductReviewContext.php, ProductVariantContext.php, PromotionContext.php, ProvinceContext.php, SharedStorageContext.php, ShippingCalculatorContext.php, ShippingCategoryContext.php, ShippingMethodContext.php, ShopUserContext.php, TaxCategoryContext.php, TaxRateContext.php, TaxonContext.php, ThemeContext.php, UserContext.php, ZoneContext.php, ZoneMemberContext.php
Replaced PHPDoc @Transform annotations with PHP 8 #[Transform(...)] attributes across 35 Transform context classes. Added use Behat\Transformation\Transform; import to each file. One file (ExchangeRateContext.php) also adds a return type declaration. No method signatures or control flow altered.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

DX, Maintenance

Suggested reviewers

  • TheMilek
  • GSadee
  • mpysiak

Poem

🐰 From docblock comments, old and worn,
Attributes emerge, freshly born!
PHP 8 takes the stage with grace,
As Transform decorators find their place.
A tidy refactor, clean and bright—
Behat contexts shine in morning light! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.96% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting Behat annotations from PHPDoc style to PHP 8 attributes across Transform context files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 18, 2026

❗ Preview Environment delete from Bunnyshell failed

Check https://github.com/Sylius/Sylius/actions/runs/22173636242 for details.

See: Environment Details

Available commands:

  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@loic425 loic425 mentioned this pull request Feb 18, 2026
27 tasks
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (17)
src/Sylius/Behat/Context/Transform/ShippingCategoryContext.php (2)

31-42: getShippingCategoryByName is missing a parameter type and a return type.

♻️ Proposed fix
-    public function getShippingCategoryByName($shippingCategoryName)
+    public function getShippingCategoryByName(string $shippingCategoryName): ShippingCategoryInterface

You will also need to add the corresponding use import for ShippingCategoryInterface.

As per coding guidelines, "Add type declarations for all properties, arguments, and return values in PHP code."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/ShippingCategoryContext.php` around lines
31 - 42, Add explicit types to the getShippingCategoryByName method: declare the
parameter as string and the return type as ShippingCategoryInterface (i.e.,
change signature to getShippingCategoryByName(string $shippingCategoryName):
ShippingCategoryInterface) and ensure you add the corresponding use import for
ShippingCategoryInterface at the top of the file; keep the internal logic
unchanged but rely on type hints for safety and clarity.

21-21: ShippingCategoryContext is the only class in the PR not declared final.

All other context classes in this PR use final. This pre-existing gap stands out now that the class is being touched.

♻️ Proposed fix
-class ShippingCategoryContext implements Context
+final class ShippingCategoryContext implements Context

As per coding guidelines, "Use final for all PHP classes, except entities and repositories."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/ShippingCategoryContext.php` at line 21,
The ShippingCategoryContext class should be declared final to match the
project's coding guidelines and other context classes; update the class
declaration for ShippingCategoryContext (the class named ShippingCategoryContext
implementing Context) to add the final keyword so it becomes a final class.
src/Sylius/Behat/Context/Transform/CountryContext.php (1)

36-47: getCountryByName is missing a parameter type and return type.

♻️ Proposed fix
-    public function getCountryByName($countryName)
+    public function getCountryByName(string $countryName): CountryInterface

You will also need to add use Sylius\Component\Addressing\Model\CountryInterface;.

As per coding guidelines, "Add type declarations for all properties, arguments, and return values in PHP code."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/CountryContext.php` around lines 36 - 47,
The getCountryByName method lacks argument and return type declarations; update
its signature to public function getCountryByName(string $countryName):
CountryInterface (and add use
Sylius\Component\Addressing\Model\CountryInterface;) so the $countryName
parameter is typed and the method returns CountryInterface, leaving the body
intact (keep calls to $this->countryNameConverter->convertToCode and
$this->countryRepository->findOneBy and the Assert::notNull check).
src/Sylius/Behat/Context/Transform/AdminUserContext.php (1)

41-45: getLoggedAdminUser is missing a return type.

♻️ Proposed fix
-    public function getLoggedAdminUser()
+    public function getLoggedAdminUser(): AdminUserInterface

As per coding guidelines, "Add type declarations for all properties, arguments, and return values in PHP code."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/AdminUserContext.php` around lines 41 -
45, getLoggedAdminUser lacks a return type declaration; update the method
signature to declare the concrete return type returned by
$this->sharedStorage->get('administrator') (for example add ":
AdminUserInterface" or ": UserInterface" as appropriate), import that interface
at the top of the file, and adjust the return if necessary to ensure it always
returns that type (or use a nullable type like ": ?AdminUserInterface" only if
sharedStorage can return null).
src/Sylius/Behat/Context/Transform/ProductContext.php (2)

50-53: getProductsByNames is missing a return type.

♻️ Proposed fix
-    public function getProductsByNames(...$productsNames)
+    public function getProductsByNames(string ...$productsNames): array

As per coding guidelines, "Add type declarations for all properties, arguments, and return values in PHP code."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/ProductContext.php` around lines 50 - 53,
getProductsByNames lacks a PHP return type declaration; update its signature to
declare types (e.g. type-hint the variadic parameter as string ...$productsNames
if appropriate) and add an explicit return type (e.g. : array) so the method
becomes strongly typed; keep the body using getProductByName($productName)
unchanged but ensure the declared return type matches the actual returned
collection (use a more specific array of Product/ ProductInterface in a docblock
if you need finer-grained typing).

35-46: getProductByName is missing a parameter type and return type.

♻️ Proposed fix
-    public function getProductByName($productName)
+    public function getProductByName(string $productName): ProductInterface

Add the corresponding use import for ProductInterface.

As per coding guidelines, "Add type declarations for all properties, arguments, and return values in PHP code."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/ProductContext.php` around lines 35 - 46,
The getProductByName function lacks type hints: add a string type for the
$productName parameter and declare the return type as ProductInterface; also add
a use statement for ProductInterface and ensure the method returns
ProductInterface (not just mixed) — update the method signature
(getProductByName) to accept string $productName and return ProductInterface and
keep the body using $this->productRepository->findByName($productName,
$this->locale) and the Assert check unchanged.
src/Sylius/Behat/Context/Transform/DateTimeContext.php (1)

25-28: Missing type declarations; prefer \DateTimeImmutable over \DateTime.

getDate has no parameter or return type, and returns a mutable \DateTime instance. Modern PHP 8.2+ practice (and Sylius convention) favours \DateTimeImmutable for value objects.

♻️ Suggested fix
-    public function getDate($date)
+    public function getDate(string $date): \DateTimeImmutable
     {
-        return new \DateTime($date);
+        return new \DateTimeImmutable($date);
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/DateTimeContext.php` around lines 25 - 28,
The getDate method in DateTimeContext lacks type hints and returns a mutable
\DateTime; change its signature to accept a string and return an immutable
instance by updating function getDate(string $date): \DateTimeImmutable and
instantiate and return new \DateTimeImmutable($date) inside the method so
callers get typed, immutable date values.
src/Sylius/Behat/Context/Transform/ProductAssociationTypeContext.php (1)

30-30: Missing parameter and return type declarations.

getProductAssociationTypeByName has no type on its parameter or return value. Per coding guidelines, all arguments and return values should have type declarations.

♻️ Suggested fix
-    public function getProductAssociationTypeByName($productAssociationTypeName)
+    public function getProductAssociationTypeByName(string $productAssociationTypeName): ProductAssociationTypeInterface

You'll also need to add the corresponding use import for ProductAssociationTypeInterface.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/ProductAssociationTypeContext.php` at line
30, Update the signature of getProductAssociationTypeByName to declare the
parameter type and return type (e.g. change to accept string
$productAssociationTypeName and return ?ProductAssociationTypeInterface or
ProductAssociationTypeInterface depending on whether null is possible), add the
corresponding use import for ProductAssociationTypeInterface at the top of the
file, and adjust any callers if required to handle the declared return type.
src/Sylius/Behat/Context/Transform/ProductOptionContext.php (1)

30-30: Missing parameter and return type declarations.

Same pre-existing gap as other transform methods in this PR: getProductOptionByName lacks a typed parameter and return type.

♻️ Suggested fix
-    public function getProductOptionByName($productOptionName)
+    public function getProductOptionByName(string $productOptionName): ProductOptionInterface

Add the corresponding use import for ProductOptionInterface.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/ProductOptionContext.php` at line 30,
Update the getProductOptionByName method to declare its parameter and return
types: change the signature of getProductOptionByName($productOptionName) to
accept a string and return ProductOptionInterface (e.g.
getProductOptionByName(string $productOptionName): ProductOptionInterface), and
add the corresponding use import for ProductOptionInterface at the top of the
file so the type is resolved.
src/Sylius/Behat/Context/Transform/UserContext.php (2)

27-30: getLoggedUser() is missing a return type.

Per coding guidelines, return types should always be declared. The method returns whatever is stored under the 'user' key, which is presumably a typed user object from shared storage.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/UserContext.php` around lines 27 - 30, The
method getLoggedUser() lacks an explicit return type; update its signature to
declare the correct return type (e.g., the UserInterface or concrete User class
used by sharedStorage) so the method returns that type instead of an untyped
value; locate the getLoggedUser method in UserContext and change its declaration
to include the appropriate return type matching the object stored under
sharedStorage->get('user').

20-20: UserContext should be declared final.

Every sibling context class in this PR (and across the Transform/ directory) uses final class. The coding guidelines require final for all non-entity/non-repository classes.

♻️ Suggested fix
-class UserContext implements Context
+final class UserContext implements Context
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/UserContext.php` at line 20, The
UserContext class declaration should be marked final to match project
conventions; update the class header "class UserContext implements Context" to
"final class UserContext implements Context" so the class is non-extendable, and
run tests/PHPCS to ensure no other style changes are required; keep all existing
methods and imports unchanged.
src/Sylius/Behat/Context/Transform/CustomerGroupContext.php (1)

30-30: Missing parameter and return type declarations.

getCustomerGroupByName has no typed parameter or return value. Should be string for the parameter and a CustomerGroupInterface (or equivalent) for the return.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/CustomerGroupContext.php` at line 30,
Update the method signature for getCustomerGroupByName to add a typed parameter
and return type: change the parameter to string and add a return type of
CustomerGroupInterface (or the project’s equivalent interface), and ensure the
appropriate use/import for CustomerGroupInterface is added at the top of the
file; keep the method body unchanged except for any necessary assertions/casts
to satisfy the new type hints.
src/Sylius/Behat/Context/Transform/ZoneMemberContext.php (2)

16-17: use imports are not in alphabetical order.

Behat\Behat\Context\Context (Behat < Transformation) should precede Behat\Transformation\Transform. As per coding guidelines, PHP use imports must be sorted alphabetically.

♻️ Proposed fix
-use Behat\Transformation\Transform;
 use Behat\Behat\Context\Context;
+use Behat\Transformation\Transform;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/ZoneMemberContext.php` around lines 16 -
17, The two PHP use imports in ZoneMemberContext are out of alphabetical order;
reorder them so Behat\Behat\Context\Context comes before
Behat\Transformation\Transform (i.e., sort the use statements alphabetically) to
comply with the project's import-ordering rule — update the use block containing
"use Behat\Transformation\Transform" and "use Behat\Behat\Context\Context"
accordingly.

36-36: Add missing type declarations to the three untyped public Transform methods.

getCountryTypeZoneMemberByName, getProvinceTypeZoneMemberByName, and getZoneTypeZoneMemberByName all lack parameter and return type declarations, while the sibling method getCountryTypeZoneMembersByNames already declares them. ZoneMemberInterface is already imported. As per coding guidelines, all PHP arguments and return values must have type declarations.

♻️ Proposed fix
-    public function getCountryTypeZoneMemberByName($name)
+    public function getCountryTypeZoneMemberByName(string $name): ZoneMemberInterface

-    public function getProvinceTypeZoneMemberByName($name)
+    public function getProvinceTypeZoneMemberByName(string $name): ZoneMemberInterface

-    public function getZoneTypeZoneMemberByName($name)
+    public function getZoneTypeZoneMemberByName(string $name): ZoneMemberInterface

Also applies to: 54-54, 62-62

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/ZoneMemberContext.php` at line 36, Add
strict type declarations to the three untyped public Transform methods: change
the parameter for getCountryTypeZoneMemberByName,
getProvinceTypeZoneMemberByName, and getZoneTypeZoneMemberByName to string $name
and add a return type of ZoneMemberInterface; ensure the methods import/use
ZoneMemberInterface (as in the sibling getCountryTypeZoneMembersByNames) and
update any docblocks to reflect the typed signature.
src/Sylius/Behat/Context/Transform/TaxonContext.php (1)

16-17: use imports are not in alphabetical order.

Same issue as in ZoneMemberContext.php: Behat\Behat\Context\Context must come before Behat\Transformation\Transform. As per coding guidelines, PHP use imports must be sorted alphabetically.

♻️ Proposed fix
-use Behat\Transformation\Transform;
 use Behat\Behat\Context\Context;
+use Behat\Transformation\Transform;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/TaxonContext.php` around lines 16 - 17,
Reorder the PHP use imports in TaxonContext.php so they are alphabetized: place
Behat\Behat\Context\Context before Behat\Transformation\Transform (same change
as in ZoneMemberContext.php). Update the import block where Context and
Transform are declared to follow alphabetical ordering to satisfy the coding
guidelines.
src/Sylius/Behat/Context/Transform/PromotionContext.php (2)

16-17: use imports are not in alphabetical order.

Same issue as the other files in this PR: Behat\Behat\Context\Context must precede Behat\Transformation\Transform. As per coding guidelines, PHP use imports must be sorted alphabetically.

♻️ Proposed fix
-use Behat\Transformation\Transform;
 use Behat\Behat\Context\Context;
+use Behat\Transformation\Transform;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/PromotionContext.php` around lines 16 -
17, The file's PHP use imports are out of alphabetical order; swap the two use
statements so Behat\Behat\Context\Context comes before
Behat\Transformation\Transform in PromotionContext.php—i.e., update the use
declarations for Context and Transform in the PromotionContext class so they are
sorted alphabetically.

33-33: Add missing type declarations to both public Transform methods.

getPromotionByName and getPromotionCouponByCode have no parameter or return type declarations. The respective return types (PromotionInterface / PromotionCouponInterface) would also need to be added to the use block. As per coding guidelines, all PHP arguments and return values must carry type declarations.

♻️ Proposed fix (parameter types; return types need their respective interface imports)
-    public function getPromotionByName($promotionName)
+    public function getPromotionByName(string $promotionName): PromotionInterface

-    public function getPromotionCouponByCode($promotionCouponCode)
+    public function getPromotionCouponByCode(string $promotionCouponCode): PromotionCouponInterface

Also applies to: 48-48

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/PromotionContext.php` at line 33, Both
public transform methods lack parameter and return type hints: add string
$promotionName and string $couponCode parameter types and declare return types
PromotionInterface for getPromotionByName and PromotionCouponInterface for
getPromotionCouponByCode; also import those interfaces in the use block
(PromotionInterface, PromotionCouponInterface) and adjust any nullable/exception
behavior to match the new signatures. Locate the methods getPromotionByName and
getPromotionCouponByCode and update their signatures accordingly and add the two
interface imports at the top of the file.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Sylius/Behat/Context/Transform/ShippingCategoryContext.php`:
- Around line 16-17: The two PHP use statements are alphabetized incorrectly in
ShippingCategoryContext; swap the order so Behat\Behat\Context\Context appears
before Behat\Transformation\Transform (i.e., ensure the use imports list has
Context then Transform), and apply the same alphabetical reorder to the other
seven files in this PR to match CartContext.php and the project's import sorting
guideline.

---

Duplicate comments:
In `@src/Sylius/Behat/Context/Transform/AdminUserContext.php`:
- Around line 16-17: Reorder the use statements in AdminUserContext.php so they
follow the project's import ordering convention (match
ShippingCategoryContext.php) by placing Behat\Behat\Context\Context before
Behat\Transformation\Transform; update the import order for the symbols Context
and Transform accordingly to satisfy the linter/PSR ordering.

In `@src/Sylius/Behat/Context/Transform/CountryContext.php`:
- Around line 16-17: The import statements in CountryContext are out of the
project's canonical order; reorder the use statements so
Behat\Behat\Context\Context appears before Behat\Transformation\Transform
(consistent with the ordering used in ShippingCategoryContext and
PSR‑12/alphabetical grouping), i.e., update the use block in the CountryContext
class to place the Context import above the Transform import.

In `@src/Sylius/Behat/Context/Transform/ExchangeRateContext.php`:
- Around line 16-17: Fix the import ordering in ExchangeRateContext by
reordering the use statements so they match the project's import style (same
order used in ShippingCategoryContext): place Behat\Behat\Context\Context before
Behat\Transformation\Transform and ensure the import block around the
ExchangeRateContext class uses the same grouping/ordering convention as the
other context files.

In `@src/Sylius/Behat/Context/Transform/ProductContext.php`:
- Around line 16-17: Reorder the use statements in ProductContext.php to match
the project's import ordering (same fix as ShippingCategoryContext.php): place
"use Behat\Behat\Context\Context;" before "use Behat\Transformation\Transform;"
so the imports are consistently ordered (third-party/namespace grouping and
alphabetical), and ensure there are no duplicate or stray import lines.

In `@src/Sylius/Behat/Context/Transform/ProvinceContext.php`:
- Around line 16-17: Reorder the use statements in ProvinceContext.php to match
the ordering used in ShippingCategoryContext.php: place "use
Behat\Behat\Context\Context;" before "use Behat\Transformation\Transform;" (keep
one use per line and consistent sorting), ensuring the ProvinceContext class
imports are consistently ordered.

In `@src/Sylius/Behat/Context/Transform/ShopUserContext.php`:
- Around line 16-17: Reorder the use statements in ShopUserContext so they match
the ordering used in ShippingCategoryContext: place "use
Behat\Behat\Context\Context;" before "use Behat\Transformation\Transform;".
Update the imports at the top of the ShopUserContext class (the use declarations
referencing Transform and Context) so they follow that ordering.

---

Nitpick comments:
In `@src/Sylius/Behat/Context/Transform/AdminUserContext.php`:
- Around line 41-45: getLoggedAdminUser lacks a return type declaration; update
the method signature to declare the concrete return type returned by
$this->sharedStorage->get('administrator') (for example add ":
AdminUserInterface" or ": UserInterface" as appropriate), import that interface
at the top of the file, and adjust the return if necessary to ensure it always
returns that type (or use a nullable type like ": ?AdminUserInterface" only if
sharedStorage can return null).

In `@src/Sylius/Behat/Context/Transform/CountryContext.php`:
- Around line 36-47: The getCountryByName method lacks argument and return type
declarations; update its signature to public function getCountryByName(string
$countryName): CountryInterface (and add use
Sylius\Component\Addressing\Model\CountryInterface;) so the $countryName
parameter is typed and the method returns CountryInterface, leaving the body
intact (keep calls to $this->countryNameConverter->convertToCode and
$this->countryRepository->findOneBy and the Assert::notNull check).

In `@src/Sylius/Behat/Context/Transform/CustomerGroupContext.php`:
- Line 30: Update the method signature for getCustomerGroupByName to add a typed
parameter and return type: change the parameter to string and add a return type
of CustomerGroupInterface (or the project’s equivalent interface), and ensure
the appropriate use/import for CustomerGroupInterface is added at the top of the
file; keep the method body unchanged except for any necessary assertions/casts
to satisfy the new type hints.

In `@src/Sylius/Behat/Context/Transform/DateTimeContext.php`:
- Around line 25-28: The getDate method in DateTimeContext lacks type hints and
returns a mutable \DateTime; change its signature to accept a string and return
an immutable instance by updating function getDate(string $date):
\DateTimeImmutable and instantiate and return new \DateTimeImmutable($date)
inside the method so callers get typed, immutable date values.

In `@src/Sylius/Behat/Context/Transform/ProductAssociationTypeContext.php`:
- Line 30: Update the signature of getProductAssociationTypeByName to declare
the parameter type and return type (e.g. change to accept string
$productAssociationTypeName and return ?ProductAssociationTypeInterface or
ProductAssociationTypeInterface depending on whether null is possible), add the
corresponding use import for ProductAssociationTypeInterface at the top of the
file, and adjust any callers if required to handle the declared return type.

In `@src/Sylius/Behat/Context/Transform/ProductContext.php`:
- Around line 50-53: getProductsByNames lacks a PHP return type declaration;
update its signature to declare types (e.g. type-hint the variadic parameter as
string ...$productsNames if appropriate) and add an explicit return type (e.g. :
array) so the method becomes strongly typed; keep the body using
getProductByName($productName) unchanged but ensure the declared return type
matches the actual returned collection (use a more specific array of Product/
ProductInterface in a docblock if you need finer-grained typing).
- Around line 35-46: The getProductByName function lacks type hints: add a
string type for the $productName parameter and declare the return type as
ProductInterface; also add a use statement for ProductInterface and ensure the
method returns ProductInterface (not just mixed) — update the method signature
(getProductByName) to accept string $productName and return ProductInterface and
keep the body using $this->productRepository->findByName($productName,
$this->locale) and the Assert check unchanged.

In `@src/Sylius/Behat/Context/Transform/ProductOptionContext.php`:
- Line 30: Update the getProductOptionByName method to declare its parameter and
return types: change the signature of getProductOptionByName($productOptionName)
to accept a string and return ProductOptionInterface (e.g.
getProductOptionByName(string $productOptionName): ProductOptionInterface), and
add the corresponding use import for ProductOptionInterface at the top of the
file so the type is resolved.

In `@src/Sylius/Behat/Context/Transform/PromotionContext.php`:
- Around line 16-17: The file's PHP use imports are out of alphabetical order;
swap the two use statements so Behat\Behat\Context\Context comes before
Behat\Transformation\Transform in PromotionContext.php—i.e., update the use
declarations for Context and Transform in the PromotionContext class so they are
sorted alphabetically.
- Line 33: Both public transform methods lack parameter and return type hints:
add string $promotionName and string $couponCode parameter types and declare
return types PromotionInterface for getPromotionByName and
PromotionCouponInterface for getPromotionCouponByCode; also import those
interfaces in the use block (PromotionInterface, PromotionCouponInterface) and
adjust any nullable/exception behavior to match the new signatures. Locate the
methods getPromotionByName and getPromotionCouponByCode and update their
signatures accordingly and add the two interface imports at the top of the file.

In `@src/Sylius/Behat/Context/Transform/ShippingCategoryContext.php`:
- Around line 31-42: Add explicit types to the getShippingCategoryByName method:
declare the parameter as string and the return type as ShippingCategoryInterface
(i.e., change signature to getShippingCategoryByName(string
$shippingCategoryName): ShippingCategoryInterface) and ensure you add the
corresponding use import for ShippingCategoryInterface at the top of the file;
keep the internal logic unchanged but rely on type hints for safety and clarity.
- Line 21: The ShippingCategoryContext class should be declared final to match
the project's coding guidelines and other context classes; update the class
declaration for ShippingCategoryContext (the class named ShippingCategoryContext
implementing Context) to add the final keyword so it becomes a final class.

In `@src/Sylius/Behat/Context/Transform/TaxonContext.php`:
- Around line 16-17: Reorder the PHP use imports in TaxonContext.php so they are
alphabetized: place Behat\Behat\Context\Context before
Behat\Transformation\Transform (same change as in ZoneMemberContext.php). Update
the import block where Context and Transform are declared to follow alphabetical
ordering to satisfy the coding guidelines.

In `@src/Sylius/Behat/Context/Transform/UserContext.php`:
- Around line 27-30: The method getLoggedUser() lacks an explicit return type;
update its signature to declare the correct return type (e.g., the UserInterface
or concrete User class used by sharedStorage) so the method returns that type
instead of an untyped value; locate the getLoggedUser method in UserContext and
change its declaration to include the appropriate return type matching the
object stored under sharedStorage->get('user').
- Line 20: The UserContext class declaration should be marked final to match
project conventions; update the class header "class UserContext implements
Context" to "final class UserContext implements Context" so the class is
non-extendable, and run tests/PHPCS to ensure no other style changes are
required; keep all existing methods and imports unchanged.

In `@src/Sylius/Behat/Context/Transform/ZoneMemberContext.php`:
- Around line 16-17: The two PHP use imports in ZoneMemberContext are out of
alphabetical order; reorder them so Behat\Behat\Context\Context comes before
Behat\Transformation\Transform (i.e., sort the use statements alphabetically) to
comply with the project's import-ordering rule — update the use block containing
"use Behat\Transformation\Transform" and "use Behat\Behat\Context\Context"
accordingly.
- Line 36: Add strict type declarations to the three untyped public Transform
methods: change the parameter for getCountryTypeZoneMemberByName,
getProvinceTypeZoneMemberByName, and getZoneTypeZoneMemberByName to string $name
and add a return type of ZoneMemberInterface; ensure the methods import/use
ZoneMemberInterface (as in the sibling getCountryTypeZoneMembersByNames) and
update any docblocks to reflect the typed signature.

Comment on lines +16 to 17
use Behat\Transformation\Transform;
use Behat\Behat\Context\Context;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

use imports are not in alphabetical order — swap lines 16 and 17.

Behat\Behat\Context\Context must precede Behat\Transformation\Transform alphabetically (Behat < Transformation). CartContext.php in the same PR already has the correct order. This same transposition was applied to all 7 other files changed in this PR except CartContext.php; each needs the same fix.

♻️ Proposed fix
-use Behat\Transformation\Transform;
 use Behat\Behat\Context\Context;
+use Behat\Transformation\Transform;

As per coding guidelines, "Sort PHP use imports alphabetically and group by type (classes, functions, constants)."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use Behat\Transformation\Transform;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\Context;
use Behat\Transformation\Transform;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Sylius/Behat/Context/Transform/ShippingCategoryContext.php` around lines
16 - 17, The two PHP use statements are alphabetized incorrectly in
ShippingCategoryContext; swap the order so Behat\Behat\Context\Context appears
before Behat\Transformation\Transform (i.e., ensure the use imports list has
Context then Transform), and apply the same alphabetical reorder to the other
seven files in this PR to match CartContext.php and the project's import sorting
guideline.

@NoResponseMate NoResponseMate merged commit 623f56d into Sylius:2.3 Feb 19, 2026
36 checks passed
@loic425 loic425 deleted the behat-annotations-to-attributes/transform branch February 19, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants