Skip to content

Commit 3458928

Browse files
authored
Merge pull request #311 from bowphp/refactor/code-base
code formatting
2 parents a6cf59f + f8c1530 commit 3458928

19 files changed

Lines changed: 79 additions & 68 deletions

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"fakerphp/faker": "^1.20",
1717
"neitanod/forceutf8": "^2.0",
1818
"ramsey/uuid": "^4.7",
19-
"ext-ftp": "*"
19+
"ext-ftp": "*",
20+
"ext-openssl": "*"
2021
},
2122
"require-dev": {
2223
"pda/pheanstalk": "^5.0",

src/Auth/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Bow\Http\Exception\UnauthorizedException;
88

99
$auth = auth();
1010

11-
$logged = $auth->attemps(["username" => "name@example.com", "password" => "password"]);
11+
$logged = $auth->attempts(["username" => "name@example.com", "password" => "password"]);
1212

1313
if (!$logged) {
1414
throw new UnauthorizedException("Access denied");

src/Notification/CanSendNotification.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
trait CanSendNotification
66
{
7-
public function sendNotification(Notification $notification)
7+
/**
8+
* Send notification from authenticate user
9+
*
10+
* @param Notification $notification
11+
* @return void
12+
*/
13+
public function sendNotification(Notification $notification): void
814
{
915
$notification->process($this);
1016
}

src/Notification/Channel/ChannelInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ interface ChannelInterface
1010
* @param mixed $message
1111
* @return void
1212
*/
13-
public function send(mixed $message);
13+
public function send(mixed $message): void;
1414
}

src/Notification/Channel/DatabaseChannel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DatabaseChannel implements ChannelInterface
1212
* @param mixed $message
1313
* @return void
1414
*/
15-
public function send(mixed $message)
15+
public function send(mixed $message): void
1616
{
1717
}
1818
}

src/Notification/Channel/MailChannel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Bow\Mail\Mail;
66
use Bow\Mail\Message;
7-
use Bow\Notification\Channel\ChannelInterface;
87

98
class MailChannel implements ChannelInterface
109
{
@@ -14,7 +13,7 @@ class MailChannel implements ChannelInterface
1413
* @param mixed $message
1514
* @return void
1615
*/
17-
public function send(mixed $message)
16+
public function send(mixed $message): void
1817
{
1918
if ($message instanceof Message) {
2019
Mail::getInstance()->send($message);

src/Notification/Notification.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,26 @@ abstract class Notification
2222
/**
2323
* Returns the available channels to be used
2424
*
25-
* @param \Bow\Database\Barry\Model $notifiable
25+
* @param Model $notifiable
2626
* @return array
2727
*/
2828
abstract public function channels(Model $notifiable): array;
2929

3030
/**
3131
* Send notification to mail
3232
*
33-
* @param \Bow\Database\Barry\Model $notifiable
34-
* @return mixed
33+
* @param Model $notifiable
34+
* @return Message|null
3535
*/
3636
public function toMail(Model $notifiable): ?Message
3737
{
38-
$message = new Message();
39-
40-
return $message;
38+
return new Message();
4139
}
4240

4341
/**
4442
* Send notification to database
4543
*
46-
* @param \Bow\Database\Barry\Model $notifiable
44+
* @param Model $notifiable
4745
* @return array
4846
*/
4947
public function toDatabase(Model $notifiable): array
@@ -53,10 +51,10 @@ public function toDatabase(Model $notifiable): array
5351

5452
/**
5553
* Process the notification
56-
* @param \Bow\Database\Barry\Model $notifiable
54+
* @param Model $notifiable
5755
* @return void
5856
*/
59-
final function process(Model $notifiable)
57+
final function process(Model $notifiable): void
6058
{
6159
$channels = $this->channels($notifiable);
6260

src/Queue/Adapters/BeanstalkdAdapter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public function run(string $queue = null): void
134134
} else {
135135
$this->pheanstalk->release($job, $this->getPriority($producer->getPriority()), $producer->getDelay());
136136
}
137+
137138
$this->sleep(1);
138139
}
139140
}

src/Queue/Adapters/SQSAdapter.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ public function size(string $queue): int
9999
*
100100
* @param ?string $queue
101101
* @return void
102+
* @throws \ErrorException
102103
*/
103104
public function run(?string $queue = null): void
104105
{
105106
$this->sleep($this->sleep ?? 5);
107+
$message = null;
106108

107109
try {
108110
$result = $this->sqs->receiveMessage([
@@ -130,31 +132,31 @@ public function run(?string $queue = null): void
130132
error_log($e->getMessage());
131133
app('logger')->error($e->getMessage(), $e->getTrace());
132134

133-
if (isset($message)) {
134-
cache(
135-
"job:failed:" . $message["ReceiptHandle"],
136-
$message["Body"]
137-
);
135+
if (!$message) {
136+
$this->sleep(1);
137+
return;
138138
}
139139

140+
cache("job:failed:" . $message["ReceiptHandle"], $message["Body"]);
141+
140142
// Check if producer has been loaded
141143
if (!isset($producer)) {
142144
$this->sleep(1);
143145
return;
144146
}
145147

146148
// Execute the onException method for notify the producer
147-
// and let developper to decide if the job should be delete
149+
// and let developer decide if the job should be deleted
148150
$producer->onException($e);
149151

150-
// Check if the job should be delete
152+
// Check if the job should be deleted
151153
if ($producer->jobShouldBeDelete()) {
152-
$result = $this->sqs->deleteMessage([
154+
$this->sqs->deleteMessage([
153155
'QueueUrl' => $this->config["url"],
154156
'ReceiptHandle' => $message['ReceiptHandle']
155157
]);
156158
} else {
157-
$result = $this->sqs->changeMessageVisibilityBatch([
159+
$this->sqs->changeMessageVisibilityBatch([
158160
'QueueUrl' => $this->config["url"],
159161
'Entries' => [
160162
'Id' => $producer->getId(),
@@ -163,6 +165,7 @@ public function run(?string $queue = null): void
163165
],
164166
]);
165167
}
168+
166169
$this->sleep(1);
167170
}
168171
}

src/Queue/Connection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Connection
3030
/**
3131
* The supported connection
3232
*
33-
* @param array
33+
* @var array
3434
*/
3535
private static array $connections = [
3636
"beanstalkd" => BeanstalkdAdapter::class,
@@ -50,11 +50,12 @@ public function __construct(array $config)
5050
}
5151

5252
/**
53-
* Push the new connection support in connectors managment
53+
* Push the new connection support in connectors management
5454
*
5555
* @param string $name
56-
* @param string $name
56+
* @param string $classname
5757
* @return bool
58+
* @throws ErrorException
5859
*/
5960
public static function pushConnection(string $name, string $classname): bool
6061
{

0 commit comments

Comments
 (0)