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

refactor: remove $_SERVER['HTTP_HOST'] in RouteCollection #5962

Merged
merged 6 commits into from
May 8, 2022

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented May 5, 2022

Description
Depending on superglobals is bad practice.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the refactor Pull requests that refactor code label May 5, 2022
@kenjis kenjis marked this pull request as draft May 5, 2022 06:35
@kenjis kenjis force-pushed the remove-SERVER-from-route branch from 0b45ebb to 0fce2b8 Compare May 5, 2022 06:57
@kenjis kenjis force-pushed the remove-SERVER-from-route branch from 4e91477 to fe627b3 Compare May 5, 2022 13:01
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

I like this change but that is a lot of adjustments to tests to accommodate it. Is this going to break people's tests if they are using anything HTTP-specific?

@kenjis
Copy link
Member Author

kenjis commented May 8, 2022

Is this going to break people's tests if they are using anything HTTP-specific?

Maybe yes. This PR changes the point that fetches the $_SERVER['HTTP_HOST'] value.
The RouteCollection's constructor fixes the value for the object.

Tests that sets $_SERVER['HTTP_HOST'] value after instantiation of RouteCollection
would break.

The current CI4 code has many property or variable values that can be changed later.
Setters are in many classes, and some classes depend on superglobals like this.
It makes harder to read and use the code because I don't know when the correct value will be set,
when the object state is not invalid.

I want more classes that have complete constructor, and want more immutable classes.
But changes for them will break existing tests...

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

I went and looked through my packages that I thought might set this directly, but none of them so. I think this is highly unlikely to break anything, and it brings good benefits and actually better testability.

@kenjis kenjis marked this pull request as ready for review May 8, 2022 13:07
@kenjis
Copy link
Member Author

kenjis commented May 8, 2022

Good to hear!
Probably there are few people that test RouteCollection and $_SERVER['HTTP_HOST'] directly.
And changing supergloabls after instantiating objects to test is wrong wary to write test code.

@kenjis kenjis merged commit 8265dc2 into codeigniter4:develop May 8, 2022
@kenjis kenjis deleted the remove-SERVER-from-route branch May 8, 2022 23:28
@kenjis kenjis mentioned this pull request May 9, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Pull requests that refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants