Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary Function Call #19838

Closed
justin-oh opened this issue May 1, 2024 · 1 comment
Closed

Unnecessary Function Call #19838

justin-oh opened this issue May 1, 2024 · 1 comment
Labels
hasPR A Pull Request has already been submitted for this issue.
Milestone

Comments

@justin-oh
Copy link

In the documentation for Compiler Passes in Bundles, the example shows:

// src/MyBundle/MyBundle.php
namespace App\MyBundle;

use App\DependencyInjection\Compiler\CustomPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class MyBundle extends Bundle
{
    public function build(ContainerBuilder $container): void
    {
        parent::build($container);

        $container->addCompilerPass(new CustomPass());
    }
}

However, the call to the parent function is unnecessary because the Bundle class's implementation of the function is empty:

/**
 * This method can be overridden to register compilation passes,
 * other extensions, ...
 *
 * @return void
 */
public function build(ContainerBuilder $container)
{
}

Also, shouldn't anything related to bundles in documentation of 6.1 and beyond be extending AbstractBundle?

@javiereguiluz
Copy link
Member

About your first question, we always call the parent method because even if today might be empty, those parent methods could change in the future, so the code must be ready for that.

About the second question: yes, we should use AbstractBundle everywhere. We did some recent changes related to this (see #19793) but we need to update more examples. Thanks!

@javiereguiluz javiereguiluz added this to the 6.4 milestone May 9, 2024
@javiereguiluz javiereguiluz added the hasPR A Pull Request has already been submitted for this issue. label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hasPR A Pull Request has already been submitted for this issue.
Projects
None yet
Development

No branches or pull requests

2 participants