Skip to content

Commit 7eee466

Browse files
committed
UPDATED: codes with renamed classname.
1 parent 41eb08c commit 7eee466

8 files changed

+35
-35
lines changed

Src/InvalidMiddlewareForPipe.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212
use TypeError;
1313

14-
class InvalidMiddlewareForPipeError extends TypeError {}
14+
class InvalidMiddlewareForPipe extends TypeError {}

Src/InvalidPipe.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use TypeError;
1313

14-
class InvalidPipeError extends TypeError {
14+
class InvalidPipe extends TypeError {
1515
public static function from( mixed $pipe ): self {
1616
return new self( $pipe );
1717
}

Src/InvalidPipeline.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
use Exception;
1111

12-
class UnexpectedPipelineException extends Exception {}
12+
class InvalidPipeline extends Exception {}

Src/Pipeline.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class Pipeline {
3737
protected Closure $catcher;
3838

3939
/**
40-
* @throws InvalidPipeError When invalid pipe given.
41-
* @throws UnexpectedPipelineException When could not determine thrown exception.
40+
* @throws InvalidPipe When invalid pipe given.
41+
* @throws InvalidPipeline When could not determine thrown exception.
4242
* @phpstan-param class-string<Pipe>|Pipe|Closure(mixed $subject, Closure $next, mixed ...$use): mixed $pipe
4343
*/
4444
// phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.WrongNumber -- Exactly 2 exception thrown.
@@ -47,17 +47,17 @@ final public static function resolve( string|Closure|Pipe $pipe ): Closure {
4747

4848
try {
4949
return match ( true ) {
50-
default => throw InvalidPipeError::from( $pipe ),
50+
default => throw InvalidPipe::from( $pipe ),
5151
$isClassName => PipelineBridge::make( $pipe )->handle( ... ),
5252
$pipe instanceof Pipe => $pipe->handle( ... ),
5353
$pipe instanceof Closure => $pipe,
5454
};
5555
} catch ( Throwable $e ) {
56-
if ( $e instanceof InvalidPipeError ) {
56+
if ( $e instanceof InvalidPipe ) {
5757
throw $e;
5858
}
5959

60-
throw new UnexpectedPipelineException( $e->getMessage(), $e->getCode(), $e );
60+
throw new InvalidPipeline( $e->getMessage(), $e->getCode(), $e );
6161
}
6262
}
6363

@@ -161,8 +161,8 @@ public function pipe( string|Closure|Pipe $pipe ): static {
161161
* Gets the transformed subject after passing through one last pipe.
162162
*
163163
* @param Closure(mixed $subject, mixed ...$use): mixed $return
164-
* @throws InvalidPipeError When pipe type could not be resolved.
165-
* @throws UnexpectedPipelineException When a pipe abrupt the pipeline by throwing an exception & sealWith not used.
164+
* @throws InvalidPipe When pipe type could not be resolved.
165+
* @throws InvalidPipeline When a pipe abrupt the pipeline by throwing an exception & sealWith not used.
166166
*/
167167
// phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.Missing -- Doesn't throw throwable.
168168
public function then( Closure $return ): mixed {
@@ -177,17 +177,17 @@ public function then( Closure $return ): mixed {
177177
return $catcher( $e, ...$use );
178178
}
179179

180-
return $e instanceof InvalidPipeError
180+
return $e instanceof InvalidPipe
181181
? throw $e
182-
: throw new UnexpectedPipelineException( $e->getMessage(), $e->getCode(), $e );
182+
: throw new InvalidPipeline( $e->getMessage(), $e->getCode(), $e );
183183
}
184184
}
185185

186186
/**
187187
* Passes through pipes in the pipeline and returns the transformed result.
188188
*
189-
* @throws InvalidPipeError When pipe type could not be resolved.
190-
* @throws UnexpectedPipelineException When a pipe abrupt the pipeline by throwing an exception & sealWith not used.
189+
* @throws InvalidPipe When pipe type could not be resolved.
190+
* @throws InvalidPipeline When a pipe abrupt the pipeline by throwing an exception & sealWith not used.
191191
*/
192192
public function thenReturn() {
193193
return $this->then( return: static fn( $transformed ) => $transformed );

Src/PipelineBridge.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PipelineBridge {
2929
/**
3030
* @param string|Pipe|Closure(mixed $subject, Closure $next, mixed ...$use): mixed $from
3131
* @throws InvalidPipeError When invalid pipe given.
32-
* @throws UnexpectedPipelineException When could not determine thrown exception.
32+
* @throws InvalidPipeline When could not determine thrown exception.
3333
*/
3434
public static function toPipe( string|Closure|Pipe $from ): Pipe {
3535
$pipe = Pipeline::resolve( pipe: $from );
@@ -45,17 +45,17 @@ public function handle( mixed $subject, Closure $next, mixed ...$use ): mixed {
4545
// phpcs:enable
4646

4747
/**
48-
* @throws MiddlewarePsrNotFoundException When invoked on projects that doesn't implement PSR7 & PSR15.
49-
* @throws InvalidMiddlewareForPipeError When middleware creation fails due to invalid classname.
50-
* @throws UnexpectedPipelineException When could not determine thrown exception.
48+
* @throws PsrMiddlewareNotFound When invoked on projects that doesn't implement PSR7 & PSR15.
49+
* @throws InvalidMiddlewareForPipe When middleware creation fails due to invalid classname.
50+
* @throws InvalidPipeline When could not determine thrown exception.
5151
*/
5252
// phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.WrongNumber -- Exactly 3 exceptions thrown.
5353
public static function toMiddleware( mixed $middleware ): object {
5454
$interface = static::hasMiddlewareInterfaceAdapter()
5555
? static::$middlewareInterface
5656
: (
5757
! interface_exists( $default = '\\Psr\\Http\\Server\\MiddlewareInterface' )
58-
? throw new MiddlewarePsrNotFoundException( 'Cannot find PSR15 HTTP Server Middleware.' )
58+
? throw new PsrMiddlewareNotFound( 'Cannot find PSR15 HTTP Server Middleware.' )
5959
: $default
6060
);
6161

@@ -73,19 +73,19 @@ public static function toMiddleware( mixed $middleware ): object {
7373
return static::getMiddlewareAdapter( $middleware );
7474
}
7575

76-
throw new InvalidMiddlewareForPipeError(
76+
throw new InvalidMiddlewareForPipe(
7777
sprintf(
7878
'Invalid middleware type. Middleware must be a Closure, an instance of'
7979
. ' "%1$s" or a concrete\'s classname that implements "%1$s".',
8080
$interface
8181
)
8282
);
8383
} catch ( Throwable $e ) {
84-
throw $e instanceof InvalidMiddlewareForPipeError
84+
throw $e instanceof InvalidMiddlewareForPipe
8585
? $e
8686
: ( ! is_string( $middleware )
87-
? new UnexpectedPipelineException( $e->getMessage(), $e->getCode(), $e )
88-
: new InvalidMiddlewareForPipeError(
87+
? new InvalidPipeline( $e->getMessage(), $e->getCode(), $e )
88+
: new InvalidMiddlewareForPipe(
8989
sprintf(
9090
'The given middleware classname: "%1$s" must be an instance of "%2$s".',
9191
$middleware,

Src/PsrMiddlewareNotFound.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212
use RuntimeException;
1313

14-
class MiddlewarePsrNotFoundException extends RuntimeException {}
14+
class PsrMiddlewareNotFound extends RuntimeException {}

Tests/BridgeTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
use TheWebSolver\Codegarage\Stub\PipeStub;
2525
use TheWebSolver\Codegarage\Lib\PipeInterface;
2626
use TheWebSolver\Codegarage\Lib\PipelineBridge;
27-
use TheWebSolver\Codegarage\Lib\InvalidMiddlewareForPipeError;
28-
use TheWebSolver\Codegarage\Lib\MiddlewarePsrNotFoundException;
27+
use TheWebSolver\Codegarage\Lib\PsrMiddlewareNotFound;
28+
use TheWebSolver\Codegarage\Lib\InvalidMiddlewareForPipe;
2929

3030
class BridgeTest extends TestCase {
3131
private function addPsrPackageFixtures(): void {
@@ -82,9 +82,9 @@ public function provideMiddlewares(): array {
8282
return array(
8383
array( Middleware::class, null ),
8484
array( $this->createMock( MiddlewareInterface::class ), null ),
85-
array( '\\Invalid\\Middleware', InvalidMiddlewareForPipeError::class ),
86-
array( true, InvalidMiddlewareForPipeError::class ),
87-
array( static::class, InvalidMiddlewareForPipeError::class ),
85+
array( '\\Invalid\\Middleware', InvalidMiddlewareForPipe::class ),
86+
array( true, InvalidMiddlewareForPipe::class ),
87+
array( static::class, InvalidMiddlewareForPipe::class ),
8888
array(
8989
static fn( ServerRequestInterface $r, RequestHandlerInterface $h ) => new Response(),
9090
null,
@@ -142,7 +142,7 @@ public function process(
142142

143143
// Must always throw exception if core PSR-15 implementation not used.
144144
if ( ! TWS_CODEGARAGE_PSR_PACKAGE_INSTALLED ) {
145-
$this->expectException( MiddlewarePsrNotFoundException::class );
145+
$this->expectException( PsrMiddlewareNotFound::class );
146146
$this->expectExceptionMessage( 'Cannot find PSR15 HTTP Server Middleware.' );
147147

148148
PipelineBridge::toMiddleware( middleware: '' );

Tests/PipelineTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
use PHPUnit\Framework\TestCase;
1616
use TheWebSolver\Codegarage\Lib\Pipeline;
1717
use TheWebSolver\Codegarage\Stub\PipeStub;
18+
use TheWebSolver\Codegarage\Lib\InvalidPipe;
1819
use TheWebSolver\Codegarage\Lib\PipeInterface;
19-
use TheWebSolver\Codegarage\Lib\InvalidPipeError;
20-
use TheWebSolver\Codegarage\Lib\UnexpectedPipelineException;
20+
use TheWebSolver\Codegarage\Lib\InvalidPipeline;
2121

2222
class PipelineTest extends TestCase {
2323
/** @dataProvider provideVariousPipeTypes */
@@ -40,8 +40,8 @@ public static function provideVariousPipeTypes(): array {
4040
return array(
4141
array( PipeStub::class, null ),
4242
array( static fn ( string $subject, Closure $next ): string => $next( $subject ), null ),
43-
array( '\\Undefined\\ClassName', InvalidPipeError::class ),
44-
array( static::class, UnexpectedPipelineException::class ),
43+
array( '\\Undefined\\ClassName', InvalidPipe::class ),
44+
array( static::class, InvalidPipeline::class ),
4545
array(
4646
new class() implements PipeInterface {
4747
public function handle( mixed $subject, Closure $next, mixed ...$use ): mixed {
@@ -168,7 +168,7 @@ public function testPipeSealer(): void {
168168
);
169169

170170
// When "Pipeline::sealWith()" is not used, exception is thrown.
171-
$this->expectException( UnexpectedPipelineException::class );
171+
$this->expectException( InvalidPipeline::class );
172172

173173
( new Pipeline() )
174174
->send( subject: 'test' )

0 commit comments

Comments
 (0)