proget-hq / phpstan-yii2

Yii2 extension for PHPStan
MIT License
52 stars 17 forks source link

Handle already-initialized components #15

Closed EtienneBruines closed 5 years ago

EtienneBruines commented 5 years ago

Sometimes the components within the configuration may already be configured.

This change adds support for following config syntax:

return [
    'components' => [
        'client' => new \GuzzleHttp\Client(),
    ],
]
EtienneBruines commented 5 years ago

Hello @akondas, thank you for your code review. It is much appreciated.

As per your suggestion, I changed !is_array to is_object. Additionally, I added a check to verify that if it's not an object, it should at least be an array - otherwise the code will crash in a weird manner anyways. Now a more useful error message is thrown.

Two tests were added:

I wasn't quite sure what the getComponentIdentityClassById method was supposed to do, so I didn't change it. I had to add a special condition for getComponentClassById to make it perform as expected.

If you have any points of improvements, don't hesitate to mention them :smile:

akondas commented 5 years ago

Great, thanks for tests :+1: