chore: add phpstan static analysis minimum (#4511)

This commit is contained in:
Lance Pioch 2022-11-28 11:56:03 -05:00 committed by GitHub
parent 3f7e2a565f
commit a1a52754ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
67 changed files with 561 additions and 279 deletions

View file

@ -26,9 +26,9 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property string|null $startup
* @property bool $script_is_privileged
* @property string|null $script_install
* @property string $script_entry
* @property string $script_container
* @property int|null $copy_script_from
* @property ?string $script_entry
* @property ?string $script_container
* @property ?int $copy_script_from
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string|null $copy_script_install

View file

@ -18,8 +18,9 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
* @property \Carbon\CarbonImmutable $created_at
* @property \Carbon\CarbonImmutable $updated_at
* @property bool $required
* @property \Pterodactyl\Models\Egg $egg
* @property \Pterodactyl\Models\ServerVariable $serverVariable
* @property Egg $egg
* @property ServerVariable $serverVariable
* @property string $field_type
*
* The "server_value" variable is only present on the object if you've loaded this model
* using the server relationship.

View file

@ -155,6 +155,7 @@ abstract class Model extends IlluminateModel
return;
}
/** @var \Illuminate\Validation\Validator $validator */
$validator = $this->getValidator();
$validator->setData(
// Trying to do self::toArray() here will leave out keys based on the whitelist/blacklist

View file

@ -6,6 +6,7 @@ use Illuminate\Support\Str;
use Symfony\Component\Yaml\Yaml;
use Illuminate\Container\Container;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -24,20 +25,24 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough;
* @property bool $maintenance_mode
* @property int $memory
* @property int $memory_overallocate
* @property int $sum_memory
* @property int $disk
* @property int $disk_overallocate
* @property int $sum_disk
* @property int $upload_size
* @property string $daemon_token_id
* @property string $daemon_token
* @property int $daemonListen
* @property int $daemonSFTP
* @property string $daemonBase
* @property int $servers_count
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property \Pterodactyl\Models\Location $location
* @property \Pterodactyl\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
* @property \Pterodactyl\Models\Allocation[]|\Illuminate\Database\Eloquent\Collection $allocations
* @property Location $location
* @property int[]|\Illuminate\Support\Collection $ports
* @property Mount[]|Collection $mounts
* @property Server[]|Collection $servers
* @property Allocation[]|Collection $allocations
*/
class Node extends Model
{
@ -220,11 +225,21 @@ class Node extends Model
return $this->hasMany(Allocation::class);
}
public function loadServerSums(): self
{
$this->loadSum('servers as sum_memory', 'memory');
$this->loadSum('servers as sum_disk', 'disk');
return $this;
}
/**
* Returns a boolean if the node is viable for an additional server to be placed on it.
*/
public function isViable(int $memory, int $disk): bool
public function isViable(int $memory = 0, int $disk = 0): bool
{
$this->loadServerSums();
$memoryLimit = $this->memory * (1.0 + ($this->memory_overallocate / 100.0));
$diskLimit = $this->disk * (1.0 + ($this->disk_overallocate / 100.0));

View file

@ -2,6 +2,7 @@
namespace Pterodactyl\Models;
/** @property string $value */
class Setting extends Model
{
/**

View file

@ -11,6 +11,7 @@ use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Builder;
use Pterodactyl\Models\Traits\HasAccessTokens;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Pterodactyl\Traits\Helpers\AvailableLanguages;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\Access\Authorizable;
@ -129,6 +130,10 @@ class User extends Model implements
'root_admin',
];
protected $appends = [
'md5',
];
/**
* Cast values to correct type.
*/
@ -259,6 +264,13 @@ class User extends Model implements
return $this->morphToMany(ActivityLog::class, 'subject', 'activity_log_subjects');
}
public function md5(): Attribute
{
return Attribute::make(
get: fn () => md5(strtolower($this->email)),
);
}
/**
* Returns all the servers that a user can access by way of being the owner of the
* server, or because they are assigned as a subuser for that server.