Skip to content

[improvement] PHP 7.4 property generation #856

Closed
phpactor/code-builder
#16

Description

@camilledejoye

Still the same subject :)

Right now the templates use to generates property use a phpdoc block to declare the type.
I would like to add a new templates that will add the type in the property declaration instead.

In order to handle multiple versions I was wondering if we could handle different templates by version.
Like adding a folder templates/7.4 for PHP 7.4 and templates/default if there is directory for the currently configured version.
We would also need to depreciate the templates/ folder without a subdirectory. So it is still used for know if templates/default does not exists.

For the PHP version itself, I think we should resolved it automatically but still provide a way to override it.
For example, I'm working with PHP 7.4 on my computer but at work the project run with PHP 7.2.
So we need to be able to override it.

It's a lot of changes so I would like to know where you stand on that matter.
I think it will be a plus to be able to add functionality in the future but I would understand if you prefer to wait for know and just let the user override the templates itself.

Activity

  1. dantleech commented on Dec 7, 2019

    @dantleech
    Collaborator

    Maybe this can be facilitated by introducing template sets:

    e.g.

    code_builder.import_templates:
        - php/7.4
        - collections
        - phpunit

    As for automatic -- we could dynamically include the php/$php_version set based on a php_version parameter (but default to the running version). But possibly the above could be a good start.

  2. camilledejoye commented on Dec 7, 2019

    @camilledejoye
    ContributorAuthor

    Ok so there is already a way to tell to twig where to look for, great!
    That should do the trick, I just have to look how we handle the override of the templates directory.
    I just need to make sure that <user_dir>/templates/ATemplate.twig has the priority over <phpactor>/templates/default/ATemplate.twig.

    I agree for the version, we should be able to add a parameter in the configuration that we can then inject to our services.
    And make the current PHP version the default if the parameter is not provided.

    I'm currently working on the ClassLikeUpdater because it was coupled with the logic that we can't have a type without a phpdoc block.
    And I also fix some bugs like adding a property for the first time when you already have a trait or constant declared.
    There will be plenty of commits with explanation in the commit message for you to choose which one to keep in the PR.

  3. dantleech commented on Dec 7, 2019

    @dantleech
    Collaborator

    Ok so there is already a way to tell to twig where to look for, great!

    This was a suggested feature :) You can override templates but you can only put the templates globally or per project, which isn't great. Having and being able to distribute (as extensions) template sets would be good.

    But on second thoughts this isn't necessarily related to what we want to do here, so just ignore that suggestion for now 👀 we can decide which default template to load, I would guess this could even be done in the extension rather in than in the library.

    I'm currently working on the ClassLikeUpdater

    Cool :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions