Skip to content

Commit ce124cb

Browse files
committed
phpstan updates
1 parent 7db3137 commit ce124cb

File tree

7 files changed

+47
-33
lines changed

7 files changed

+47
-33
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"mockery/mockery": "^1.6.10",
1919
"phpunit/phpunit": "^10.5.35|^11.3.6",
2020
"orchestra/testbench": "^9.0",
21-
"laravel/pint": "^1.20"
21+
"laravel/pint": "^1.20",
22+
"phpstan/phpstan": "^2.1"
2223
},
2324
"autoload": {
2425
"psr-4": {

src/Commands/DeployCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DeployCommand extends BaseCommand
1818

1919
protected $description = 'Deploy a clone of your latest build and attach symlink';
2020

21-
public function handle()
21+
public function handle(): void
2222
{
2323
Output::alert('Running Atomic Deployment');
2424

@@ -30,7 +30,8 @@ public function handle()
3030

3131
$deploymentModel = AtomicDeployment::successful()->where('commit_hash', $hash)->first();
3232

33-
if (! $deploymentModel || ! $deploymentModel->hasDeployment) {
33+
/** @var AtomicDeployment $deploymentModel */
34+
if (! $deploymentModel || ! $deploymentModel->has_deployment) {
3435
Output::warn("Build not found for hash: {$hash}");
3536
} else {
3637
$atomicDeployment = AtomicDeploymentService::create(

src/Commands/ListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function handle()
2525
'deployment_status',
2626
'created_at',
2727
)->get()->map(function ($deployment) {
28-
$deployment->append('isCurrentlyDeployed');
28+
$deployment->append('is_currently_deployed');
2929
$deployment->deployment_status = DeploymentStatus::getNameFromValue($deployment->deployment_status);
3030

3131
return $deployment;

src/Helpers/ConsoleOutput.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
use Illuminate\Console\Command;
66

7+
/**
8+
* @method static void line(string $string)
9+
* @method static void alert(string $string)
10+
* @method static void error(string $string)
11+
* @method static void info(string $string)
12+
* @method static void table(string $string)
13+
*/
714
class ConsoleOutput
815
{
916
public static ?Command $runningCommand = null;
1017

11-
public function setOutput(Command $runningCommand)
18+
public function setOutput(Command $runningCommand): void
1219
{
1320
static::$runningCommand = $runningCommand;
1421
}

src/Models/AtomicDeployment.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22

33
namespace JTMcC\AtomicDeployments\Models;
44

5+
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Casts\Attribute;
57
use Illuminate\Database\Eloquent\Model;
68
use Illuminate\Database\Eloquent\SoftDeletes;
79
use Illuminate\Support\Facades\File;
810
use JTMcC\AtomicDeployments\Exceptions\AreYouInsaneException;
911
use JTMcC\AtomicDeployments\Models\Enums\DeploymentStatus;
1012
use JTMcC\AtomicDeployments\Services\Exec;
1113

14+
/**
15+
* @mixin Builder
16+
*
17+
* @method static Builder successful()
18+
*
19+
* @property-read bool $has_deployment
20+
* @property-read bool $is_currently_deployed
21+
*/
1222
class AtomicDeployment extends Model
1323
{
1424
use SoftDeletes;
@@ -25,7 +35,7 @@ protected static function boot()
2535
{
2636
parent::boot();
2737
static::deleting(function ($model) {
28-
if ($model->isCurrentlyDeployed) {
38+
if ($model->is_currently_deployed) {
2939
throw new AreYouInsaneException('Cannot delete live deployment');
3040
}
3141
$model->deleteDeployment();
@@ -37,28 +47,23 @@ public function scopeSuccessful($query)
3747
return $query->where('deployment_status', DeploymentStatus::SUCCESS);
3848
}
3949

40-
public function getHasDeploymentAttribute()
50+
public function hasDeployment(): Attribute
4151
{
42-
return File::isDirectory($this->deployment_path);
52+
return Attribute::make(
53+
get: fn () => File::isDirectory($this->deployment_path),
54+
);
4355
}
4456

45-
/**
46-
* @return bool
47-
*
48-
* @throws \JTMcC\AtomicDeployments\Exceptions\ExecuteFailedException
49-
*/
50-
public function getIsCurrentlyDeployedAttribute()
57+
public function isCurrentlyDeployed(): Attribute
5158
{
52-
if (! $this->hasDeployment) {
53-
return false;
54-
}
55-
56-
return Exec::readlink($this->deployment_link) === $this->deployment_path;
59+
return Attribute::make(
60+
get: fn () => $this->has_deployment && Exec::readlink($this->deployment_link) === $this->deployment_path,
61+
);
5762
}
5863

5964
public function deleteDeployment()
6065
{
61-
if ($this->hasDeployment) {
66+
if ($this->has_deployment) {
6267
File::deleteDirectory($this->deployment_path);
6368
}
6469

src/Services/AtomicDeploymentService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public function cleanBuilds(int $limit): void
317317
Output::info('Found '.$countOfBuildsToRemove.' '.Pluralizer::plural('folder', $countOfBuildsToRemove).' to be removed');
318318

319319
foreach ($buildsToRemove as $deployment) {
320-
if ($deployment->isCurrentlyDeployed) {
320+
if ($deployment->is_currently_deployed) {
321321
Output::warn('Current linked path has appeared in the directory cleaning logic');
322322
Output::warn('This either means you currently have an old build deployed or there is a problem with your deployment data');
323323
Output::warn('Skipping deletion');

tests/Feature/Commands/DeployCommandTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ public function test_it_allows_swapping_between_deployments()
116116
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
117117
Artisan::call('atomic-deployments:deploy --directory=test-dir-2');
118118
$deployment1 = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append(
119-
'isCurrentlyDeployed'
119+
'is_currently_deployed'
120120
)->toArray();
121121
$deployment2 = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append(
122-
'isCurrentlyDeployed'
122+
'is_currently_deployed'
123123
)->toArray();
124124

125-
$this->assertFalse($deployment1['isCurrentlyDeployed']);
126-
$this->assertTrue($deployment2['isCurrentlyDeployed']);
125+
$this->assertFalse($deployment1['is_currently_deployed']);
126+
$this->assertTrue($deployment2['is_currently_deployed']);
127127

128128
// Act
129129
Artisan::call('atomic-deployments:deploy --hash=test-dir-fake');
@@ -144,14 +144,14 @@ public function test_it_allows_swapping_between_deployments()
144144
]);
145145

146146
$deployment1 = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append(
147-
'isCurrentlyDeployed'
147+
'is_currently_deployed'
148148
)->toArray();
149149
$deployment2 = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append(
150-
'isCurrentlyDeployed'
150+
'is_currently_deployed'
151151
)->toArray();
152152

153-
$this->assertTrue($deployment1['isCurrentlyDeployed']);
154-
$this->assertFalse($deployment2['isCurrentlyDeployed']);
153+
$this->assertTrue($deployment1['is_currently_deployed']);
154+
$this->assertFalse($deployment2['is_currently_deployed']);
155155
}
156156

157157
public function test_it_cleans_old_build_folders_based_on_build_limit()
@@ -190,18 +190,18 @@ public function test_it_dispatches_deployment_successful_event_on_deployment_swa
190190
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
191191
Artisan::call('atomic-deployments:deploy --directory=test-dir-2');
192192
$deployment = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append(
193-
'isCurrentlyDeployed'
193+
'is_currently_deployed'
194194
)->toArray();
195-
$this->assertTrue($deployment['isCurrentlyDeployed']);
195+
$this->assertTrue($deployment['is_currently_deployed']);
196196

197197
// Act
198198
Artisan::call('atomic-deployments:deploy --hash=test-dir-1');
199199

200200
// Assert
201201
$deployment = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append(
202-
'isCurrentlyDeployed'
202+
'is_currently_deployed'
203203
)->toArray();
204-
$this->assertTrue($deployment['isCurrentlyDeployed']);
204+
$this->assertTrue($deployment['is_currently_deployed']);
205205
Event::assertDispatched(DeploymentSuccessful::class);
206206
}
207207

0 commit comments

Comments
 (0)