Add phpstan level 7(#544)

This commit is contained in:
Saeed Vaziry
2025-03-12 13:31:10 +01:00
committed by GitHub
parent c22bb1fa80
commit 493cbb0849
437 changed files with 4505 additions and 2193 deletions

View File

@ -16,12 +16,13 @@
* @property string $command
* @property Carbon $created_at
* @property Carbon $updated_at
* @property Collection<CommandExecution> $executions
* @property Collection<int, CommandExecution> $executions
* @property ?CommandExecution $lastExecution
* @property Site $site
*/
class Command extends AbstractModel
{
/** @use HasFactory<\Database\Factories\CommandFactory> */
use HasFactory;
protected $fillable = [
@ -38,32 +39,42 @@ public static function boot(): void
{
parent::boot();
static::deleting(function (Command $command) {
static::deleting(function (Command $command): void {
$command->executions()->delete();
});
}
/**
* @return BelongsTo<Site, covariant $this>
*/
public function site(): BelongsTo
{
return $this->belongsTo(Site::class);
}
/**
* @return array<string>
*/
public function getVariables(): array
{
$variables = [];
preg_match_all('/\${(.*?)}/', $this->command, $matches);
foreach ($matches[1] as $match) {
$variables[] = $match;
}
$variables = $matches[1];
return array_unique($variables);
}
/**
* @return HasMany<CommandExecution, covariant $this>
*/
public function executions(): HasMany
{
return $this->hasMany(CommandExecution::class);
}
/**
* @return HasOne<CommandExecution, covariant $this>
*/
public function lastExecution(): HasOne
{
return $this->hasOne(CommandExecution::class)->latest();