Skip to content

Bundle configuration with PHP files#436

Merged
NoResponseMate merged 5 commits intoSylius:1.15from
loic425:php-file-config
Nov 7, 2025
Merged

Bundle configuration with PHP files#436
NoResponseMate merged 5 commits intoSylius:1.15from
loic425:php-file-config

Conversation

@loic425
Copy link
Copy Markdown
Member

@loic425 loic425 commented Oct 31, 2025

@loic425 loic425 changed the base branch from 1.14 to 1.15 October 31, 2025 08:35
@loic425 loic425 marked this pull request as draft October 31, 2025 08:35
Copy link
Copy Markdown
Contributor

@Prometee Prometee left a comment

Choose a reason for hiding this comment

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

Code Review Summary

This review identifies 1 critical issue and 1 medium issue that should be addressed before merging, along with several suggestions for code quality improvements.

Critical Issues: 1
Medium Issues: 1
Suggestions: 4
Nitpicks: 1

Please see the inline comments for details.

service('sylius.grid.data_extractor'),
'%sylius_grid.timezone%',
])
->tag('sylius.grid_field', ['type' => \datetime::class]);
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.

Type: Issue
Severity: Critical

Bug: Invalid class constant usage

The original XML uses type="datetime" (lowercase string), but the PHP version uses \datetime::class. This will fail because:

  1. \datetime should be \DateTime (capital D) if it were a class reference
  2. But it shouldn't be a class reference at all - it should be the string 'datetime'

Current code:

->tag('sylius.grid_field', ['type' => \datetime::class]);

Should be:

->tag('sylius.grid_field', ['type' => 'datetime']);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, I agree, that's not good.

->public();

$services->set('sylius.grid_driver.doctrine.orm', 'Sylius\Bundle\GridBundle\Doctrine\ORM\Driver')
->args([service('doctrine')->nullOnInvalid()])
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.

Type: Issue
Severity: Medium

⚠️ Type Safety Issue: Driver doesn't accept null

After reviewing the Sylius\Bundle\GridBundle\Doctrine\ORM\Driver class, there's a type mismatch. The Driver's constructor requires a non-nullable ManagerRegistry parameter:

public function __construct(ManagerRegistry $managerRegistry)

However, the service configuration uses ->nullOnInvalid(), which can pass null when the doctrine service is not available. This will cause a type error at runtime if Doctrine is not installed.

Note: The PHPCR driver correctly handles this by accepting a nullable parameter: public function __construct(private ?DocumentManagerInterface $documentManager = null) and checking for null in the getDataSource() method.

Recommendation: Either remove ->nullOnInvalid() (since Doctrine is a required dependency), or update the Driver class to accept nullable ManagerRegistry and add proper null checks.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.


$services->set('sylius.grid.data_extractor.property_access', 'Sylius\Component\Grid\DataExtractor\PropertyAccessDataExtractor')
->args([service('property_accessor')]);

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.

Type: Nitpick

💡 Suggestion: Consider using ::class constant for better IDE support and refactoring safety.

Current:

$services->set('sylius.grid.data_extractor.property_access', 'Sylius\Component\Grid\DataExtractor\PropertyAccessDataExtractor')

Suggested:

use Sylius\Component\Grid\DataExtractor\PropertyAccessDataExtractor;

$services->set('sylius.grid.data_extractor.property_access', PropertyAccessDataExtractor::class)

This would make the code more maintainable and catch typos at parse time rather than runtime.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, done with AI

->public();

$services->set('sylius.grid_field.callable', 'Sylius\Component\Grid\FieldTypes\CallableFieldType')
->args([
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.

Type: Suggestion

💡 Code Quality: Consider adding use statements at the top of the file for all the classes being referenced. This would make the file more readable and easier to maintain.

Example:

use Sylius\Component\Grid\FieldTypes\CallableFieldType;
use Sylius\Component\Grid\FieldTypes\DatetimeFieldType;
use Sylius\Component\Grid\FieldTypes\StringFieldType;
use Sylius\Component\Grid\FieldTypes\EnumFieldType;

Then you could use CallableFieldType::class instead of the full string.

Copy link
Copy Markdown
Member Author

@loic425 loic425 Nov 6, 2025

Choose a reason for hiding this comment

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

Done (with AI 👍)


$services->set('sylius.grid_filter.string', 'Sylius\Component\Grid\Filter\StringFilter')
->tag('sylius.grid_filter', ['type' => 'string', 'form_type' => 'Sylius\Bundle\GridBundle\Form\Type\Filter\StringFilterType']);

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.

Type: Suggestion

💡 Code Quality: There's a lot of repetition in the filter definitions (lines 35-110). Each filter follows the same pattern:

  1. Define the filter service with a tag
  2. Create an alias
  3. Define the form type
  4. Create another alias

Consider extracting this into a helper function or loop to reduce duplication:

$filters = [
    'string' => ['filter' => StringFilter::class, 'form' => StringFilterType::class],
    'boolean' => ['filter' => BooleanFilter::class, 'form' => BooleanFilterType::class],
    // ...
];

foreach ($filters as $type => $classes) {
    // Register filter and form type
}

This would make the code more maintainable and less error-prone.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interesting, but it should be done in another PR to keep it simple to review.
We should open an issue instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@loic425
Copy link
Copy Markdown
Member Author

loic425 commented Nov 6, 2025

@Prometee Everything is fixed I suppose, but we'll need a good review, cause opencode did one error with FQCN.

@Prometee
Copy link
Copy Markdown
Contributor

Prometee commented Nov 6, 2025

@loic425 I only see remaining class string here :

  • src/Bundle/Resources/config/services/integrations/doctrine/orm.php
  • src/Bundle/Resources/config/services/integrations/twig/templating.php
  • src/Bundle/Resources/config/services/integrations/sylius_currency_bundle.php
  • src/Bundle/Resources/config/services/integrations/twig.php

@NoResponseMate NoResponseMate merged commit 58ffe29 into Sylius:1.15 Nov 7, 2025
10 checks passed
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.

3 participants