fix: phpstan level 7 errors in Jobs

This commit is contained in:
Roardom
2024-01-07 07:26:55 +00:00
parent 191ca6e1ab
commit 66660b9c5e
5 changed files with 56 additions and 87 deletions
+52 -33
View File
@@ -48,41 +48,9 @@ class ProcessAnnounce implements ShouldQueue
/**
* Execute the job.
*
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function handle(): void
{
// Check if peer is connectable
$connectable = false;
if (config('announce.connectable_check')) {
$ip = hex2bin($this->ip);
$ip = inet_ntop(pack('A'.\strlen($ip), $ip));
// IPv6 Check
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$ip = '['.$ip.']';
}
$key = $ip.'-'.$this->port.'-'.hex2bin($this->agent);
if (cache()->has('peers:connectable-timer:'.$key)) {
$connectable = cache()->get('peers:connectable:'.$key) === true;
} else {
$connection = @fsockopen($ip, $this->port, $_, $_, 1);
if ($connectable = \is_resource($connection)) {
fclose($connection);
}
cache()->put('peers:connectable:'.$key, $connectable, config('announce.connectable_check_interval'));
cache()->remember('peers:connectable-timer:'.$key, config('announce.connectable_check_interval'), fn () => true);
}
}
/**
* Peer batch upsert.
*
@@ -102,8 +70,59 @@ class ProcessAnnounce implements ShouldQueue
'torrent_id' => $this->torrentId,
'user_id' => $this->userId,
'active' => $this->active,
'connectable' => $connectable,
'connectable' => $this->getConnectableStatus(),
]),
]);
}
/**
* Check if peer is connectable.
*
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
private function getConnectableStatus(): bool
{
if (!config('announce.connectable_check')) {
return false;
}
// Unhex
$ip = hex2bin($this->ip);
if ($ip === false) {
return false;
}
// Pack
$ip = inet_ntop(pack('A'.\strlen($ip), $ip));
if ($ip === false) {
return false;
}
// IPv6 Check
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$ip = '['.$ip.']';
}
$key = $ip.'-'.$this->port.'-'.hex2bin($this->agent);
// Check cache
if (cache()->has('peers:connectable-timer:'.$key)) {
return cache()->get('peers:connectable:'.$key) === true;
}
// Connect
$connection = @fsockopen($ip, $this->port, $_, $_, 1);
if ($connectable = \is_resource($connection)) {
fclose($connection);
}
cache()->put('peers:connectable:'.$key, $connectable, config('announce.connectable_check_interval'));
cache()->remember('peers:connectable-timer:'.$key, config('announce.connectable_check_interval'), fn () => true);
return $connectable;
}
}
+2 -2
View File
@@ -27,7 +27,7 @@ class ProcessBackup implements ShouldQueue
public int $timeout = 0;
public function __construct(protected $option = '')
public function __construct(protected string $option = '')
{
}
@@ -44,7 +44,7 @@ class ProcessBackup implements ShouldQueue
}
if (!empty($this->option)) {
$prefix = str_replace('_', '-', (string) $this->option).'-';
$prefix = str_replace('_', '-', $this->option).'-';
$backupJob->setFilename($prefix.date('Y-m-d-H-i-s').'.zip');
}
+1 -11
View File
@@ -27,20 +27,10 @@ class ProcessMassPM implements ShouldQueue
use Queueable;
use SerializesModels;
/**
* @var mixed
*/
public $sender_id;
/**
* @var mixed
*/
public $receiver_id;
/**
* ProcessMassPM Constructor.
*/
public function __construct(protected $senderId, protected $receiverId, protected $subject, protected $message)
public function __construct(protected int $senderId, protected int $receiverId, protected string $subject, protected string $message)
{
}
+1 -1
View File
@@ -37,7 +37,7 @@ class SendActivationMail implements ShouldQueue
/**
* SendActivationMail Constructor.
*/
public function __construct(public User $user, public $code)
public function __construct(public User $user, public string $code)
{
}
-40
View File
@@ -2115,46 +2115,6 @@ parameters:
count: 1
path: app/Http/Resources/UserResource.php
-
message: "#^Parameter \\#1 \\$hostname of function fsockopen expects string, string\\|false given\\.$#"
count: 1
path: app/Jobs/ProcessAnnounce.php
-
message: "#^Parameter \\#1 \\$string of function strlen expects string, string\\|false given\\.$#"
count: 1
path: app/Jobs/ProcessAnnounce.php
-
message: "#^Method App\\\\Jobs\\\\ProcessBackup\\:\\:__construct\\(\\) has parameter \\$option with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessBackup.php
-
message: "#^Method App\\\\Jobs\\\\ProcessMassPM\\:\\:__construct\\(\\) has parameter \\$message with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessMassPM.php
-
message: "#^Method App\\\\Jobs\\\\ProcessMassPM\\:\\:__construct\\(\\) has parameter \\$receiverId with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessMassPM.php
-
message: "#^Method App\\\\Jobs\\\\ProcessMassPM\\:\\:__construct\\(\\) has parameter \\$senderId with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessMassPM.php
-
message: "#^Method App\\\\Jobs\\\\ProcessMassPM\\:\\:__construct\\(\\) has parameter \\$subject with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessMassPM.php
-
message: "#^Method App\\\\Jobs\\\\SendActivationMail\\:\\:__construct\\(\\) has parameter \\$code with no type specified\\.$#"
count: 1
path: app/Jobs/SendActivationMail.php
-
message: "#^Parameter \\#1 \\$string of function htmlspecialchars expects string, array\\<string\\>\\|string given\\.$#"
count: 1