Automatically resolve the flag's type if it's a class string#146
Automatically resolve the flag's type if it's a class string#146taylorotwell merged 1 commit intolaravel:1.xfrom
Conversation
|
@RVxLab, this does not seem to work. I'm opening a PR to revert the change but would love to know if you tested this and I'm doing something wrong before we merge it. I've tested via PHPStan and it never seems to return the class instance. Always mixed. See below for the test: <?php
class MyFeatureClass
{
//
}
/** @var Laravel\Pennant\Drivers\Decorator $feature */
// ... //
$var = $feature->instance('foo');
PHPStan\Testing\assertType('mixed', $var);
$var = $feature->instance('NonExistentClass');
PHPStan\Testing\assertType('mixed', $var);
$var = $feature->instance(MyFeatureClass::class);
PHPStan\Testing\assertType('MyFeatureClass', $var);
|
|
Hi @timacdonald, I tested this end to end in PHPStorm and the typings looked mostly correct. I wasn't even aware PHPStan had functions like this. The way I tested it was by creating a blank Laravel project and adding Pennant through a local repository. Then I created a class-based flag with a method in it: <?php
namespace App\Features;
use Illuminate\Support\Lottery;
class MyFeatureClass
{
/**
* Resolve the feature's initial value.
*/
public function resolve(mixed $scope): mixed
{
return false;
}
public function doSomething(): void
{
//
}
}PhpStorm was able to pick that method up correctly.
Doing this with a string gives the expected behaviour as well.
When I use your testing method I get the same result as you did and I have no clue why since the parameter is a Removing the I really can't explain this, sadly. Probably do that revert and I'll try again another time. |
|
No worries. Thanks for trying. I did try and get it working myself, but had no luck. |
|
@timacdonald Just for a bit of guidance; the void errors above in @RVxLab PHPStan logs are because of the facade docblock were incorrect. I've fixed that in the following PR (not released yet): #147 |
I was about to make a reply about that, though it got reverted in b0ef334 through a Github Action. https://github.com/laravel/pennant/blob/1.x/.github/workflows/facade.yml |
|
@maartenpaauw, my test above is calling the |




This PR extends the docblock of the
instancemethod to automatically resolve the feature flag's class if it's a class string.