Skip to content

docs: remove useless @return BaseConnection|ConnectionInterface on BaseBuilder::db() #8701

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

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Apr 3, 2024

Description

BaseConnection is implements ConnectionInterface so it can be removed from @return doc. Detected by run latest "rector/rector": "dev-main"

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@samsonasik
Copy link
Member Author

Ready to merge 👍

@kenjis
Copy link
Member

kenjis commented Apr 3, 2024

BaseConnection is implements ConnectionInterface so it can be removed from @return doc.

Why? BaseConnection has more public methods than ConnectionInterface.

In fact, the db() returns BaseConnection.
Or the return type ConnectionInterface is incorrect.

Or ConnectionInterface is broken.
Or we don't know how to use interface correctly.
See #4356

@kenjis kenjis changed the title chore: remove useless @return BaseConnection|ConnectionInterface on BaseBuilder::db() docs: remove useless @return BaseConnection|ConnectionInterface on BaseBuilder::db() Apr 3, 2024
@samsonasik
Copy link
Member Author

The problem with including the interface itself in the union make all other type already valid as child of it.

The current usage is incorrect imo, if union type to be used, both should be a class that implement the interface, eg, for param which valid:

/** @param SomeClass|SomeClass2 $param */
public function run(SomeInterface $param)
{
   echo $param->prop;
}

which both SomeClass and SomeClass2 child of SomeInterface and has prop property, so that "more" data is valid.

@samsonasik
Copy link
Member Author

The another solution is mark as BaseConnection instead:

/** @return BaseConnection */
public function db(): ConnectionInterface

@samsonasik
Copy link
Member Author

samsonasik commented Apr 3, 2024

@kenjis I updated to @return BaseConnection a2802a6

@kenjis
Copy link
Member

kenjis commented Apr 3, 2024

@samsonasik Yes, after all, our code is incorrect.
But I think this is better.

/** @return BaseConnection */
public function db(): ConnectionInterface

Because devs expect BaseConnection instead of ConnectionInterface.

@samsonasik
Copy link
Member Author

done 👍

@samsonasik samsonasik merged commit 518b912 into codeigniter4:develop Apr 3, 2024
@samsonasik
Copy link
Member Author

Thank you @kenjis for the review.

@samsonasik samsonasik deleted the chore-return-doc branch April 3, 2024 09:49
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.

2 participants