mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -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();
|
||||
|
Reference in New Issue
Block a user