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

Adding better types #2614

Merged
merged 5 commits into from Mar 29, 2024
Merged

Adding better types #2614

merged 5 commits into from Mar 29, 2024

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).

@@ -35,7 +35,6 @@ public function has(string $name): bool
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
10 checks passed
@dantleech
Copy link
Collaborator

thanks

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.

None yet

2 participants