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

Remove unecessary calls to func_get_args #79

Conversation

alanscott75
Copy link

Hi,

I've suffered from the same issue as flagged up in Issue #77, where passing a single string to the tag() method does nothing. For example:

$article->tag('test'); //does nothing

This is caused by the following code which appears in several places throughout the Taggable.php class:

if(!is_array($tagNames)) {
    $tagNames = func_get_args();
    array_shift($tagNames);
}

When this code runs on a method with only one argument, such as the tag method, it is shifting the only argument off the array, leaving nothing. For scopeWithAllTags and scopeWithAnyTags which both take two parameters, it removes the $query argument, which makes sense.

It looks like this code is there to convert a string value to an array, however immediately after it in all four of the places it appears is a call to makeTagArray which does exactly the same thing. So this block of code is not needed, and given it's causing issues, should be removed.

This was on v2.0.4 of the code, on Laravel 5.1.20 and PHP 5.5

@rtconner
Copy link
Owner

Oh wow. You are right. I feel pretty embarrassed. I've been trying to write unit tests to cover these things but I haven't yet found a way to do that without a database connected.

Anyways, I can't merge this because you stripped it from scopeWithAnyTag and scopeWithAllTags, but I'll do the exact same changes in another commit.

rtconner added a commit that referenced this pull request Oct 23, 2015
@rtconner
Copy link
Owner

Fixed in version 2.0.5

@rtconner rtconner closed this Oct 23, 2015
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.

3 participants