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

Check whether function parameter+return has typehint #20

Closed
wants to merge 2 commits into from

Conversation

adaamz
Copy link
Contributor

@adaamz adaamz commented May 6, 2018

Hi,

  1. added check that every function parameter has typehint
  2. added check that every function has return typehint

@Majkl578
Copy link
Contributor

Majkl578 commented May 6, 2018

Missing tests for closures, which must not be covered by this rule.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented May 6, 2018 via email

@adaamz
Copy link
Contributor Author

adaamz commented May 7, 2018

@Majkl578 closures as direct parameter of function or stored into variable?
Function stored into variable is not checked with this rule, but I can add test for it :-)

@adaamz adaamz force-pushed the master branch 3 times, most recently from 5d0143d to c60ca9d Compare May 11, 2018 20:52
@adaamz
Copy link
Contributor Author

adaamz commented May 11, 2018

@Majkl578 Added closure test.
@ondrejmirtes Rgistered both rules to rules.neon

@Majkl578
Copy link
Contributor

closures as direct parameter of function or stored into variable?

Both. There is no supported way to document closure signature.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Please apply the same changes also to the second rule.

public function processNode(Node $node, Scope $scope): array
{
if ($scope->isInClass()) {
throw new \PHPStan\ShouldNotHappenException();
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?

throw new \PHPStan\ShouldNotHappenException();
}

$functionReflection = $this->broker->getCustomFunction(new Node\Name($node->name, $node->getAttributes()), $scope);
Copy link
Member

Choose a reason for hiding this comment

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

I think that passing the attributes is not necessary.


if ($parameterType instanceof MixedType && !$parameterType->isExplicitMixed()) {
return sprintf(
'Function %s() has parameter $%s with no typehint specified',
Copy link
Member

Choose a reason for hiding this comment

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

Please add a dot . at the end. If there are other rules from you without this trailing dot, please add it in a new commit as well 😊


public function setBroker(Broker $broker): void
{
$this->broker = $broker;
Copy link
Member

Choose a reason for hiding this comment

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

In rules, you can pass broker directly into the constructor.

private $broker;

/**
* @return string Class implementing \PhpParser\Node
Copy link
Member

Choose a reason for hiding this comment

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

This phpDoc is not necessary.

@ondrejmirtes
Copy link
Member

Missing tests for closures, which must not be covered by this rule.

Closures have different node type so I think the test is not necessary.

@ondrejmirtes
Copy link
Member

Fixed and merged, 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.

3 participants