Skip to content

Conversation

@CReimer
Copy link
Contributor

@CReimer CReimer commented Sep 27, 2025

After level 1 follows level 2

Nothing too exciting here, i guess.

One thing I want to point out. I prefer to check for the right instance in runtime. I just found out you seem to prefer, to declare the type as it should be.

My runtime check makes sure it's the right instance while running
Your approach is valid, too. It should ideally never be different than expected... but it might be

{
if ($date = $this->header(HeaderConsts::DATE)?->getDateTime()) {
return Carbon::instance($date);
$dateHeader = $this->header(HeaderConsts::DATE);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I mean. That's my prefered approach. Runtime checking for the right instance

{
/** @var UntaggedResponse $response */
if (! $response = $this->id($id, $identifier)->first()) {
$response = $this->id($id, $identifier)->first();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And that's your approach. I changed it to have $response directly at the DocTag. It's easier to understand this way... and PHPStan understands it this way

return $this->connection()->fetch($fetch, $uids->all())->mapWithKeys(function (UntaggedResponse $response) {
$data = $response->tokenAt(3);

if (!$data instanceof ListData) {
Copy link
Contributor Author

@CReimer CReimer Sep 27, 2025

Choose a reason for hiding this comment

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

I'm not sure as of right now how you approach exceptions. This is more or less a third approach. For the same problem. -> method returns parent, but specific child is expected

Copy link
Member

Choose a reason for hiding this comment

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

Yea I think this is a good approach -- best to throw an exception here like you've implemented 👍

Copy link
Member

@stevebauman stevebauman left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! I'm going to implement a few formatting adjustments but it appears your branch is locked so I can't push them here. I'll merge this and then make the changes on master 👍

@stevebauman stevebauman merged commit 267ace7 into DirectoryTree:master Sep 27, 2025
8 checks passed
@CReimer CReimer deleted the phpstan-level-2 branch September 29, 2025 06:10
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