Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mamazu
Copy link
Contributor

@mamazu mamazu commented Mar 24, 2024

Using phpactor to generate return types for phpactor code.

What is in here:

  • Specifying types and reducing the amount of "fromUnknown" calls since now we know what types there are.
  • Removing deprecated isClass and isInterface calls from the code and replaced them with instanceof calls.
  • Moving one of the tests from array returns to Generator (and include the tests).

return isset($this->filesystems[$name]);
}

/** @return array<string> */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to the interface.

Comment on lines -57 to -69

if (is_array($path)) {
return self::fromParts($path);
}

if ($path instanceof SplFileInfo) {
return self::fromSplFileInfo($path);
}

throw new RuntimeException(sprintf(
'Do not know how to create FilePath from "%s"',
is_object($path) ? get_class($path) : gettype($path)
));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those were only used in tests. The rest of the code already uses the correct function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

they were used by tests though, removing this changes the purpose of the function (fromUnknown)

Copy link
Collaborator

Choose a reason for hiding this comment

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

can rename to fromFilePathOrString for clarity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I mean most other function that deal with paths also except both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If possible I would like to remove those kinds of methods entirely and reduce the amount of "unknown"s from phpactor. :D

/**
* @return Generator<string,array{string,string,Closure(ReflectionTrait): void}>
*/
public function provideReflectionTrait(): Generator
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function was partly returning an array and partly generator. So now there are more tests at the end that now also get executed.

@mamazu mamazu force-pushed the better_types branch 2 times, most recently from 692b8b7 to d9ed777 Compare March 25, 2024 20:55
@dantleech dantleech merged commit 7f00bf8 into phpactor:master Mar 29, 2024
@dantleech
Copy link
Collaborator

thanks

@mamazu mamazu deleted the better_types branch March 29, 2024 11:05
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