Skip to content

Commit befe900

Browse files
committed
Code cleanup
1 parent ed99f70 commit befe900

17 files changed

Lines changed: 73 additions & 68 deletions

File tree

src/cli/Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ public function actionExec($id, $ttr, $attempt, $pid)
126126
{
127127
if ($this->queue->execute($id, file_get_contents('php://stdin'), $ttr, $attempt, $pid)) {
128128
return ExitCode::OK;
129-
} else {
130-
return ExitCode::UNSPECIFIED_ERROR;
131129
}
130+
131+
return ExitCode::UNSPECIFIED_ERROR;
132132
}
133133

134134
/**
@@ -155,11 +155,11 @@ protected function handleMessage($id, $message, $ttr, $attempt)
155155
'pid' => $this->queue->getWorkerPid(),
156156
]);
157157
foreach ($this->getPassedOptions() as $name) {
158-
if (in_array($name, $this->options('exec'))) {
158+
if (in_array($name, $this->options('exec'), true)) {
159159
$cmd .= ' --' . $name . '=' . $this->$name;
160160
}
161161
}
162-
if (!in_array('color', $this->getPassedOptions())) {
162+
if (!in_array('color', $this->getPassedOptions(), true)) {
163163
$cmd .= ' --color=' . $this->isColorEnabled();
164164
}
165165

src/cli/Queue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ protected function handleMessage($id, $message, $ttr, $attempt)
131131
{
132132
if ($this->messageHandler) {
133133
return call_user_func($this->messageHandler, $id, $message, $ttr, $attempt);
134-
} else {
135-
return parent::handleMessage($id, $message, $ttr, $attempt);
136134
}
135+
136+
return parent::handleMessage($id, $message, $ttr, $attempt);
137137
}
138138

139139
/**

src/cli/VerboseBehavior.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ protected function formatDuration($value)
154154

155155
if ($days > 0) {
156156
return sprintf('%d:%02d:%02d:%02d', $days, $hours, $minutes, $seconds);
157-
} else {
158-
return sprintf('%d:%02d:%02d', $hours, $minutes, $seconds);
159157
}
158+
159+
return sprintf('%d:%02d:%02d', $hours, $minutes, $seconds);
160160
}
161161
}

src/drivers/beanstalk/Command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public function actionRemove($id)
8080
if ($this->queue->remove($id)) {
8181
$this->stdout("The job has been removed.\n");
8282
return ExitCode::OK;
83-
} else {
84-
$this->stdout("The job was not found.\n");
85-
return ExitCode::DATAERR;
8683
}
84+
85+
$this->stdout("The job was not found.\n");
86+
return ExitCode::DATAERR;
8787
}
8888
}

src/drivers/beanstalk/Queue.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ public function status($id)
8282
$stats = $this->getPheanstalk()->statsJob($id);
8383
if ($stats['state'] === 'reserved') {
8484
return self::STATUS_RESERVED;
85-
} else {
86-
return self::STATUS_WAITING;
8785
}
86+
87+
return self::STATUS_WAITING;
8888
} catch (ServerException $e) {
8989
if ($e->getMessage() === 'Server reported NOT_FOUND') {
9090
return self::STATUS_DONE;
91-
} else {
92-
throw $e;
9391
}
92+
93+
throw $e;
9494
}
9595
}
9696

@@ -110,9 +110,9 @@ public function remove($id)
110110
} catch (ServerException $e) {
111111
if (strpos($e->getMessage(), 'NOT_FOUND') === 0) {
112112
return false;
113-
} else {
114-
throw $e;
115113
}
114+
115+
throw $e;
116116
}
117117
}
118118

src/drivers/db/Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function actions()
4242
*/
4343
protected function isWorkerAction($actionID)
4444
{
45-
return in_array($actionID, ['run' ,'listen']);
45+
return in_array($actionID, ['run' ,'listen'], true);
4646
}
4747

