Skip to content

Commit

Permalink
Cleanup docblocks added return types (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinvdpol authored Aug 12, 2024
1 parent 87cabcf commit fb5a31d
Show file tree
Hide file tree
Showing 54 changed files with 178 additions and 304 deletions.
5 changes: 3 additions & 2 deletions src/ActionPendingChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Lorisleiva\Actions;

use Illuminate\Foundation\Bus\PendingChain;
use Illuminate\Foundation\Bus\PendingDispatch;
use Lorisleiva\Actions\Concerns\AsJob;

class ActionPendingChain extends PendingChain
{
public function dispatch()
public function dispatch(): ?PendingDispatch
{
/** @var $job AsJob */
if ($this->usesAsJobTrait($job = $this->job)) {
Expand All @@ -17,7 +18,7 @@ public function dispatch()
return parent::dispatch();
}

public function usesAsJobTrait($job)
public function usesAsJobTrait($job): bool
{
return is_string($job)
&& class_exists($job)
Expand Down
2 changes: 1 addition & 1 deletion src/ActionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ActionRequest extends FormRequest
{
use ValidateActions;

public function validateResolved()
public function validateResolved(): void
{
// Cancel the auto-resolution trait.
}
Expand Down
16 changes: 11 additions & 5 deletions src/ActionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

class ActionServiceProvider extends ServiceProvider
{
public function register()
/**
* Register any application services.
*/
public function register(): void
{
$this->app->scoped(ActionManager::class, function () {
return new ActionManager([
Expand All @@ -24,10 +27,13 @@ public function register()
$this->extendActions();
}

public function boot()
/**
* Bootstrap any application services.
*/
public function boot(): void
{
if ($this->app->runningInConsole()) {
// publish Stubs File
// Publish Stubs File
$this->publishes([
__DIR__ . '/Console/stubs/action.stub' => base_path('stubs/action.stub'),
], 'stubs');
Expand All @@ -39,7 +45,7 @@ public function boot()
}
}

protected function extendActions()
protected function extendActions(): void
{
$this->app->beforeResolving(function ($abstract, $parameters, Application $app) {
if ($abstract === ActionManager::class) {
Expand All @@ -50,7 +56,7 @@ protected function extendActions()
// Fix conflict with package: barryvdh/laravel-ide-helper.
// @see https://github.com/lorisleiva/laravel-actions/issues/142
$classExists = class_exists($abstract);
} catch (\ReflectionException $exception) {
} catch (\ReflectionException) {
return;
}

Expand Down
8 changes: 3 additions & 5 deletions src/BacktraceFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class BacktraceFrame
public ?string $class;
public ?string $function;
public bool $isStatic;

/** @var mixed|null */
public $object;
public mixed $object;

public function __construct(array $frame)
{
Expand All @@ -36,9 +34,9 @@ public function instanceOf(string $superClass): bool
|| is_subclass_of($this->class, $superClass);
}

public function matches(string $class, string $method, ?bool $isStatic = null)
public function matches(string $class, string $method, ?bool $isStatic = null): bool
{
$matchesStatic = is_null($isStatic) ? true : ($this->isStatic === $isStatic);
$matchesStatic = is_null($isStatic) || $this->isStatic === $isStatic;

return $this->instanceOf($class)
&& $this->function === $method
Expand Down
7 changes: 2 additions & 5 deletions src/Concerns/AsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ trait AsController
{
/**
* @see static::handle()
* @param mixed ...$arguments
* @return mixed
*/
public function __invoke(...$arguments)
public function __invoke(mixed ...$arguments): mixed
{
return $this->handle(...$arguments);
}

/**
* This empty method is required to enable controller middleware on the action.
* @see https://github.com/lorisleiva/laravel-actions/issues/199
* @return array
*/
public function getMiddleware()
public function getMiddleware(): array
{
return [];
}
Expand Down
37 changes: 3 additions & 34 deletions src/Concerns/AsFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

trait AsFake
{
/**
* @return MockInterface
*/
public static function mock(): MockInterface
{
if (static::isFake()) {
Expand All @@ -25,9 +22,6 @@ public static function mock(): MockInterface
return static::setFakeResolvedInstance($mock);
}

/**
* @return MockInterface
*/
public static function spy(): MockInterface
{
if (static::isFake()) {
Expand All @@ -37,41 +31,26 @@ public static function spy(): MockInterface
return static::setFakeResolvedInstance(Mockery::spy(static::class));
}

/**
* @return MockInterface
*/
public static function partialMock(): MockInterface
{
return static::mock()->makePartial();
}

/**
* @return Expectation|ExpectationInterface|HigherOrderMessage
*/
public static function shouldRun()
public static function shouldRun(): Expectation|ExpectationInterface|HigherOrderMessage
{
return static::mock()->shouldReceive('handle');
}

/**
* @return Expectation|ExpectationInterface|HigherOrderMessage
*/
public static function shouldNotRun()
public static function shouldNotRun(): Expectation|ExpectationInterface|HigherOrderMessage
{
return static::mock()->shouldNotReceive('handle');
}

/**
* @return Expectation|ExpectationInterface|HigherOrderMessage|MockInterface
*/
public static function allowToRun()
public static function allowToRun(): Expectation|ExpectationInterface|HigherOrderMessage|MockInterface
{
return static::spy()->allows('handle');
}

/**
* @return bool
*/
public static function isFake(): bool
{
return app()->isShared(static::getFakeResolvedInstanceKey());
Expand All @@ -85,26 +64,16 @@ public static function clearFake(): void
app()->forgetInstance(static::getFakeResolvedInstanceKey());
}

/**
* @param MockInterface $fake
* @return MockInterface
*/
protected static function setFakeResolvedInstance(MockInterface $fake): MockInterface
{
return app()->instance(static::getFakeResolvedInstanceKey(), $fake);
}

/**
* @return MockInterface|null
*/
protected static function getFakeResolvedInstance(): ?MockInterface
{
return app(static::getFakeResolvedInstanceKey());
}

/**
* @return string
*/
protected static function getFakeResolvedInstanceKey(): string
{
return 'LaravelActions:AsFake:' . static::class;
Expand Down
98 changes: 24 additions & 74 deletions src/Concerns/AsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,34 @@
* @method void configureJob(JobDecorator|UniqueJobDecorator $job)
*
* @property-read int|array $jobBackoff
* @method int|array getJobBackoff(...$parameters)
* @method int|array getJobBackoff()
*
* @property-read \DateTime|int $jobRetryUntil
* @method \DateTime|int getJobRetryUntil(...$parameters)
* @method \DateTime|int getJobRetryUntil()
*
* @method array getJobMiddleware(...$parameters)
* @method array getJobMiddleware()
*
* @method void jobFailed(Throwable $e, ...$parameters)
* @method void jobFailed(Throwable $e)
*
* @method string getJobDisplayName(...$parameters)
* @method string getJobDisplayName()
*
* @method array getJobTags(...$parameters)
* @method array getJobTags()
*
* @property-read int $jobUniqueFor
* @method int getJobUniqueFor(...$parameters)
* @method int getJobUniqueFor()
*
* @property-read int $jobUniqueId
* @method int getJobUniqueId(...$parameters)
* @method int getJobUniqueId()
*
* @method int getJobUniqueVia(...$parameters)
* @method int getJobUniqueVia()
*
* @property-read bool $jobDeleteWhenMissingModels
* @method bool getJobDeleteWhenMissingModels()
*
*/
trait AsJob
{
/**
* @param mixed ...$arguments
* @return JobDecorator|UniqueJobDecorator
*/
public static function makeJob(...$arguments): JobDecorator
public static function makeJob(mixed ...$arguments): JobDecorator
{
if (static::jobShouldBeUnique()) {
return static::makeUniqueJob(...$arguments);
Expand All @@ -61,93 +60,52 @@ public static function makeJob(...$arguments): JobDecorator
return new ActionManager::$jobDecorator(static::class, ...$arguments);
}

/**
* @param mixed ...$arguments
* @return UniqueJobDecorator
*/
public static function makeUniqueJob(...$arguments): UniqueJobDecorator
public static function makeUniqueJob(mixed ...$arguments): UniqueJobDecorator
{
return new ActionManager::$uniqueJobDecorator(static::class, ...$arguments);
}

/**
* @return bool
*/
protected static function jobShouldBeUnique(): bool
{
return is_subclass_of(static::class, ShouldBeUnique::class);
}

/**
* @param mixed ...$arguments
* @return PendingDispatch
*/
public static function dispatch(...$arguments): PendingDispatch
public static function dispatch(mixed ...$arguments): PendingDispatch
{
return new PendingDispatch(static::makeJob(...$arguments));
}

/**
* @param $boolean
* @param mixed ...$arguments
* @return PendingDispatch|Fluent
*/
public static function dispatchIf($boolean, ...$arguments)
public static function dispatchIf(bool $boolean, mixed ...$arguments): PendingDispatch|Fluent
{
return $boolean ? static::dispatch(...$arguments) : new Fluent;
}

/**
* @param $boolean
* @param mixed ...$arguments
* @return PendingDispatch|Fluent
*/
public static function dispatchUnless($boolean, ...$arguments)
public static function dispatchUnless(bool $boolean, mixed ...$arguments): PendingDispatch|Fluent
{
return static::dispatchIf(! $boolean, ...$arguments);
}

/**
* @param mixed ...$arguments
* @return mixed
*/
public static function dispatchSync(...$arguments)
public static function dispatchSync(mixed ...$arguments): mixed
{
return app(Dispatcher::class)->dispatchSync(static::makeJob(...$arguments));
}

/**
* @param mixed ...$arguments
* @return mixed
*/
public static function dispatchNow(...$arguments)
public static function dispatchNow(mixed ...$arguments): mixed
{
return static::dispatchSync(...$arguments);
}

/**
* @param mixed ...$arguments
* @return void
*/
public static function dispatchAfterResponse(...$arguments): void
public static function dispatchAfterResponse(mixed ...$arguments): void
{
static::dispatch(...$arguments)->afterResponse();
}

/**
* @param $chain
* @return ActionPendingChain
*/
public static function withChain($chain): ActionPendingChain
public static function withChain(array $chain): ActionPendingChain
{
return new ActionPendingChain(static::class, $chain);
}

/**
* @param Closure|int|null $times
* @param Closure|null $callback
*/
public static function assertPushed($times = null, Closure $callback = null): void
public static function assertPushed(Closure|int|null $times = null, Closure|null $callback = null): void
{
if ($times instanceof Closure) {
$callback = $times;
Expand Down Expand Up @@ -191,20 +149,12 @@ public static function assertPushed($times = null, Closure $callback = null): vo
}
}

/**
* @param Closure|null $callback
*/
public static function assertNotPushed(Closure $callback = null): void
public static function assertNotPushed(Closure|null $callback = null): void
{
static::assertPushed(0, $callback);
}

/**
* @param string $queue
* @param Closure|int|null $times
* @param Closure|null $callback
*/
public static function assertPushedOn(string $queue, $times = null, Closure $callback = null): void
public static function assertPushedOn(string $queue, Closure|int|null $times = null, Closure|null $callback = null): void
{
if ($times instanceof Closure) {
$callback = $times;
Expand Down
Loading

0 comments on commit fb5a31d

Please sign in to comment.