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

Add support for @no-named-arguments #5968

Open
MidnightDesign opened this issue Nov 10, 2021 · 6 comments
Open

Add support for @no-named-arguments #5968

MidnightDesign opened this issue Nov 10, 2021 · 6 comments

Comments

@MidnightDesign
Copy link
Contributor

It would be great if PHPStan added support for Psalm's @no-named-arguments.

Example use case: https://phpstan.org/r/65ac2b61-6af2-41b2-87b2-a611439210c3

class Test
{
	/** @var list<string> */
	private array $items;
	
	/**
	 * @no-named-arguments
	 */
	public function __construct(string ...$items): void
	{
		$this->items = $items;
	}
	
	/**
	 * @return list<string>
	 */
	public function getItems(): array {
		return $this->items;
	}
}
@phpstan-bot
Copy link
Contributor

@MidnightDesign After the latest commit in 1.7.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 – 8.1 (1 error)
-==========
-
-13: Property Test::$items (array<int, string>) does not accept array<int|string, string>.
-
-PHP 7.1 – 7.4
-==========
-
 No errors

@ondrejmirtes
Copy link
Member

Part of the work was done already in phpstan/phpstan-src#1349 :)

@phpstan-bot
Copy link
Contributor

@MidnightDesign After the latest push in 1.9.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 – 8.1 (1 error)
-==========
-
-13: Property Test::$items (array<int, string>) does not accept array<int|string, string>.
-
-PHP 7.1 – 7.4
-==========
-
-No errors
+13: Property Test::$items (list<string>) does not accept array<int, string>.
Full report
Line Error
13 Property Test::$items (list<string>) does not accept array<int, string>.

@phpstan-bot
Copy link
Contributor

@MidnightDesign After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 – 8.1 (1 error)
-==========
-
-13: Property Test::$items (array<int, string>) does not accept array<int|string, string>.
-
-PHP 7.1 – 7.4
-==========
-
-No errors
+11: Constructor of class Test has a return type.
Full report
Line Error
11 Constructor of class Test has a return type.

@mhsdesign
Copy link

As pointed out here #10034 (comment) the call site will currently not be validated.

So neither of them raise an error:

new Test(foo: "string");
new Test(...["foo" => "string"]);

fyi. the bot will probably never rest as there is an actual syntax error in your example : void in constructor...

@ondrejmirtes
Copy link
Member

/cc @schlndh Hi, this is very close to what you did with named argument variants.

My idea is: add allowsNamedArguments to ExtendedMethodReflection and FunctionReflection, and check that in function/method/static method rules.

Thank you for considering contributing that 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants