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

Added type annotation to all methods #203

Open
wants to merge 10 commits into
base: 1.3
Choose a base branch
from

Conversation

tolik518
Copy link
Contributor

@tolik518 tolik518 commented May 19, 2023

I'm currently working on adding Docblocks with type annotations and throws to all methods to get full type-hinting through the IDE.

@tolik518 tolik518 marked this pull request as ready for review May 21, 2023 11:11
@tolik518
Copy link
Contributor Author

tolik518 commented May 21, 2023

The PR is now ready for review @lyrixx

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. But I think this is not what we should do. See the first comment.

Comment on lines +174 to +178
* @param string $command
* @param array $args
* @param array $options
*
* @return Process
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not the way to go. Instead we should add really PHP type.
It's easily doable for argument since PHP allow it in a BC manner.
But the return type will be a huge BC break!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyrixx Could you please elaborate on what you mean by BC?

You mean instead of

     * @param string $command
     * @param array  $args
     * @param array  $options
     *
     * @return Process
     private static function getProcess($command, array $args = [], array $options = [])

one should write

     * @param string $command
     * @param array  $args
     * @param array  $options
     private static function getProcess($command, array $args = [], array $options = []): Process

I'm all for it but I thought this wouldn't work with PHP 5.6. If it does work - it won't work with mixed types at least.

If this is ok, could I go one step further and add PHP typing for all the arguments as well to ditch the DocBlocks entirely?

Copy link
Member

@lyrixx lyrixx May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BC mean Backward Compatible. see https://symfony.com/bc ; We should use the same policy.

The patch would be:

    /**
     * This internal method is used to create a process object.
     *
     * @return Process
     */
    private static function getProcess(string $command, array $args = [], array $options = [])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, I misunderstood you completely the first time.
So if I understood you correctly this time then I should add typed arguments instead of DocBlocks, but leave the Return in the DocBlocks?

I haven't worked much where BC was needed, so its better I'll ask you.
Is this case also valid when writing instead of this

    /**
     * @param Commit | string $hash
     *
     * @return Tag[] An array of Tag objects
     */
    public function resolveTags($hash)

this

    /**
     * @return Tag[] An array of Tag objects
     */
    public function resolveTags(Commit | string $hash)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this project is still compatible with PHP 5.6 😨 ! So wee cannot write this code (union). But with PHP 8+, you can 👍🏼

I'll bump this and I'll do a new release (next week I guess)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. Should I change everything that's not a union-type to php types instead of DocBlocks though like you required?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just figured out that primitive type-hints weren't supported until PHP 7.0.
So all I can do is add native type-hints only for arrays and objects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you wait a bit? I'll bump some things...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #204 🎉

lyrixx and others added 2 commits May 22, 2023 17:00
* Bump minimal PHP version to 8.0

* Fixed ci when pushing on origin repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants