mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +02:00
Even more static analysis!
This commit is contained in:
parent
c7bf124a15
commit
e9ea5b1cae
@ -20,20 +20,20 @@ class Fractal extends SpatieFractal
|
|||||||
public function createData(): Scope
|
public function createData(): Scope
|
||||||
{
|
{
|
||||||
// Set the serializer by default.
|
// Set the serializer by default.
|
||||||
if (is_null($this->serializer)) {
|
if (empty($this->serializer)) {
|
||||||
$this->serializer = new PanelSerializer();
|
$this->serializer = new PanelSerializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Automatically set the paginator on the response object if the
|
// Automatically set the paginator on the response object if the
|
||||||
// data being provided implements a paginator.
|
// data being provided implements a paginator.
|
||||||
if (is_null($this->paginator) && $this->data instanceof LengthAwarePaginator) {
|
if ($this->data instanceof LengthAwarePaginator) {
|
||||||
$this->paginator = new IlluminatePaginatorAdapter($this->data);
|
$this->paginator = new IlluminatePaginatorAdapter($this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the resource name is not set attempt to pull it off the transformer
|
// If the resource name is not set attempt to pull it off the transformer
|
||||||
// itself and set it automatically.
|
// itself and set it automatically.
|
||||||
if (
|
if (
|
||||||
is_null($this->resourceName)
|
empty($this->resourceName)
|
||||||
&& $this->transformer instanceof TransformerAbstract
|
&& $this->transformer instanceof TransformerAbstract
|
||||||
&& method_exists($this->transformer, 'getResourceName')
|
&& method_exists($this->transformer, 'getResourceName')
|
||||||
) {
|
) {
|
||||||
|
@ -22,7 +22,6 @@ class ApiController extends Controller
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private AlertsMessageBag $alert,
|
private AlertsMessageBag $alert,
|
||||||
private KeyCreationService $keyCreationService,
|
private KeyCreationService $keyCreationService,
|
||||||
private ViewFactory $view,
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
use Illuminate\View\Factory as ViewFactory;
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Services\Helpers\SoftwareVersionService;
|
use App\Services\Helpers\SoftwareVersionService;
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ class BaseController extends Controller
|
|||||||
/**
|
/**
|
||||||
* BaseController constructor.
|
* BaseController constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(private SoftwareVersionService $version, private ViewFactory $view)
|
public function __construct(private SoftwareVersionService $version)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ class DatabaseController extends Controller
|
|||||||
private HostCreationService $creationService,
|
private HostCreationService $creationService,
|
||||||
private HostDeletionService $deletionService,
|
private HostDeletionService $deletionService,
|
||||||
private HostUpdateService $updateService,
|
private HostUpdateService $updateService,
|
||||||
private ViewFactory $view
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ class CreateServerController extends Controller
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private AlertsMessageBag $alert,
|
private AlertsMessageBag $alert,
|
||||||
private ServerCreationService $creationService,
|
private ServerCreationService $creationService,
|
||||||
private ViewFactory $view
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ class AdvancedController extends Controller
|
|||||||
private AlertsMessageBag $alert,
|
private AlertsMessageBag $alert,
|
||||||
private ConfigRepository $config,
|
private ConfigRepository $config,
|
||||||
private Kernel $kernel,
|
private Kernel $kernel,
|
||||||
private ViewFactory $view
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ class IndexController extends Controller
|
|||||||
private AlertsMessageBag $alert,
|
private AlertsMessageBag $alert,
|
||||||
private Kernel $kernel,
|
private Kernel $kernel,
|
||||||
private SoftwareVersionService $versionService,
|
private SoftwareVersionService $versionService,
|
||||||
private ViewFactory $view
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ class MailController extends Controller
|
|||||||
private ConfigRepository $config,
|
private ConfigRepository $config,
|
||||||
private Encrypter $encrypter,
|
private Encrypter $encrypter,
|
||||||
private Kernel $kernel,
|
private Kernel $kernel,
|
||||||
private ViewFactory $view
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,10 +50,9 @@ class StartupController extends ClientApiController
|
|||||||
*/
|
*/
|
||||||
public function update(UpdateStartupVariableRequest $request, Server $server): array
|
public function update(UpdateStartupVariableRequest $request, Server $server): array
|
||||||
{
|
{
|
||||||
/** @var \App\Models\EggVariable $variable */
|
|
||||||
$variable = $server->variables()->where('env_variable', $request->input('key'))->first();
|
$variable = $server->variables()->where('env_variable', $request->input('key'))->first();
|
||||||
|
|
||||||
if (is_null($variable) || !$variable->user_viewable) {
|
if (!$variable || !$variable->user_viewable) {
|
||||||
throw new BadRequestHttpException('The environment variable you are trying to edit does not exist.');
|
throw new BadRequestHttpException('The environment variable you are trying to edit does not exist.');
|
||||||
} elseif (!$variable->user_editable) {
|
} elseif (!$variable->user_editable) {
|
||||||
throw new BadRequestHttpException('The environment variable you are trying to edit is read-only.');
|
throw new BadRequestHttpException('The environment variable you are trying to edit is read-only.');
|
||||||
|
@ -69,7 +69,7 @@ class LoginCheckpointController extends AbstractLoginController
|
|||||||
} else {
|
} else {
|
||||||
$decrypted = $this->encrypter->decrypt($user->totp_secret);
|
$decrypted = $this->encrypter->decrypt($user->totp_secret);
|
||||||
|
|
||||||
if ($this->google2FA->verifyKey($decrypted, (string) $request->input('authentication_code') ?? '', config('panel.auth.2fa.window'))) {
|
if ($this->google2FA->verifyKey($decrypted, (string) $request->input('authentication_code'), config('panel.auth.2fa.window'))) {
|
||||||
Event::dispatch(new ProvidedAuthenticationToken($user));
|
Event::dispatch(new ProvidedAuthenticationToken($user));
|
||||||
|
|
||||||
return $this->sendLoginResponse($user, $request);
|
return $this->sendLoginResponse($user, $request);
|
||||||
|
@ -27,7 +27,9 @@ class ResourceBelongsToServer
|
|||||||
public function handle(Request $request, \Closure $next): mixed
|
public function handle(Request $request, \Closure $next): mixed
|
||||||
{
|
{
|
||||||
$params = $request->route()->parameters();
|
$params = $request->route()->parameters();
|
||||||
if (is_null($params) || !$params['server'] instanceof Server) {
|
|
||||||
|
$server = $params['server'] ?? null;
|
||||||
|
if (!$server instanceof Server) {
|
||||||
throw new \InvalidArgumentException('This middleware cannot be used in a context that is missing a server in the parameters.');
|
throw new \InvalidArgumentException('This middleware cannot be used in a context that is missing a server in the parameters.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@ class RequireTwoFactorAuthentication
|
|||||||
*/
|
*/
|
||||||
public function handle(Request $request, \Closure $next): mixed
|
public function handle(Request $request, \Closure $next): mixed
|
||||||
{
|
{
|
||||||
/** @var \App\Models\User $user */
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$uri = rtrim($request->getRequestUri(), '/') . '/';
|
$uri = rtrim($request->getRequestUri(), '/') . '/';
|
||||||
$current = $request->route()->getName();
|
$current = $request->route()->getName();
|
||||||
@ -44,6 +43,8 @@ class RequireTwoFactorAuthentication
|
|||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
|
|
||||||
$level = (int) config('panel.auth.2fa_required');
|
$level = (int) config('panel.auth.2fa_required');
|
||||||
// If this setting is not configured, or the user is already using 2FA then we can just
|
// If this setting is not configured, or the user is already using 2FA then we can just
|
||||||
// send them right through, nothing else needs to be checked.
|
// send them right through, nothing else needs to be checked.
|
||||||
|
@ -37,12 +37,12 @@ abstract class ApplicationApiRequest extends FormRequest
|
|||||||
throw new PanelException('An ACL resource must be defined on API requests.');
|
throw new PanelException('An ACL resource must be defined on API requests.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var ApiKey $token */
|
|
||||||
$token = $this->user()->currentAccessToken();
|
$token = $this->user()->currentAccessToken();
|
||||||
if ($token instanceof TransientToken) {
|
if ($token instanceof TransientToken) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var ApiKey $token */
|
||||||
if ($token->key_type === ApiKey::TYPE_ACCOUNT) {
|
if ($token->key_type === ApiKey::TYPE_ACCOUNT) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ class Egg extends Model
|
|||||||
*/
|
*/
|
||||||
public function getCopyScriptInstallAttribute(): ?string
|
public function getCopyScriptInstallAttribute(): ?string
|
||||||
{
|
{
|
||||||
if (!is_null($this->script_install) || is_null($this->copy_script_from)) {
|
if (!empty($this->script_install) || empty($this->copy_script_from)) {
|
||||||
return $this->script_install;
|
return $this->script_install;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ class Egg extends Model
|
|||||||
*/
|
*/
|
||||||
public function getCopyScriptEntryAttribute(): string
|
public function getCopyScriptEntryAttribute(): string
|
||||||
{
|
{
|
||||||
if (!is_null($this->script_entry) || is_null($this->copy_script_from)) {
|
if (!empty($this->script_entry) || empty($this->copy_script_from)) {
|
||||||
return $this->script_entry;
|
return $this->script_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ class Egg extends Model
|
|||||||
*/
|
*/
|
||||||
public function getCopyScriptContainerAttribute(): string
|
public function getCopyScriptContainerAttribute(): string
|
||||||
{
|
{
|
||||||
if (!is_null($this->script_container) || is_null($this->copy_script_from)) {
|
if (!empty($this->script_container) || empty($this->copy_script_from)) {
|
||||||
return $this->script_container;
|
return $this->script_container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,6 @@ class InitiateBackupService
|
|||||||
// Get the oldest backup the server has that is not "locked" (indicating a backup that should
|
// Get the oldest backup the server has that is not "locked" (indicating a backup that should
|
||||||
// never be automatically purged). If we find a backup we will delete it and then continue with
|
// never be automatically purged). If we find a backup we will delete it and then continue with
|
||||||
// this process. If no backup is found that can be used an exception is thrown.
|
// this process. If no backup is found that can be used an exception is thrown.
|
||||||
/** @var \App\Models\Backup $oldest */
|
|
||||||
$oldest = $successful->where('is_locked', false)->orderBy('created_at')->first();
|
$oldest = $successful->where('is_locked', false)->orderBy('created_at')->first();
|
||||||
if (!$oldest) {
|
if (!$oldest) {
|
||||||
throw new TooManyBackupsException($server->backup_limit);
|
throw new TooManyBackupsException($server->backup_limit);
|
||||||
|
@ -94,40 +94,23 @@ class DatabaseManagementService
|
|||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$database = null;
|
return $this->connection->transaction(function () use ($data, &$database) {
|
||||||
|
$database = $this->createModel($data);
|
||||||
|
|
||||||
try {
|
$this->dynamic->set('dynamic', $data['database_host_id']);
|
||||||
return $this->connection->transaction(function () use ($data, &$database) {
|
|
||||||
$database = $this->createModel($data);
|
|
||||||
|
|
||||||
$this->dynamic->set('dynamic', $data['database_host_id']);
|
$database->createDatabase($database->database);
|
||||||
|
$database->createUser(
|
||||||
|
$database->username,
|
||||||
|
$database->remote,
|
||||||
|
$this->encrypter->decrypt($database->password),
|
||||||
|
$database->max_connections
|
||||||
|
);
|
||||||
|
$database->assignUserToDatabase($database->database, $database->username, $database->remote);
|
||||||
|
$database->flush();
|
||||||
|
|
||||||
$database->createDatabase($database->database);
|
return $database;
|
||||||
$database->createUser(
|
});
|
||||||
$database->username,
|
|
||||||
$database->remote,
|
|
||||||
$this->encrypter->decrypt($database->password),
|
|
||||||
$database->max_connections
|
|
||||||
);
|
|
||||||
$database->assignUserToDatabase($database->database, $database->username, $database->remote);
|
|
||||||
$database->flush();
|
|
||||||
|
|
||||||
return $database;
|
|
||||||
});
|
|
||||||
} catch (Exception $exception) {
|
|
||||||
try {
|
|
||||||
if ($database instanceof Database) {
|
|
||||||
$database->dropDatabase($database->database);
|
|
||||||
$database->dropUser($database->username, $database->remote);
|
|
||||||
$database->flush();
|
|
||||||
}
|
|
||||||
} catch (Exception) {
|
|
||||||
// Do nothing here. We've already encountered an issue before this point so no
|
|
||||||
// reason to prioritize this error over the initial one.
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $exception;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,10 +27,9 @@ class ProcessScheduleService
|
|||||||
*/
|
*/
|
||||||
public function handle(Schedule $schedule, bool $now = false): void
|
public function handle(Schedule $schedule, bool $now = false): void
|
||||||
{
|
{
|
||||||
/** @var \App\Models\Task $task */
|
|
||||||
$task = $schedule->tasks()->orderBy('sequence_id')->first();
|
$task = $schedule->tasks()->orderBy('sequence_id')->first();
|
||||||
|
|
||||||
if (is_null($task)) {
|
if (!$task) {
|
||||||
throw new DisplayException('Cannot process schedule for task execution: no tasks are registered.');
|
throw new DisplayException('Cannot process schedule for task execution: no tasks are registered.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ parameters:
|
|||||||
- app/
|
- app/
|
||||||
|
|
||||||
# Level 9 is the highest level
|
# Level 9 is the highest level
|
||||||
level: 3
|
level: 4
|
||||||
|
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
# Prologue\Alerts defines its methods from its configuration file dynamically
|
# Prologue\Alerts defines its methods from its configuration file dynamically
|
||||||
|
Loading…
x
Reference in New Issue
Block a user