Convert hardcoded strings to hintable fields in Contains{One, Many}Test#822
Convert hardcoded strings to hintable fields in Contains{One, Many}Test#822
Conversation
891c458 to
925196d
Compare
tests/ContainsManyTest.php
Outdated
| * | ||
| * @property Line2 $lines @Atk\RefMany() | ||
| * @property string $total_gross @Atk\Field() | ||
| * @property Line2 $lines @Atk\RefOne() |
There was a problem hiding this comment.
always use RefOne, RefMany should be used once load() returns another instance (otherwise you will not be able to laod a model, you must get it thru iterator first)
tests/ContainsManyTest.php
Outdated
| $total = 0; | ||
| foreach ($m->ref('lines') as $line) { | ||
| $total += $line->get('total_gross'); | ||
| foreach ($m->lines as $line) { |
There was a problem hiding this comment.
this is one strong advantage of hintable magic, thanks to #821 foreach value has correct type for phpstan as the iterated model
a73db73 to
c87335f
Compare
c87335f to
f184be7
Compare
| * @return Reference\HasOne | ||
| */ | ||
| public function hasOne(string $link, array $defaults = []): Reference | ||
| public function hasOne(string $link, array $defaults = []) //: Reference |
There was a problem hiding this comment.
otherwise autohinting (from phpdoc) does not work
There was a problem hiding this comment.
Why not add HasOne to Method Signature?
public function hasOne(string $link, array $defaults = []): Reference\HasOne
There was a problem hiding this comment.
because it can be implemented by another class not based on this one
this is almost the no1 issue with Atk
There was a problem hiding this comment.
so you mean a child class could e.g. implement
public function hasOne(string $link, array $defaults = []): Some\Other\Reference
and that would fail if we set the parent signature to Reference\HasOne?
There was a problem hiding this comment.
grml this is ugly. Do you really think adding Reference\HasOne would be an issue? I see return types in method signatures as an important part of good code. While this PR helps IDEs and phpstan and so on using comments, it weakens the method signatures which was something I liked about almost any of your PR: You created stricter, clearer method signatures.
26edb56 to
781497d
Compare
781497d to
17988b4
Compare
0032e48 to
5f9863c
Compare
5f9863c to
36e90f5
Compare
related with #800