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

[7.x] Changed fixed value, used laravel string helper function #31080

Closed
wants to merge 15 commits into from

Conversation

pathak-vikash
Copy link
Contributor

@pathak-vikash pathak-vikash commented Jan 9, 2020

This PR is about remove fixed counter ( like 7 for 'base64:') and used laravel Str:after() helper function to improve code readability.

Edited:

This PR is based on #31069

@jmarcher
Copy link
Contributor

jmarcher commented Jan 9, 2020

I found that most of the changes made the code less readable.

@Miguel-Serejo
Copy link

Is this necessary? At most I could see a comment being added to clarify what the numbers mean, but they're pretty self-explanatory in most cases.

I also don't like the introduction of the $prefix variables. The code would be more readable as Str::after($key, 'base64:')in my opinion, as these are fixed values.

@pathak-vikash
Copy link
Contributor Author

pathak-vikash commented Jan 9, 2020

Hi @jmarcher & @36864 the code would be more readable. As let's take an example

// Before
if (Str::startsWith($header, 'Bearer ')) {
    return Str::substr($header, 7);
}

In the example above, it doesn't make sense to keep the value as fixed: 7. Now the change in this PR like:

// After
if (Str::startsWith($header, $prefix = 'Bearer ')) {
    return Str::after($header, $prefix);
}

Also defining the variable $prefix to avoid duplicate checks with string token and make more sense to read as The value after this prefix.

@jmarcher I'm open to update this if you feels any portion of code you feels not readable. Please point me there I'll update.

FYI, the requested changes based on the previous #31069

@Miguel-Serejo
Copy link

My concern here is that we're hindering performance for a subjective increase in readability that could be achieved with a simple comment.

Yes, it's a minor performance hit, but it's also a minor increase in readability.
I don't think anyone looking at this could would be confused as to what substr($key, 7) does in the context of the previous if (Str::startsWith($key, 'base64:')) { statement.

The one point where a change would be useful, in my opinion, is in the dynamicWhere function, but the same could be accomplished with the following:

// trim leading "where" from method name
$finder = substr($method, 5); 

As for the referenced PR, I also disagree with the changes on the same terms, but wasn't around to voice my opinions before it got merged. That one is even worse because the encryption provider is registered on every request, while the files changed in this PR are less used.

Also for some additional context, I offer #30960 which was merged as a strict micro-optimization, arguably at the cost of readability according to some people.

@pathak-vikash
Copy link
Contributor Author

pathak-vikash commented Jan 9, 2020

@36864 I'm checking this for 10k requests and it's producing me the similar result for both of the case. There would be some very minnor impact for this change... but not as much as in terms of readability it may acceptable.

@taylorotwell
Copy link
Member

If nothing is broken I think it's fine.

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

Successfully merging this pull request may close these issues.

None yet

4 participants