Skip to content

Commit 96a9235

Browse files
Changed typing of the method property for events
1 parent ab1b0e1 commit 96a9235

File tree

8 files changed

+62
-20
lines changed

8 files changed

+62
-20
lines changed

docs/helpers/events.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ class EventServiceProvider extends ServiceProvider
4040
```php
4141
namespace App\Listeners;
4242

43+
use DragonCode\LaravelDeployOperations\Enums\MethodEnum;
4344
use DragonCode\LaravelDeployOperations\Events\BaseEvent;
4445

4546
class SomeOperationsListener
4647
{
4748
public function handle(BaseEvent $event): void
4849
{
49-
$method = $event->method; // `up` or `down` string value
50+
$method = $event->method; // MethodEnum object value
5051
$isBefore = $event->before; // boolean
5152
}
5253
}

docs/upgrade-guide/6.x.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [Database transactions](#database-transactions)
1616
- [Removed `$async` property](#removed-async-property)
1717
- [Removed `operations:stub` command](#removed-operationsstub-command)
18+
- [Changed property typing for events](#changed-property-typing-for-events)
1819

1920
## Low-Impact Changes
2021

@@ -102,6 +103,30 @@ You should replace `DragonCode\LaravelActions\Action` namespace with `DragonCode
102103
Don't forget to also change the namespace from `DragonCode\LaravelActions\Events`
103104
to `DragonCode\LaravelDeployOperations\Events`.
104105

106+
## Changed property typing for events
107+
108+
The type of the `method` property for events has been changed.
109+
110+
Before:
111+
112+
```php
113+
use DragonCode\LaravelActions\Events\ActionEnded;
114+
use DragonCode\LaravelDeployOperations\Enums\MethodEnum;
115+
116+
/** @var ActionEnded */
117+
$event->method; // is string
118+
```
119+
120+
After:
121+
122+
```php
123+
use DragonCode\LaravelDeployOperations\Enums\MethodEnum;
124+
use DragonCode\LaravelDeployOperations\Events\DeployOperationEnded;
125+
126+
/** @var DeployOperationEnded */
127+
$event->method; // is MethodEnum
128+
```
129+
105130
## Configuration file name changed
106131

107132
We recommend that you delete the old configuration file `config/actions.php` and publish a new one.

src/Constants/Names.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
class Names
66
{
7-
public const Operations = 'operations';
8-
public const Fresh = 'operations:fresh';
9-
public const Install = 'operations:install';
10-
public const Make = 'make:operation';
11-
public const Refresh = 'operations:refresh';
12-
public const Reset = 'operations:reset';
13-
public const Rollback = 'operations:rollback';
14-
public const Status = 'operations:status';
15-
public const Upgrade = 'operations:upgrade';
7+
public const Operations = 'operations';
8+
public const Fresh = 'operations:fresh';
9+
public const Install = 'operations:install';
10+
public const Make = 'make:operation';
11+
public const Refresh = 'operations:refresh';
12+
public const Reset = 'operations:reset';
13+
public const Rollback = 'operations:rollback';
14+
public const Status = 'operations:status';
15+
public const Upgrade = 'operations:upgrade';
1616
}

src/Enums/MethodEnum.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelDeployOperations\Enums;
6+
7+
enum MethodEnum: string
8+
{
9+
case Up = 'up';
10+
case Down = 'down';
11+
}

src/Events/BaseEvent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace DragonCode\LaravelDeployOperations\Events;
66

7+
use DragonCode\LaravelDeployOperations\Enums\MethodEnum;
8+
79
abstract class BaseEvent
810
{
911
public function __construct(
10-
public string $method,
12+
public MethodEnum $method,
1113
public bool $before
1214
) {}
1315
}

src/Processors/Operations.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DragonCode\LaravelDeployOperations\Constants\Names;
88
use DragonCode\LaravelDeployOperations\Constants\Options;
9+
use DragonCode\LaravelDeployOperations\Enums\MethodEnum;
910
use DragonCode\LaravelDeployOperations\Events\DeployOperationEnded;
1011
use DragonCode\LaravelDeployOperations\Events\DeployOperationFailed;
1112
use DragonCode\LaravelDeployOperations\Events\DeployOperationStarted;
@@ -40,19 +41,19 @@ protected function runOperations(array $completed): void
4041
{
4142
try {
4243
if ($files = $this->getNewFiles($completed)) {
43-
$this->fireEvent(DeployOperationStarted::class, 'up');
44+
$this->fireEvent(DeployOperationStarted::class, MethodEnum::Up);
4445

4546
$this->runEach($files, $this->getBatch());
4647

47-
$this->fireEvent(DeployOperationEnded::class, 'up');
48+
$this->fireEvent(DeployOperationEnded::class, MethodEnum::Up);
4849

4950
return;
5051
}
5152

52-
$this->fireEvent(NoPendingDeployOperations::class, 'up');
53+
$this->fireEvent(NoPendingDeployOperations::class, MethodEnum::Up);
5354
}
5455
catch (Throwable $e) {
55-
$this->fireEvent(DeployOperationFailed::class, 'up');
56+
$this->fireEvent(DeployOperationFailed::class, MethodEnum::Up);
5657

5758
throw $e;
5859
}

src/Processors/Processor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Closure;
88
use DragonCode\LaravelDeployOperations\Concerns\Artisan;
9+
use DragonCode\LaravelDeployOperations\Enums\MethodEnum;
910
use DragonCode\LaravelDeployOperations\Helpers\Config;
1011
use DragonCode\LaravelDeployOperations\Helpers\Git;
1112
use DragonCode\LaravelDeployOperations\Helpers\Sorter;
@@ -78,7 +79,7 @@ protected function tableNotFound(): bool
7879
return false;
7980
}
8081

81-
protected function fireEvent(string $event, string $method): void
82+
protected function fireEvent(string $event, MethodEnum $method): void
8283
{
8384
$this->events->dispatch(new $event($method, $this->options->before));
8485
}

src/Processors/Rollback.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace DragonCode\LaravelDeployOperations\Processors;
66

7+
use DragonCode\LaravelDeployOperations\Enums\MethodEnum;
78
use DragonCode\LaravelDeployOperations\Events\DeployOperationEnded;
89
use DragonCode\LaravelDeployOperations\Events\DeployOperationStarted;
910
use DragonCode\LaravelDeployOperations\Events\NoPendingDeployOperations;
@@ -13,23 +14,23 @@ class Rollback extends Processor
1314
public function handle(): void
1415
{
1516
if ($this->tableNotFound() || $this->nothingToRollback()) {
16-
$this->fireEvent(NoPendingDeployOperations::class, 'down');
17+
$this->fireEvent(NoPendingDeployOperations::class, MethodEnum::Down);
1718

1819
return;
1920
}
2021

2122
if ($items = $this->getOperations($this->options->step)) {
22-
$this->fireEvent(DeployOperationStarted::class, 'down');
23+
$this->fireEvent(DeployOperationStarted::class, MethodEnum::Down);
2324

2425
$this->showCaption();
2526
$this->run($items);
2627

27-
$this->fireEvent(DeployOperationEnded::class, 'down');
28+
$this->fireEvent(DeployOperationEnded::class, MethodEnum::Down);
2829

2930
return;
3031
}
3132

32-
$this->fireEvent(NoPendingDeployOperations::class, 'down');
33+
$this->fireEvent(NoPendingDeployOperations::class, MethodEnum::Down);
3334
}
3435

3536
protected function showCaption(): void

0 commit comments

Comments
 (0)