Skip to content

Commit 9369e6d

Browse files
authored
Merge pull request #9 from zaengle/develop
Adds support for Laravel 10 and drops lower than Laravel 8
2 parents 60cc23b + d991cb3 commit 9369e6d

17 files changed

+99
-230
lines changed

.github/workflows/php.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
- name: Setup PHP
1818
uses: shivammathur/setup-php@v2
1919
with:
20-
php-version: '7.4'
20+
php-version: '8.1'
2121

2222
- name: Validate composer.json and composer.lock
2323
run: composer validate
24-
24+
2525
- name: Cache Composer packages
2626
id: composer-cache
2727
uses: actions/cache@v2

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The first step in using the Zaengle Pipeline is to create a Data Traveler class.
6565
$traveler = (new RegisterTraveler())->setRequest(request()->all());
6666
```
6767

68-
While not required, by extending `Zaengle\Pipeline\Contracts\AbstractTraveler` you will inherit additional methods utilized in the `Zaengle\Pipeline\Pipeline` class.
68+
`Zaengle\Pipeline\Contracts\AbstractTraveler` provides additional methods utilized in the `Zaengle\Pipeline\Pipeline` class.
6969

7070
```php
7171
<?php
@@ -122,7 +122,7 @@ use App\User;
122122
use Zaengle\Pipeline\Contracts\PipeInterface;
123123

124124
class CreateUser implements PipeInterface {
125-
public function handle($traveler, \Closure $next)
125+
public function handle(RegisterTraveler|AbstractTraveler $traveler, \Closure $next): RegisterTraveler
126126
{
127127
$traveler->setUser(
128128
User::create([
@@ -144,7 +144,7 @@ use Zaengle\Pipeline\Contracts\PipeInterface;
144144

145145
class HandleMailingList implements PipeInterface
146146
{
147-
public function handle($traveler, \Closure $next)
147+
public function handle(RegisterTraveler|AbstractTraveler $traveler, \Closure $next): RegisterTraveler
148148
{
149149
if ($traveler->getRequest()->subscribe) {
150150
MailingService::subscribe($traveler->getUser()->email);
@@ -171,7 +171,7 @@ $response = app(Pipeline::class)->pipe($traveler, $pipes, $useTransactions = tru
171171
```
172172

173173
#### Results
174-
Assuming the traveler extends `AbstractTraveler`, after sending the `$traveler` through the data pipes you will have access to a `->passed()` method which indicates whether the pipeline completed successfully or not.
174+
After sending the `$traveler` through the data pipes you will have access to a `->passed()` method which indicates whether the pipeline completed successfully or not.
175175

176176
```php
177177
$response = app(Pipeline::class)->pipe($traveler, $pipes, $useTransactions = true);
@@ -187,7 +187,7 @@ if ($response->passed()) {
187187
}
188188
```
189189

190-
Extending `AbstractTraveler` also grants you access to the following convenience methods:
190+
`AbstractTraveler` grants you access to the following convenience methods:
191191

192192
*`$response->passed()`*
193193

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.3|^8.0",
14-
"illuminate/support": "5.*|6.*|7.*|8.*|9.*",
15-
"illuminate/console": "5.*|6.*|7.*|8.*|9.*"
13+
"php": "^8.1",
14+
"illuminate/support": "8.*|9.*|10.*",
15+
"illuminate/console": "8.*|9.*|10.*"
1616
},
1717
"require-dev": {
1818
"mockery/mockery": ">=0.9.9",
1919
"phpunit/phpunit": ">=4.1",
20-
"orchestra/testbench": "~3.6.0|~3.7.0|~3.8.0"
20+
"orchestra/testbench": "~8.0"
2121
},
2222
"autoload": {
2323
"psr-4": {

phpunit.xml

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnError="false"
11-
stopOnFailure="false"
12-
verbose="true"
13-
>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
backupGlobals="false"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
processIsolation="false"
8+
stopOnError="false"
9+
stopOnFailure="false"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
11+
cacheDirectory=".phpunit.cache"
12+
backupStaticProperties="false">
1413
<testsuites>
1514
<testsuite name="Zaengle Pipeline Test Suite">
1615
<directory suffix="Test.php">./tests/</directory>

src/Contracts/AbstractTraveler.php

+15-49
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,57 @@
22

33
namespace Zaengle\Pipeline\Contracts;
44

5-
/**
6-
* Class AbstractTraveler.
7-
*/
5+
use Exception;
6+
87
abstract class AbstractTraveler
98
{
109
const TRAVELER_SUCCESS = 'ok';
1110

1211
const TRAVELER_FAIL = 'fail';
1312

14-
/**
15-
* @var string
16-
*/
17-
protected $status;
18-
19-
/**
20-
* @var string
21-
*/
22-
protected $message = 'Traveler passed successfully.';
23-
24-
/**
25-
* @var \Exception
26-
*/
27-
protected $exception;
28-
29-
/**
30-
* @param mixed $status
31-
* @return AbstractTraveler
32-
*/
33-
public function setStatus($status)
13+
protected string $status;
14+
15+
protected string $message = 'Traveler passed successfully.';
16+
17+
protected ?Exception $exception = null;
18+
19+
public function setStatus(string $status): AbstractTraveler
3420
{
3521
$this->status = $status;
3622

3723
return $this;
3824
}
3925

40-
/**
41-
* @return mixed
42-
*/
43-
public function getStatus()
26+
public function getStatus(): string
4427
{
4528
return $this->status;
4629
}
4730

48-
/**
49-
* @param mixed $message
50-
* @return AbstractTraveler
51-
*/
52-
public function setMessage($message)
31+
public function setMessage(string $message): AbstractTraveler
5332
{
5433
$this->message = $message;
5534

5635
return $this;
5736
}
5837

59-
/**
60-
* @return mixed
61-
*/
62-
public function getMessage()
38+
public function getMessage(): string
6339
{
6440
return $this->message;
6541
}
6642

67-
/**
68-
* @param mixed $exception
69-
* @return AbstractTraveler
70-
*/
71-
public function setException($exception)
43+
public function setException(Exception $exception): AbstractTraveler
7244
{
7345
$this->exception = $exception;
7446

7547
return $this;
7648
}
7749

78-
/**
79-
* @return mixed
80-
*/
81-
public function getException()
50+
public function getException(): ?Exception
8251
{
8352
return $this->exception;
8453
}
8554

86-
/**
87-
* @return bool
88-
*/
89-
public function passed()
55+
public function passed(): bool
9056
{
9157
return $this->getStatus() === self::TRAVELER_SUCCESS;
9258
}

src/Contracts/PipeInterface.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22

33
namespace Zaengle\Pipeline\Contracts;
44

5-
/**
6-
* Interface PipeInterface.
7-
*/
5+
use Closure;
6+
87
interface PipeInterface
98
{
10-
/**
11-
* @param $traveler
12-
* @param \Closure $next
13-
* @return mixed
14-
*/
15-
public function handle($traveler, \Closure $next);
9+
public function handle(AbstractTraveler $traveler, Closure $next): AbstractTraveler;
1610
}

src/Example/ExamplePipeline.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
use Zaengle\Pipeline\Example\Pipes\ExamplePipe;
66
use Zaengle\Pipeline\Pipeline;
77

8-
/**
9-
* Class Example.
10-
*/
118
class ExamplePipeline
129
{
1310
public function __invoke()
1411
{
1512
$traveler = (new ExampleTraveler())
16-
->setDemoData([
17-
'name' => 'Zaengle',
18-
]);
13+
->setDemoData([
14+
'name' => 'Zaengle',
15+
]);
1916

2017
$pipes = [
2118
ExamplePipe::class,
@@ -27,9 +24,9 @@ public function __invoke()
2724
// Handle pass
2825
} else {
2926
// Handle fail
30-
// $response->getException();
31-
// $response->getMessage();
32-
// $response->getStatus();
27+
// $response->getException();
28+
// $response->getMessage();
29+
// $response->getStatus();
3330
}
3431
}
3532
}

src/Example/ExampleTraveler.php

+3-16
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,16 @@
44

55
use Zaengle\Pipeline\Contracts\AbstractTraveler;
66

7-
/**
8-
* Class ExampleTraveler.
9-
*/
107
class ExampleTraveler extends AbstractTraveler
118
{
12-
/**
13-
* @var mixed
14-
*/
15-
private $demoData;
9+
private array $demoData;
1610

17-
/**
18-
* @return mixed
19-
*/
20-
public function getDemoData()
11+
public function getDemoData(): array
2112
{
2213
return $this->demoData;
2314
}
2415

25-
/**
26-
* @param mixed $demoData
27-
* @return ExampleTraveler
28-
*/
29-
public function setDemoData($demoData)
16+
public function setDemoData(array $demoData): ExampleTraveler
3017
{
3118
$this->demoData = $demoData;
3219

src/Example/Pipes/ExamplePipe.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
namespace Zaengle\Pipeline\Example\Pipes;
44

5+
use Closure;
6+
use Zaengle\Pipeline\Contracts\AbstractTraveler;
57
use Zaengle\Pipeline\Contracts\PipeInterface;
8+
use Zaengle\Pipeline\Example\ExampleTraveler;
69

7-
/**
8-
* Class ExamplePipe.
9-
*/
1010
class ExamplePipe implements PipeInterface
1111
{
12-
/**
13-
* {@inheritdoc}
14-
*/
15-
public function handle($traveler, \Closure $next)
12+
public function handle(ExampleTraveler|AbstractTraveler $traveler, Closure $next): AbstractTraveler
1613
{
1714
dump($traveler->getName());
1815

src/Facade.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
namespace Zaengle\Pipeline;
44

5-
/**
6-
* Class Facade.
7-
*/
85
class Facade extends \Illuminate\Support\Facades\Facade
96
{
107
/**
118
* {@inheritdoc}
129
*/
13-
protected static function getFacadeAccessor()
10+
protected static function getFacadeAccessor(): string
1411
{
1512
return 'pipeline';
1613
}

0 commit comments

Comments
 (0)