kalessil / yii2inspections

MIT License
31 stars 3 forks source link

Missing @property annotations, loop #33

Open craiglondon opened 5 years ago

craiglondon commented 5 years ago

My environment MacOS Sierra PHPStorm 2018.3.1 Yii2Inspections 1.0.3 Yii 2.0.15.1

In my model, an ActiveQuery property was not annotated.

image

Here is the code for the property to be annotated

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBillType(): \yii\db\ActiveQuery
    {
        return $this->hasOne(BillTypeForm::class, ['iBillTypePK' => 'iBillTypeFk']);
    }

I clicked the "Annotate properties" button. * @property \yii\db\ActiveQuery $billType was added to the PHPDoc block.

I run the inspection again, and the same property is determined to be annotated.

Another slightly strange thing about it, it doesn't add it as the last property, it adds it to the second to last.

Before "Annotate properties"

 * @property string $Amount
 * @property string $Subtotal

After "Annotate properties"

 * @property string $Amount
 * @property \yii\db\ActiveQuery $billType
 * @property string $Subtotal

If I click the "Annotate properties" button again, I'll get a duplicate property line, and then a newly detected error.

 * @property string $Amount
 * @property \yii\db\ActiveQuery $billType
 * @property \yii\db\ActiveQuery $billType
 * @property string $Subtotal

image

kalessil commented 5 years ago

Hi @craiglondon, thank you for reporting. I'll take a look what happens here, hopefully with a solution. Currently, I re-working plugin build scripts and come back to this when all works again.

kalessil commented 5 years ago

@brandonkelly, @samdark: do we need to add @property annotation for getters returning ActiveQuery as well (or we do stick to scalar types only)?

samdark commented 5 years ago

@kalessil that's magical part of the framework. In fact, these are relations so while getter method return ActiveQuery, property is a result of this query. Annotation should be the following for the case:

 * @property BillTypeForm $billType
kalessil commented 5 years ago

Awesome, thank you @samdark for the prompt answer!