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

Do not create Controller instance every time getLinkHref is called #91

Closed
Pepelac opened this issue Mar 19, 2019 · 1 comment
Closed

Comments

@Pepelac
Copy link

Pepelac commented Mar 19, 2019

Hi,

is there any reason of not doing this

$this->controller = BaseController::getController() ?? new BaseController();

instead of this?

$this->controller = new BaseController;

Now it creates router instance (and other stuff) every time \BenFreke\MenuManager\Models\Menu::getLinkHref is called.

@benfreke
Copy link
Owner

Hi

  1. The ?? operator is only available from PHP 7, and when this code was written it needed to work in PHP56. That line was added nearly 5 years ago.
  2. It's not good.

Better code would be to instantiate the $this->controller in the construct method.

You're right though. This is bad code and if I had any tests when I wrote this 5 years ago I would have hopefully picked this up.

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

No branches or pull requests

2 participants