-
Notifications
You must be signed in to change notification settings - Fork 650
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
DocblockTypeContradiction when comparing @property, using prefix type, through magic getter with actual class constant #3272
Labels
Comments
I found these snippets: https://psalm.dev/r/86b57553b8<?php
/**
* @property FooBar::TYPE_* $type
*/
class FooBar {
public const TYPE_FOO = 'foo';
public const TYPE_BAR = 'bar';
/** @var FooBar::TYPE_* */
private $_type;
public function __construct()
{
$this->_type = FooBar::TYPE_FOO;
}
/**
* @param string $name
* @return mixed
*/
public function __get(string $name)
{
$getter = 'get' . $name;
return $this->$getter();
}
/**
* @return FooBar::TYPE_*
*/
public function getType()
{
return $this->_type;
}
}
$foobar = new FooBar();
$test = $foobar->type === FooBar::TYPE_BAR;
print($test);
$test = $foobar->getType() === FooBar::TYPE_BAR;
print($test);
|
Same thing with assignment through magic setter, only InvalidPropertyAssignmentValue instead: |
I found these snippets: https://psalm.dev/r/b7f029181f<?php
/**
* @property FooBar::TYPE_* $type
*/
class FooBar {
public const TYPE_FOO = 'foo';
public const TYPE_BAR = 'bar';
/** @var FooBar::TYPE_* */
private $_type;
public function __construct()
{
$this->_type = FooBar::TYPE_FOO;
}
/**
* @param string $name
* @return mixed
*/
public function __get(string $name)
{
$getter = 'get' . $name;
return $this->$getter();
}
/**
* @param string $name
* @param mixed $value
* @return void
*/
public function __set(string $name, mixed $value)
{
$setter = 'set' . $name;
$this->$setter($value);
}
/**
* @return FooBar::TYPE_*
*/
public function getType()
{
return $this->_type;
}
/**
* @param FooBar::TYPE_* $value
* @return void
*/
public function setType(string $value)
{
$this->_type = $value;
}
}
$foobar = new FooBar();
$test = $foobar->type === FooBar::TYPE_BAR;
print($test);
$test = $foobar->getType() === FooBar::TYPE_BAR; // OK
print($test);
$foobar->type = FooBar::TYPE_BAR;
$foobar->setType(FooBar::TYPE_BAR); // OK
|
weirdan
added a commit
to weirdan/psalm
that referenced
this issue
Jul 18, 2021
Fixes vimeo#4344 Fixes vimeo#5663 Fixes vimeo#5639 Fixes vimeo#5955 Fixes vimeo#3272
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://psalm.dev/r/86b57553b8
The text was updated successfully, but these errors were encountered: