Skip to content

Commit d2bc166

Browse files
authored
Merge pull request #34 from webparking/feature/style-fixes
Feature/style fixes
2 parents 3d0dea4 + f0e7896 commit d2bc166

File tree

9 files changed

+90
-61
lines changed

9 files changed

+90
-61
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
2+
.php_cs.cache
23
composer.lock
34
vendor/

.php_cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
return PhpCsFixer\Config::create()
4+
->setRules([
5+
'@Symfony' => true,
6+
'@Symfony:risky' => true,
7+
'@PSR2' => true,
8+
'array_syntax' => ['syntax' => 'short'],
9+
'protected_to_private' => false,
10+
'compact_nullable_typehint' => true,
11+
'concat_space' => ['spacing' => 'one'],
12+
'phpdoc_separation' => false,
13+
'ordered_imports' => true,
14+
'yoda_style' => null,
15+
])
16+
->setRiskyAllowed(true)
17+
->setFinder(
18+
PhpCsFixer\Finder::create()
19+
->in([
20+
__DIR__ . '/src',
21+
__DIR__ . '/tests',
22+
])
23+
->notPath('#c3.php#')
24+
->append([__FILE__])
25+
);

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ before_script:
1717
- composer install --no-interaction
1818

1919
script:
20-
- vendor/bin/phpunit
20+
- composer test

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
"illuminate/database": ">=5.3",
2020
"illuminate/queue": ">=5.3",
2121
"illuminate/support": ">=5.3",
22-
"nesbot/carbon": ">=1.21"
22+
"nesbot/carbon": ">=1.21",
23+
"ext-json": "*"
2324
},
2425
"require-dev": {
2526
"phpunit/phpunit": ">=5.7",
26-
"orchestra/testbench": ">=3.4"
27+
"orchestra/testbench": ">=3.4",
28+
"friendsofphp/php-cs-fixer": "^2.11"
2729
},
2830
"extra": {
2931
"laravel": {
@@ -41,5 +43,9 @@
4143
"psr-4": {
4244
"Imtigger\\LaravelJobStatus\\": "tests"
4345
}
46+
},
47+
"scripts": {
48+
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --config=.php_cs",
49+
"test": "composer php-cs-fixer && vendor/bin/phpunit"
4450
}
4551
}

src/JobStatus.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,38 @@
55
use Illuminate\Database\Eloquent\Model;
66

77
/**
8-
* Imtigger\LaravelJobStatus
8+
* Imtigger\LaravelJobStatus.
99
*
10-
* @property int $id
10+
* @property int $id
1111
* @property string $job_id
1212
* @property string $type
1313
* @property string $queue
14-
* @property int $attempts
15-
* @property int $progress_now
16-
* @property int $progress_max
14+
* @property int $attempts
15+
* @property int $progress_now
16+
* @property int $progress_max
1717
* @property string $status
1818
* @property string $input
1919
* @property string $output
2020
* @property string $created_at
2121
* @property string $started_at
2222
* @property string $finished_at
23-
* @property-read mixed $is_ended
24-
* @property-read mixed $is_executing
25-
* @property-read mixed $is_failed
26-
* @property-read mixed $is_finished
27-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereAttempts($value)
28-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereCreatedAt($value)
29-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereFinishedAt($value)
30-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereId($value)
31-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereInput($value)
32-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereJobId($value)
33-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereOutput($value)
34-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereProgressMax($value)
35-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereProgressNow($value)
36-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereQueue($value)
37-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereStartedAt($value)
38-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereStatus($value)
39-
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereType($value)
23+
* @property mixed $is_ended
24+
* @property mixed $is_executing
25+
* @property mixed $is_failed
26+
* @property mixed $is_finished
27+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereAttempts($value)
28+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereCreatedAt($value)
29+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereFinishedAt($value)
30+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereId($value)
31+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereInput($value)
32+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereJobId($value)
33+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereOutput($value)
34+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereProgressMax($value)
35+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereProgressNow($value)
36+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereQueue($value)
37+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereStartedAt($value)
38+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereStatus($value)
39+
* @method static \Illuminate\Database\Query\Builder|\Imtigger\LaravelJobStatus\JobStatus whereType($value)
4040
* @mixin \Eloquent
4141
*/
4242
class JobStatus extends Model
@@ -62,12 +62,12 @@ public function getOutputAttribute($value)
6262

6363
public function getProgressPercentageAttribute()
6464
{
65-
return $this->progress_max != 0 ? round(100 * $this->progress_now / $this->progress_max) : 0;
65+
return $this->progress_max !== 0 ? round(100 * $this->progress_now / $this->progress_max) : 0;
6666
}
67-
67+
6868
public function getIsEndedAttribute()
6969
{
70-
return in_array($this->status, [self::STATUS_FAILED, self::STATUS_FINISHED]);
70+
return \in_array($this->status, [self::STATUS_FAILED, self::STATUS_FINISHED], true);
7171
}
7272

7373
public function getIsFinishedAttribute()
@@ -79,7 +79,7 @@ public function getIsFailedAttribute()
7979
{
8080
return $this->status === self::STATUS_FAILED;
8181
}
82-
82+
8383
public function getIsExecutingAttribute()
8484
{
8585
return $this->status === self::STATUS_EXECUTING;
@@ -107,7 +107,7 @@ public static function getAllowedStatuses()
107107
self::STATUS_QUEUED,
108108
self::STATUS_EXECUTING,
109109
self::STATUS_FINISHED,
110-
self::STATUS_FAILED
110+
self::STATUS_FAILED,
111111
];
112112
}
113113
}

src/LaravelJobStatusServiceProvider.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,35 @@ public function boot()
2828
__DIR__ . '/../config/' => config_path(),
2929
], 'config');
3030

31-
/** @var JobStatus $entityClass */
32-
$entityClass = app(config('job-status.model'));
31+
/** @var JobStatus $entityClass */
32+
$entityClass = app(config('job-status.model'));
3333

3434
// Add Event listeners
35-
app(QueueManager::class)->before(function (JobProcessing $event) use ($entityClass){
35+
app(QueueManager::class)->before(function (JobProcessing $event) use ($entityClass) {
3636
$this->updateJobStatus($event->job, [
3737
'status' => $entityClass::STATUS_EXECUTING,
3838
'job_id' => $event->job->getJobId(),
3939
'queue' => $event->job->getQueue(),
40-
'started_at' => Carbon::now()
40+
'started_at' => Carbon::now(),
4141
]);
4242
});
43-
app(QueueManager::class)->after(function (JobProcessed $event) use($entityClass){
43+
app(QueueManager::class)->after(function (JobProcessed $event) use ($entityClass) {
4444
$this->updateJobStatus($event->job, [
4545
'status' => $entityClass::STATUS_FINISHED,
46-
'finished_at' => Carbon::now()
46+
'finished_at' => Carbon::now(),
4747
]);
4848
});
49-
app(QueueManager::class)->failing(function (JobFailed $event) use ($entityClass){
49+
app(QueueManager::class)->failing(function (JobFailed $event) use ($entityClass) {
5050
$this->updateJobStatus($event->job, [
5151
'status' => $entityClass::STATUS_FAILED,
52-
'finished_at' => Carbon::now()
52+
'finished_at' => Carbon::now(),
5353
]);
5454
});
55-
app(QueueManager::class)->exceptionOccurred(function (JobExceptionOccurred $event) use($entityClass) {
55+
app(QueueManager::class)->exceptionOccurred(function (JobExceptionOccurred $event) use ($entityClass) {
5656
$this->updateJobStatus($event->job, [
5757
'status' => $entityClass::STATUS_FAILED,
5858
'finished_at' => Carbon::now(),
59-
'output' => json_encode(['message' => $event->exception->getMessage()])
59+
'output' => json_encode(['message' => $event->exception->getMessage()]),
6060
]);
6161
});
6262
}
@@ -67,26 +67,28 @@ private function updateJobStatus(Job $job, array $data)
6767
$payload = $job->payload();
6868
$jobStatus = unserialize($payload['data']['command']);
6969

70-
if (!is_callable([$jobStatus, 'getJobStatusId'])) {
70+
if (!\is_callable([$jobStatus, 'getJobStatusId'])) {
7171
return null;
7272
}
7373

7474
$jobStatusId = $jobStatus->getJobStatusId();
7575

76-
/** @var JobStatus $entityClass */
77-
$entityClass = app(config('job-status.model'));
76+
/** @var JobStatus $entityClass */
77+
$entityClass = app(config('job-status.model'));
7878

79-
$jobStatus = $entityClass::where('id', '=', $jobStatusId);
79+
$jobStatus = $entityClass::query()->where('id', '=', $jobStatusId);
8080

81-
// Try to add attempts to the data we're saving - this will fail
81+
// Try to add attempts to the data we're saving - this will fail
8282
// for some drivers since they delete the job before we can check
8383
try {
8484
$data['attempts'] = $job->attempts();
85-
} catch (\Exception $e) { }
85+
} catch (\Exception $e) {
86+
}
8687

8788
return $jobStatus->update($data);
8889
} catch (\Exception $e) {
8990
Log::error($e->getMessage());
91+
9092
return null;
9193
}
9294
}

src/Trackable.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected function setProgressMax($value)
1717

1818
protected function setProgressNow($value, $every = 1)
1919
{
20-
if ($value % $every == 0 || $value == $this->progressMax) {
20+
if ($value % $every === 0 || $value === $this->progressMax) {
2121
$this->update(['progress_now' => $value]);
2222
}
2323
$this->progressNow = $value;
@@ -44,11 +44,12 @@ protected function update(array $data)
4444
/** @var JobStatus $entityClass */
4545
$entityClass = app(config('job-status.model'));
4646
/** @var JobStatus $status */
47-
$status = $entityClass::find($this->statusId);
47+
$status = $entityClass::query()->find($this->statusId);
4848

49-
if ($status != null) {
49+
if ($status !== null) {
5050
return $status->update($data);
5151
}
52+
5253
return null;
5354
}
5455

@@ -57,9 +58,9 @@ protected function prepareStatus(array $data = [])
5758
/** @var JobStatus $entityClass */
5859
$entityClass = app(config('job-status.model'));
5960

60-
$data = array_merge(["type" => $this->getDisplayName()], $data);
61+
$data = array_merge(['type' => $this->getDisplayName()], $data);
6162
/** @var JobStatus $status */
62-
$status = $entityClass::create($data);
63+
$status = $entityClass::query()->create($data);
6364

6465
$this->statusId = $status->getKey();
6566
}
@@ -71,8 +72,8 @@ protected function getDisplayName()
7172

7273
public function getJobStatusId()
7374
{
74-
if ($this->statusId == null) {
75-
throw new \Exception("Failed to get jobStatusId, have you called \$this->prepareStatus() in __construct() of Job?");
75+
if ($this->statusId === null) {
76+
throw new \Exception('Failed to get jobStatusId, have you called $this->prepareStatus() in __construct() of Job?');
7677
}
7778

7879
return $this->statusId;

src/migrations/2017_05_01_000000_create_job_statuses_table.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<?php
22

3-
use Illuminate\Database\Schema\Blueprint;
43
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
55

66
class CreateJobStatusesTable extends Migration
77
{
88
/**
99
* Run the migrations.
10-
*
11-
* @return void
1210
*/
1311
public function up()
1412
{
@@ -31,8 +29,6 @@ public function up()
3129

3230
/**
3331
* Reverse the migrations.
34-
*
35-
* @return void
3632
*/
3733
public function down()
3834
{

tests/JobStatusTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
namespace Imtigger\LaravelJobStatus\Tests;
44

5-
65
use Imtigger\LaravelJobStatus\JobStatus;
76
use Orchestra\Testbench\TestCase;
87

98
class JobStatusTest extends TestCase
109
{
11-
1210
public function testGetAndSetsInputAttribute()
1311
{
1412
$jobStatus = new JobStatus();
@@ -81,4 +79,4 @@ public function testJobStatusIsExecuting()
8179

8280
$this->assertTrue($jobStatus->isExecuting);
8381
}
84-
}
82+
}

0 commit comments

Comments
 (0)