helpers icon indicating copy to clipboard operation
helpers copied to clipboard

Replace stub "DummyFunction" with function name

Open mtownsend5512 opened this issue 5 years ago • 2 comments

Previously when users would run php artisan make:helper my_helper_function it would load the stub in like this:

if (!function_exists('DummyFunction')) {

    /**
     * description
     *
     * @param
     * @return
     */
    function DummyFunction()
    {

    }
}

This pull request makes the package generate the stub with the user's defined helper name, like so:

if (!function_exists('my_helper_function')) {

    /**
     * description
     *
     * @param
     * @return
     */
    function my_helper_function()
    {

    }
}

It's a small, but helpful quality of life change.

mtownsend5512 avatar Nov 28 '18 17:11 mtownsend5512

Thanks for the PR!

The intent of the helper file is not to have a 1:1 relationship with the functions within it. Looking back through some of my projects, most of my helper files have multiple functions within them. Even when I only have one function within the file, the function never has the same name as the file.

Unless you have some other thoughts, I think I'm going to pass on this for now. Thanks for submitting, though.

browner12 avatar Nov 28 '18 17:11 browner12

I fully respect your opinion on that. Some thoughts to consider:

  • The package never explicitly gives you the opinion that a 1:1 is not it's intended use. Quite the opposite, you create a helper function and it provides you one dummy function and one dummy !function_exists.
  • What does the PR hurt by adopting the file name as the function name? You know the developer will change the dummy text in every case. With a pre-filled name there is a chance that's what the developer wanted to start out with. Worse case scenario: they change the name just like they would do with the DummyFunction text.
  • It's the Laravel way to generate stubs with the user's input. Every other generation class (Controller, model, exception, job, migration, policy, middleware, mail, listener, event, factory, command, channel, request, provider, etc) replaces the dummy text in the stub.

Anyway, I wanted to thank you for making this package. I use it in every single Laravel app I create (and it never occurred to me not to follow the 1:1 pattern, lol).

mtownsend5512 avatar Nov 28 '18 18:11 mtownsend5512