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

Adds support for macros #500

Merged
merged 2 commits into from May 5, 2017
Merged

Adds support for macros #500

merged 2 commits into from May 5, 2017

Conversation

mjerwin
Copy link
Contributor

@mjerwin mjerwin commented May 4, 2017

Generates stubs for marcos if the class uses the Marcroable trait.

@barryvdh barryvdh merged commit b76156b into barryvdh:master May 5, 2017
@barryvdh
Copy link
Owner

barryvdh commented May 5, 2017

Cool thanks

@jonnywilliamson
Copy link

@barryvdh Could we get a new tag for a release please?

@mjerwin Fantastic. Thanks so much for this.

@barryvdh
Copy link
Owner

barryvdh commented May 5, 2017

Did you test this?

@barryvdh
Copy link
Owner

barryvdh commented May 5, 2017

You can get it with 2.3.x@dev

@jonnywilliamson
Copy link

I could only pull it in if I used composer --dev require barryvdh/laravel-ide-helper:dev-master but I don't like having dev-master in my composer file. When I tried 2.3.x@dev I only got ver 2.3.2 not this latest commit.

Anyway, I assumed because you have merged it was working so I'm just after testing it.

Mainly I was trying to see if I could get autocomplete when using https://github.com/spatie/laravel-collection-macros

However, after updating to this new commit, and generating a new _ide-helper.php file, I still don't get methods like ->ifAny() on a collection.

I see the PR says that "Generates stubs for macros if the class uses the Macroable trait." but it looks like thats not going to help me in this case.

@mjerwin
Copy link
Contributor Author

mjerwin commented May 5, 2017

Hey @jonnywilliamson,

Sorry, should have made it clearer. This only works on Facades so it currently wouldn't work for the Collection class.

@aledelgo
Copy link

First, thanks for your contribution. this was a really needed feature!

Unfortunately on my environment it doesn't works fine well... i'm on PhpStorm with laravel 5.3

i have this code in a custom registered provider (my code is working fine)

class ResponseMacroServiceProvider extends ServiceProvider {

    /**
     * Perform post-registration booting of services.
     *
     * @return void
     */
    public function boot()
    {



        /**
         * Create a response()->apiResponse(...) function
         */
        Response::macro('apiResponse', function($apiResultObj, $serializazionGroups=null, $includeDefaultGroups=true, $jsonPCallback=null)
        {

            /* custom code here...*/

            return $resp;


        });
    }

}

I see ide-helper correctly generate this in _ide_helper.php file

/**
         * Create a response()->apiResponse(.
         * 
         * ..) function
         *
         * @static 
         */ 
        public static function apiResponse($apiResultObj, $serializazionGroups = null, $includeDefaultGroups = true, $jsonPCallback = null)
        {
            return \Illuminate\Routing\ResponseFactory::apiResponse($apiResultObj, $serializazionGroups, $includeDefaultGroups, $jsonPCallback);
        }

but the IDE don't recognize it in the autocomplete list.
when i write:
return response()->apiResp
the method is not listed in the autocomplete list, and if i write it completely like
return response()->apiResponse($result, [], false);
the method is underlined and marked with a tooltip sayng the method is not found
image

Do you have any idea?

cgxxv pushed a commit to cgxxv/laravel-ide-helper that referenced this pull request Mar 25, 2022
* Adds support for macros

* Fixes formatting
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