Bundle configuration with PHP files#436
Conversation
03b3e6a to
0bb07ef
Compare
Prometee
left a comment
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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:
\datetimeshould be\DateTime(capital D) if it were a class reference- 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']);There was a problem hiding this comment.
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()]) |
There was a problem hiding this comment.
Type: Issue
Severity: Medium
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.
|
|
||
| $services->set('sylius.grid.data_extractor.property_access', 'Sylius\Component\Grid\DataExtractor\PropertyAccessDataExtractor') | ||
| ->args([service('property_accessor')]); | ||
|
|
There was a problem hiding this comment.
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.
| ->public(); | ||
|
|
||
| $services->set('sylius.grid_field.callable', 'Sylius\Component\Grid\FieldTypes\CallableFieldType') | ||
| ->args([ |
There was a problem hiding this comment.
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.
|
|
||
| $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']); | ||
|
|
There was a problem hiding this comment.
Type: Suggestion
💡 Code Quality: There's a lot of repetition in the filter definitions (lines 35-110). Each filter follows the same pattern:
- Define the filter service with a tag
- Create an alias
- Define the form type
- 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.
There was a problem hiding this comment.
Interesting, but it should be done in another PR to keep it simple to review.
We should open an issue instead.
77beb6b to
4124984
Compare
4124984 to
d8f956d
Compare
|
@Prometee Everything is fixed I suppose, but we'll need a good review, cause opencode did one error with FQCN. |
|
@loic425 I only see remaining class string here :
|
cdc238a to
9e4581d
Compare
Related to https://github.com/GromNaN/symfony-config-xml-to-php/