4848
/**
@@ -93,9 +93,9 @@ public function actionRemove($id)
9393
if ($this->queue->remove($id)) {
9494
$this->stdout("The job has been removed.\n");
9595
return ExitCode::OK;
96-
} else {
97-
$this->stdout("The job was not found.\n");
98-
return ExitCode::DATAERR;
9996
}
97+
98+
$this->stdout("The job was not found.\n");
99+
return ExitCode::DATAERR;
100100
}
101101
}

src/drivers/db/Queue.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,20 @@ public function status($id)
107107
if (!$payload) {
108108
if ($this->deleteReleased) {
109109
return self::STATUS_DONE;
110-
} else {
111-
throw new InvalidParamException("Unknown message ID: $id.");
112110
}
111+
112+
throw new InvalidParamException("Unknown message ID: $id.");
113113
}
114114

115115
if (!$payload['reserved_at']) {
116116
return self::STATUS_WAITING;
117-
} elseif (!$payload['done_at']) {
117+
}
118+
119+
if (!$payload['done_at']) {
118120
return self::STATUS_RESERVED;
119-
} else {
120-
return self::STATUS_DONE;
121121
}
122+
123+
return self::STATUS_DONE;
122124
}
123125

124126
/**
@@ -161,9 +163,7 @@ protected function pushMessage($message, $ttr, $delay, $priority)
161163
'priority' => $priority ?: 1024,
162164
])->execute();
163165
$tableSchema = $this->db->getTableSchema($this->tableName);
164-
$id = $this->db->getLastInsertID($tableSchema->sequenceName);
165-
166-
return $id;
166+
return $this->db->getLastInsertID($tableSchema->sequenceName);
167167
}
168168

169169
/**

src/drivers/file/Command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ public function actionRemove($id)
9393
if ($this->queue->remove((int) $id)) {
9494
$this->stdout("The job has been removed.\n");
9595
return ExitCode::OK;
96-
} else {
97-
$this->stdout("The job was not found.\n");
98-
return ExitCode::DATAERR;
9996
}
97+
98+
$this->stdout("The job was not found.\n");
99+
return ExitCode::DATAERR;
100100
}
101101
}

src/drivers/file/InfoAction.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ public function run()
4949
protected function getWaitingCount()
5050
{
5151
$data = $this->getIndexData();
52-
$count = !empty($data['waiting']) ? count($data['waiting']) : 0;
53-
54-
return $count;
52+
return !empty($data['waiting']) ? count($data['waiting']) : 0;
5553
}
5654

5755
/**
@@ -60,9 +58,7 @@ protected function getWaitingCount()
6058
protected function getDelayedCount()
6159
{
6260
$data = $this->getIndexData();
63-
$count = !empty($data['delayed']) ? count($data['delayed']) : 0;
64-
65-
return $count;
61+
return !empty($data['delayed']) ? count($data['delayed']) : 0;
6662
}
6763

6864
/**
@@ -71,9 +67,7 @@ protected function getDelayedCount()
7167
protected function getReservedCount()
7268
{
7369
$data = $this->getIndexData();
74-
$count = !empty($data['reserved']) ? count($data['reserved']) : 0;
75-
76-
return $count;
70+
return !empty($data['reserved']) ? count($data['reserved']) : 0;
7771
}
7872

7973
/**
@@ -83,9 +77,7 @@ protected function getDoneCount()
8377
{
8478
$data = $this->getIndexData();
8579
$total = isset($data['lastId']) ? $data['lastId'] : 0;
86-
$done = $total - $this->getDelayedCount() - $this->getWaitingCount();
87-
88-
return $done;
80+
return $total - $this->getDelayedCount() - $this->getWaitingCount();
8981
}
9082

9183
protected function getIndexData()

src/drivers/file/Queue.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public function status($id)
9898

9999
if (file_exists("$this->path/job$id.data")) {
100100
return self::STATUS_WAITING;
101-
} else {
102-
return self::STATUS_DONE;
103101
}
102+
103+
return self::STATUS_DONE;
104104
}
105105

106106
/**
@@ -199,9 +199,9 @@ protected function reserve()
199199

200200
if ($id) {
201201
return [$id, file_get_contents("$this->path/job$id.data"), $ttr, $attempt];
202-
} else {
203-
return null;
204202
}
203+
204+
return null;
205205
}
206206

207207
/**
@@ -271,7 +271,7 @@ private function touchIndex($callback)
271271
if ($isNew && $this->fileMode !== null) {
272272
chmod($fileName, $this->fileMode);
273273
}
274-
if (($file = fopen($fileName, 'r+')) === false) {
274+
if (($file = fopen($fileName, 'rb+')) === false) {
275275
throw new InvalidConfigException("Unable to open index file: $fileName");
276276
}
277277
flock($file, LOCK_EX);

0 commit comments

Comments
 (0)