From f8c1530450df6b64e6fecd62c76a82252dc3d417 Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Thu, 16 Jan 2025 01:47:12 +0000 Subject: [PATCH] code formatting --- composer.json | 3 +- src/Auth/README.md | 2 +- src/Notification/CanSendNotification.php | 8 +++++- src/Notification/Channel/ChannelInterface.php | 2 +- src/Notification/Channel/DatabaseChannel.php | 2 +- src/Notification/Channel/MailChannel.php | 3 +- src/Notification/Notification.php | 16 +++++------ src/Queue/Adapters/BeanstalkdAdapter.php | 1 + src/Queue/Adapters/SQSAdapter.php | 21 ++++++++------ src/Queue/Connection.php | 7 +++-- src/Queue/ProducerService.php | 28 +++++++++---------- src/Queue/WorkerService.php | 4 +-- src/Router/Route.php | 6 ++-- src/Router/Router.php | 16 ++++------- src/Security/Crypto.php | 6 ++-- src/Security/Hash.php | 4 +-- src/Security/Tokenize.php | 14 +++++++--- src/Storage/Service/FTPService.php | 2 +- tests/Filesystem/FTPServiceTest.php | 2 +- 19 files changed, 79 insertions(+), 68 deletions(-) diff --git a/composer.json b/composer.json index 5f9ba5bd..f1a73098 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "fakerphp/faker": "^1.20", "neitanod/forceutf8": "^2.0", "ramsey/uuid": "^4.7", - "ext-ftp": "*" + "ext-ftp": "*", + "ext-openssl": "*" }, "require-dev": { "pda/pheanstalk": "^5.0", diff --git a/src/Auth/README.md b/src/Auth/README.md index 35f3d1fd..7704540a 100644 --- a/src/Auth/README.md +++ b/src/Auth/README.md @@ -8,7 +8,7 @@ use Bow\Http\Exception\UnauthorizedException; $auth = auth(); -$logged = $auth->attemps(["username" => "name@example.com", "password" => "password"]); +$logged = $auth->attempts(["username" => "name@example.com", "password" => "password"]); if (!$logged) { throw new UnauthorizedException("Access denied"); diff --git a/src/Notification/CanSendNotification.php b/src/Notification/CanSendNotification.php index 1bedd618..5081a344 100644 --- a/src/Notification/CanSendNotification.php +++ b/src/Notification/CanSendNotification.php @@ -4,7 +4,13 @@ trait CanSendNotification { - public function sendNotification(Notification $notification) + /** + * Send notification from authenticate user + * + * @param Notification $notification + * @return void + */ + public function sendNotification(Notification $notification): void { $notification->process($this); } diff --git a/src/Notification/Channel/ChannelInterface.php b/src/Notification/Channel/ChannelInterface.php index 08cedc74..c6b528d5 100644 --- a/src/Notification/Channel/ChannelInterface.php +++ b/src/Notification/Channel/ChannelInterface.php @@ -10,5 +10,5 @@ interface ChannelInterface * @param mixed $message * @return void */ - public function send(mixed $message); + public function send(mixed $message): void; } diff --git a/src/Notification/Channel/DatabaseChannel.php b/src/Notification/Channel/DatabaseChannel.php index 8174ef2e..a37efc86 100644 --- a/src/Notification/Channel/DatabaseChannel.php +++ b/src/Notification/Channel/DatabaseChannel.php @@ -12,7 +12,7 @@ class DatabaseChannel implements ChannelInterface * @param mixed $message * @return void */ - public function send(mixed $message) + public function send(mixed $message): void { } } diff --git a/src/Notification/Channel/MailChannel.php b/src/Notification/Channel/MailChannel.php index 1ba081d5..b5424426 100644 --- a/src/Notification/Channel/MailChannel.php +++ b/src/Notification/Channel/MailChannel.php @@ -4,7 +4,6 @@ use Bow\Mail\Mail; use Bow\Mail\Message; -use Bow\Notification\Channel\ChannelInterface; class MailChannel implements ChannelInterface { @@ -14,7 +13,7 @@ class MailChannel implements ChannelInterface * @param mixed $message * @return void */ - public function send(mixed $message) + public function send(mixed $message): void { if ($message instanceof Message) { Mail::getInstance()->send($message); diff --git a/src/Notification/Notification.php b/src/Notification/Notification.php index 21ee69d5..25a5dc27 100644 --- a/src/Notification/Notification.php +++ b/src/Notification/Notification.php @@ -22,7 +22,7 @@ abstract class Notification /** * Returns the available channels to be used * - * @param \Bow\Database\Barry\Model $notifiable + * @param Model $notifiable * @return array */ abstract public function channels(Model $notifiable): array; @@ -30,20 +30,18 @@ abstract public function channels(Model $notifiable): array; /** * Send notification to mail * - * @param \Bow\Database\Barry\Model $notifiable - * @return mixed + * @param Model $notifiable + * @return Message|null */ public function toMail(Model $notifiable): ?Message { - $message = new Message(); - - return $message; + return new Message(); } /** * Send notification to database * - * @param \Bow\Database\Barry\Model $notifiable + * @param Model $notifiable * @return array */ public function toDatabase(Model $notifiable): array @@ -53,10 +51,10 @@ public function toDatabase(Model $notifiable): array /** * Process the notification - * @param \Bow\Database\Barry\Model $notifiable + * @param Model $notifiable * @return void */ - final function process(Model $notifiable) + final function process(Model $notifiable): void { $channels = $this->channels($notifiable); diff --git a/src/Queue/Adapters/BeanstalkdAdapter.php b/src/Queue/Adapters/BeanstalkdAdapter.php index d2d22a97..1b8d811a 100644 --- a/src/Queue/Adapters/BeanstalkdAdapter.php +++ b/src/Queue/Adapters/BeanstalkdAdapter.php @@ -134,6 +134,7 @@ public function run(string $queue = null): void } else { $this->pheanstalk->release($job, $this->getPriority($producer->getPriority()), $producer->getDelay()); } + $this->sleep(1); } } diff --git a/src/Queue/Adapters/SQSAdapter.php b/src/Queue/Adapters/SQSAdapter.php index de98bbf9..ab108597 100644 --- a/src/Queue/Adapters/SQSAdapter.php +++ b/src/Queue/Adapters/SQSAdapter.php @@ -99,10 +99,12 @@ public function size(string $queue): int * * @param ?string $queue * @return void + * @throws \ErrorException */ public function run(?string $queue = null): void { $this->sleep($this->sleep ?? 5); + $message = null; try { $result = $this->sqs->receiveMessage([ @@ -130,13 +132,13 @@ public function run(?string $queue = null): void error_log($e->getMessage()); app('logger')->error($e->getMessage(), $e->getTrace()); - if (isset($message)) { - cache( - "job:failed:" . $message["ReceiptHandle"], - $message["Body"] - ); + if (!$message) { + $this->sleep(1); + return; } + cache("job:failed:" . $message["ReceiptHandle"], $message["Body"]); + // Check if producer has been loaded if (!isset($producer)) { $this->sleep(1); @@ -144,17 +146,17 @@ public function run(?string $queue = null): void } // Execute the onException method for notify the producer - // and let developper to decide if the job should be delete + // and let developer decide if the job should be deleted $producer->onException($e); - // Check if the job should be delete + // Check if the job should be deleted if ($producer->jobShouldBeDelete()) { - $result = $this->sqs->deleteMessage([ + $this->sqs->deleteMessage([ 'QueueUrl' => $this->config["url"], 'ReceiptHandle' => $message['ReceiptHandle'] ]); } else { - $result = $this->sqs->changeMessageVisibilityBatch([ + $this->sqs->changeMessageVisibilityBatch([ 'QueueUrl' => $this->config["url"], 'Entries' => [ 'Id' => $producer->getId(), @@ -163,6 +165,7 @@ public function run(?string $queue = null): void ], ]); } + $this->sleep(1); } } diff --git a/src/Queue/Connection.php b/src/Queue/Connection.php index 270da540..eab80b1f 100644 --- a/src/Queue/Connection.php +++ b/src/Queue/Connection.php @@ -30,7 +30,7 @@ class Connection /** * The supported connection * - * @param array + * @var array */ private static array $connections = [ "beanstalkd" => BeanstalkdAdapter::class, @@ -50,11 +50,12 @@ public function __construct(array $config) } /** - * Push the new connection support in connectors managment + * Push the new connection support in connectors management * * @param string $name - * @param string $name + * @param string $classname * @return bool + * @throws ErrorException */ public static function pushConnection(string $name, string $classname): bool { diff --git a/src/Queue/ProducerService.php b/src/Queue/ProducerService.php index e3ef0cde..e7c9a05b 100644 --- a/src/Queue/ProducerService.php +++ b/src/Queue/ProducerService.php @@ -55,14 +55,14 @@ abstract class ProducerService /** * Define the job attempts * - * @return integer + * @var int */ - protected int $attemps = 2; + protected int $attempts = 2; /** * ProducerService constructor * - * @return mixed + * @return void */ public function __construct() { @@ -90,13 +90,13 @@ public function getId(): string } /** - * Get the producer attemps + * Get the producer attempts * * @return int */ - public function getAttemps(): int + public function getAttempts(): int { - return $this->attemps; + return $this->attempts; } /** @@ -132,14 +132,14 @@ final public function getDelay(): int /** - * Set the producer attemps + * Set the producer attempts * - * @param int $attemps + * @param int $attempts * @return void */ - public function setAttemps(int $attemps) + public function setAttempts(int $attempts): void { - $this->attemps = $attemps; + $this->attempts = $attempts; } /** @@ -148,7 +148,7 @@ public function setAttemps(int $attemps) * @param int $retry * @return void */ - final public function setRetry(int $retry) + final public function setRetry(int $retry): void { $this->retry = $retry; } @@ -159,7 +159,7 @@ final public function setRetry(int $retry) * @param string $queue * @return void */ - final public function setQueue(string $queue) + final public function setQueue(string $queue): void { $this->queue = $queue; } @@ -169,7 +169,7 @@ final public function setQueue(string $queue) * * @param int $delay */ - final public function setDelay(int $delay) + final public function setDelay(int $delay): void { $this->delay = $delay; } @@ -208,7 +208,7 @@ public function onException(\Throwable $e) /** * Process the producer * - * @return mixed + * @return void */ abstract public function process(): void; } diff --git a/src/Queue/WorkerService.php b/src/Queue/WorkerService.php index df7c5f1f..d02454dc 100644 --- a/src/Queue/WorkerService.php +++ b/src/Queue/WorkerService.php @@ -18,8 +18,8 @@ class WorkerService /** * Make connection base on default name * - * @param string $name - * @return QueueAdapter + * @param QueueAdapter $connection + * @return void */ public function setConnection(QueueAdapter $connection): void { diff --git a/src/Router/Route.php b/src/Router/Route.php index 850459c3..be09fe6c 100644 --- a/src/Router/Route.php +++ b/src/Router/Route.php @@ -6,7 +6,6 @@ use Bow\Container\Action; use Bow\Configuration\Loader; -use Bow\Http\Request; class Route { @@ -133,10 +132,10 @@ public function middleware(array|string $middleware): Route * Add the url rules * * @param array|string $where - * @param string $regex_constraint + * @param string|null $regex_constraint * @return Route */ - public function where(array|string $where, $regex_constraint = null): Route + public function where(array|string $where, string $regex_constraint = null): Route { $other_rule = is_array($where) ? $where : [$where => $regex_constraint]; @@ -176,6 +175,7 @@ public function call(): mixed * To give a name to the road * * @param string $name + * @return Route */ public function name(string $name): Route { diff --git a/src/Router/Router.php b/src/Router/Router.php index 2cd16ffb..50678b0c 100644 --- a/src/Router/Router.php +++ b/src/Router/Router.php @@ -31,7 +31,7 @@ class Router protected string $prefix = ''; /** - * @var string + * @var ?string */ protected ?string $special_method = null; @@ -74,7 +74,7 @@ class Router * Define the request _method parse to form * for helper router define a good method called * - * @var string + * @var ?string */ private ?string $magic_method; @@ -136,11 +136,7 @@ public function prefix(string $prefix, callable $cb): Router $prefix = '/' . $prefix; } - if ($this->prefix !== null) { - $this->prefix .= $prefix; - } else { - $this->prefix = $prefix; - } + $this->prefix .= $prefix; call_user_func_array($cb, [$this]); @@ -304,7 +300,7 @@ public function patch(string $path, callable|string|array $cb): Route * Add a OPTIONS route * * @param string $path - * @param callable $cb + * @param callable|string|array $cb * @return Route */ public function options(string $path, callable|string|array $cb): Route @@ -317,7 +313,7 @@ public function options(string $path, callable|string|array $cb): Route * When the define code match with response code. * * @param int $code - * @param callable $cb + * @param callable|array|string $cb * @return Router */ public function code(int $code, callable|array|string $cb): Router @@ -370,7 +366,7 @@ private function pushHttpVerb(string|array $methods, string $path, callable|stri /** * Start loading a route. * - * @param string|array $method + * @param string|array $methods * @param string $path * @param callable|string|array $cb * @return Route diff --git a/src/Security/Crypto.php b/src/Security/Crypto.php index a36ed974..fc883589 100644 --- a/src/Security/Crypto.php +++ b/src/Security/Crypto.php @@ -11,7 +11,7 @@ class Crypto /** * The security key * - * @var string + * @var ?string */ private static ?string $key = null; @@ -26,9 +26,9 @@ class Crypto * Set the key * * @param string $key - * @param string $cipher + * @param string|null $cipher */ - public static function setKey(string $key, ?string $cipher = null) + public static function setKey(string $key, ?string $cipher = null): void { static::$key = $key; diff --git a/src/Security/Hash.php b/src/Security/Hash.php index 75c12322..746fd618 100644 --- a/src/Security/Hash.php +++ b/src/Security/Hash.php @@ -22,10 +22,10 @@ public static function create(string $value): string|int|null /** * Allows to have a value and when the hash has failed it returns false. * - * @param string $value + * @param string $value * @return string|int|null */ - public static function make($value): string|int|null + public static function make(string $value): string|int|null { [$hash_method, $options] = static::getHashConfig(); diff --git a/src/Security/Tokenize.php b/src/Security/Tokenize.php index b6bb9c86..638c5c35 100644 --- a/src/Security/Tokenize.php +++ b/src/Security/Tokenize.php @@ -4,6 +4,7 @@ namespace Bow\Security; +use Bow\Session\Exception\SessionException; use Bow\Session\Session; use Bow\Support\Str; @@ -19,8 +20,9 @@ class Tokenize /** * Csrf token creator * - * @param int $time + * @param int|null $time * @return bool + * @throws SessionException */ public static function makeCsrfToken(?int $time = null): bool { @@ -62,8 +64,9 @@ public static function make(): string /** * Get a csrf token generate * - * @param int $time + * @param int|null $time * @return ?array + * @throws SessionException */ public static function csrf(int $time = null): ?array { @@ -75,8 +78,9 @@ public static function csrf(int $time = null): ?array /** * Check if the token expires * - * @param int $time + * @param int|null $time * @return bool + * @throws SessionException */ public static function csrfExpired(int $time = null): bool { @@ -103,6 +107,7 @@ public static function csrfExpired(int $time = null): bool * @param string $token * @param bool $strict * @return bool + * @throws SessionException */ public static function verify(string $token, bool $strict = false): bool { @@ -119,7 +124,7 @@ public static function verify(string $token, bool $strict = false): bool $status = true; if ($strict) { - $status = $status && static::CsrfExpired(time()); + $status = static::CsrfExpired(time()); } return $status; @@ -129,6 +134,7 @@ public static function verify(string $token, bool $strict = false): bool * Destroy the token * * @return void + * @throws SessionException */ public static function clear(): void { diff --git a/src/Storage/Service/FTPService.php b/src/Storage/Service/FTPService.php index 4c814c42..1929ef54 100644 --- a/src/Storage/Service/FTPService.php +++ b/src/Storage/Service/FTPService.php @@ -288,7 +288,7 @@ public function put(string $file, string $content): bool $stream = $this->readStream($file); if (!$stream) { - return false; + return false; } fwrite($stream, $content); diff --git a/tests/Filesystem/FTPServiceTest.php b/tests/Filesystem/FTPServiceTest.php index e63a190f..d0510a08 100644 --- a/tests/Filesystem/FTPServiceTest.php +++ b/tests/Filesystem/FTPServiceTest.php @@ -91,7 +91,7 @@ public function test_rename_file() public function test_copy_file_and_the_contents() { $this->createFile($this->ftp_service, 'file-copy.txt', 'something'); - + $result = $this->ftp_service->copy('file-copy.txt', 'test.txt'); $this->assertTrue($result);