-
Notifications
You must be signed in to change notification settings - Fork 19
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: reformat and modernize large parts of the code base #111
base: main
Are you sure you want to change the base?
Conversation
Code Refactoring
Styles
TestsContributorsCommit-Lint commandsYou can trigger Commit-Lint actions by commenting on this PR:
|
Hey, @adevade lots of interesting changes here 👍🏼 . Will take us a hot minute to review. I wanted to double-check and see if it made sense to review this per-commit or if just reading the diff is better. I want to tackle this piecemeal if possible. IE, does each commit stand on its own or do they depend on each other for passing tests? It's fine either way, I just want to avoid reading over work that gets re-written a commit or two later. Thanks for your hard work on this, excited for the chance to review it! |
Description
This is a rather large PR, with some tweaks to both the tests and source code. However, all tests are still passing with 100% coverage. There should be no breaking changes.
General
InvalidArgumentException
everywhere, to get rid of the leading\
setUseHttps()
andsetSignKey()
to match constructor orderUrlBuilder::VERSION
constantI created a public constant on the main class, so it can be used for both the library param and for all tests. This removes the
$version
property, but since that was private it was only used withing the class.Constructor Promotion
In the constructor of both
UrlBuilder
andUrlHelper
I've refactored to using Constructor Promotion. In simple words, it lets you declare the property directly in the constructor.Null Coalescing Operator
This is a shorter form for checking if a variable -- or a key in an array -- is set, and setting a fallback value if it's not. (Docs)
Building srcsets
Earlier the srcsets were built directly using string concatenation. I've switched to building up an array of the individual strings and then gluing them together in the return.
I've switched from
for
loops toforeach
loops, since they're generally easier to read (IMO).Also, in
createDPRSrcSet
, I'm using the keys fromDPR_QUALITIES
instead of the separateTARGET_RATIOS
which seems superfluous.README
I've updated the README to use the same formatting as the rest of the code. Also some of the examples were out of date with the actual results. I don't know if the test file for the README is needed, really? Easy to forget updating it when making changes.
Tests
I've defined a
HOST
constant to ensure the tests call the same domain. Before it was bothdemo.imgix.net
anddemos.imgix.net
.Most tests now use named arguments to keep the default values for
useHttps
andsignKey
, and disabling the library param. Ex.new UrlBuilder('demos.imgix.net', includeLibraryParam: false)
$params
and$options
arrays has been inlined.The library param has been disabled on many tests, where it wasn't needed. The reduces noise and makes it easier to se what is really being tested.
Some methods has been reordered in
UrlBuilderTest
.Checklist