Closed brandonkelly closed 7 years ago
Then perhaps we should change the behaviour:
The current implementation requires complimentary getProperty and setProperty existence. The existence of $_property is not checked.
I wouldn't worry about whether a private $_property
exists at all.
These are the checks it should have:
yii\base\Object
/^get[A-Z]/
with 0 required arguments (it may have arguments if they have a default value, e.g. getFoo($bar = 'bar')
)/^set[A-Z]/
with 1 required argument (it may have additional arguments if they have default values, e.g. setFoo($foo, $bar = 'bar')
)For determining the type, it should be a combination of all the unique types from:
@return
type@param
typeFor example:
<?php
namespace craft;
use yii\base\Object;
/**
* Class Foo
*/
class Foo extends Object
{
private $_bar;
/**
* @return string|null
*/
public function getBar()
{
return $this->_bar;
}
/**
* @param string $bar
*/
public function setBar(string $bar)
{
$this->_bar = $bar;
}
}
should get this @property annotation:
@property string|null $type
Oh, I see (ONE or BOTH), will fix and extend test cases
Not sure if this warrants a new issue, but in that example above, clicking the “Annotate properties” button adds this:
* @property \null|\string $bar
Those \
s should not be in there.
@property \null|\string $bar
: fixed, working on the ONE or BOTH approach in the inspection
Now checks ONE or BOTH, with settings for using only BOTH approach.
Example:
The “Missing @property annotations” inspection should be saying this class is missing a
$bar
property, but it doesn’t. It appears to only be checking for setters.If you add this method:
the inspection will work as expected.