Skip to content

Commit 99ef2d0

Browse files
committed
requested changes
1 parent df75d4f commit 99ef2d0

11 files changed

Lines changed: 17 additions & 165 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
Logging Error Handler for DotKernel
44

55
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-errorhandler)
6-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/3.2.0)
6+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/3.3.0)
77

88
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/issues)
99
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/network)
1010
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/stargazers)
1111
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/blob/3.0/LICENSE)
1212

1313
[![SymfonyInsight](https://insight.symfony.com/projects/cf1f8d89-f230-4157-bc8b-7cce20c75454/big.svg)](https://insight.symfony.com/projects/cf1f8d89-f230-4157-bc8b-7cce20c75454)
14+
15+
1416
## Adding the error handler
1517

1618
* Add the composer package:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"autoload-dev": {
5050
"psr-4": {
51-
"Dot\\Tests\\": "tests/"
51+
"DotTest\\ErrorHandler\\": "test/"
5252
}
5353
},
5454
"minimum-stability": "stable",

phpcs.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
<arg value="p"/>
1313

1414
<!-- Paths to check -->
15-
<file>config</file>
1615
<file>src</file>
17-
<file>tests</file>
16+
<file>test</file>
1817

1918
<!-- Include all rules from the Laminas Coding Standard -->
2019
<rule ref="LaminasCodingStandard"/>

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" bootstrap="./vendor/autoload.php" colors="true">
33
<testsuites>
44
<testsuite name="dot-errorhandler Test Suite">
5-
<directory>./tests</directory>
5+
<directory>./test</directory>
66
</testsuite>
77
</testsuites>
88
<coverage/>

src/ErrorHandler.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,6 @@
1717
use function restore_error_handler;
1818
use function set_error_handler;
1919

20-
/**
21-
* Error handler middleware.
22-
*
23-
* Use this middleware as the outermost (or close to outermost) middleware
24-
* layer, and use it to intercept PHP errors and exceptions.
25-
*
26-
* The class offers two extension points:
27-
*
28-
* - Error response generators.
29-
* - Listeners.
30-
*
31-
* Error response generators are callables with the following signature:
32-
*
33-
* <code>
34-
* function (
35-
* Throwable $e,
36-
* ServerRequestInterface $request,
37-
* ResponseInterface $response
38-
* ) : ResponseInterface
39-
* </code>
40-
*
41-
* These are provided the error, and the request responsible; the response
42-
* provided is the response prototype provided to the ErrorHandler instance
43-
* itself, and can be used as the basis for returning an error response.
44-
*
45-
* An error response generator must be provided as a constructor argument;
46-
* if not provided, an instance of Laminas\Stratigility\Middleware\ErrorResponseGenerator
47-
* will be used.
48-
*
49-
* Listeners use the following signature:
50-
*
51-
* <code>
52-
* function (
53-
* Throwable $e,
54-
* ServerRequestInterface $request,
55-
* ResponseInterface $response
56-
* ) : void
57-
* </code>
58-
*
59-
* Listeners are given the error, the request responsible, and the generated
60-
* error response, and can then react to them. They are best suited for
61-
* logging and monitoring purposes.
62-
*
63-
* Listeners are attached using the attachListener() method, and triggered
64-
* in the order attached.
65-
*/
6620
class ErrorHandler implements MiddlewareInterface, ErrorHandlerInterface
6721
{
6822
/** @var callable[] */
@@ -87,19 +41,6 @@ public function __construct(callable $responseFactory, ?callable $responseGenera
8741
$this->responseGenerator = $responseGenerator ?: new ErrorResponseGenerator();
8842
}
8943

90-
/**
91-
* Attach an error listener.
92-
*
93-
* Each listener receives the following three arguments:
94-
*
95-
* - Throwable $error
96-
* - ServerRequestInterface $request
97-
* - ResponseInterface $response
98-
*
99-
* These instances are all immutable, and the return values of
100-
* listeners are ignored; use listeners for reporting purposes
101-
* only.
102-
*/
10344
public function attachListener(callable $listener): void
10445
{
10546
if (in_array($listener, $this->listeners, true)) {
@@ -109,19 +50,6 @@ public function attachListener(callable $listener): void
10950
$this->listeners[] = $listener;
11051
}
11152

112-
/**
113-
* Middleware to handle errors and exceptions in layers it wraps.
114-
*
115-
* Adds an error handler that will convert PHP errors to ErrorException
116-
* instances.
117-
*
118-
* Internally, wraps the call to $next() in a try/catch block, catching
119-
* all PHP Throwables.
120-
*
121-
* When an exception is caught, an appropriate error response is created
122-
* and returned instead; otherwise, the response returned by $next is
123-
* used.
124-
*/
12553
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
12654
{
12755
set_error_handler($this->createErrorHandler());

src/LogErrorHandler.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,6 @@
1818
use function restore_error_handler;
1919
use function set_error_handler;
2020

21-
/**
22-
* Error handler middleware.
23-
*
24-
* Use this middleware as the outermost (or close to outermost) middleware
25-
* layer, and use it to intercept PHP errors and exceptions.
26-
*
27-
* The class offers two extension points:
28-
*
29-
* - Error response generators.
30-
* - Listeners.
31-
*
32-
* Error response generators are callables with the following signature:
33-
*
34-
* <code>
35-
* function (
36-
* Throwable $e,
37-
* ServerRequestInterface $request,
38-
* ResponseInterface $response
39-
* ) : ResponseInterface
40-
* </code>
41-
*
42-
* These are provided the error, and the request responsible; the response
43-
* provided is the response prototype provided to the ErrorHandler instance
44-
* itself, and can be used as the basis for returning an error response.
45-
*
46-
* An error response generator must be provided as a constructor argument;
47-
* if not provided, an instance of Laminas\Stratigility\Middleware\ErrorResponseGenerator
48-
* will be used.
49-
*
50-
* Listeners use the following signature:
51-
*
52-
* <code>
53-
* function (
54-
* Throwable $e,
55-
* ServerRequestInterface $request,
56-
* ResponseInterface $response
57-
* ) : void
58-
* </code>
59-
*
60-
* Listeners are given the error, the request responsible, and the generated
61-
* error response, and can then react to them. They are best suited for
62-
* logging and monitoring purposes.
63-
*
64-
* Listeners are attached using the attachListener() method, and triggered
65-
* in the order attached.
66-
*/
6721
class LogErrorHandler implements MiddlewareInterface, ErrorHandlerInterface
6822
{
6923
/** @var callable[] */
@@ -93,19 +47,6 @@ public function __construct(
9347
$this->logger = $logger;
9448
}
9549

96-
/**
97-
* Attach an error listener.
98-
*
99-
* Each listener receives the following three arguments:
100-
*
101-
* - Throwable $error
102-
* - ServerRequestInterface $request
103-
* - ResponseInterface $response
104-
*
105-
* These instances are all immutable, and the return values of
106-
* listeners are ignored; use listeners for reporting purposes
107-
* only.
108-
*/
10950
public function attachListener(callable $listener): void
11051
{
11152
if (in_array($listener, $this->listeners, true)) {
@@ -115,19 +56,6 @@ public function attachListener(callable $listener): void
11556
$this->listeners[] = $listener;
11657
}
11758

118-
/**
119-
* Middleware to handle errors and exceptions in layers it wraps.
120-
*
121-
* Adds an error handler that will convert PHP errors to ErrorException
122-
* instances.
123-
*
124-
* Internally, wraps the call to $next() in a try/catch block, catching
125-
* all PHP Throwables.
126-
*
127-
* When an exception is caught, an appropriate error response is created
128-
* and returned instead; otherwise, the response returned by $next is
129-
* used.
130-
*/
13159
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
13260
{
13361
set_error_handler($this->createErrorHandler());
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Dot\Tests;
5+
namespace DotTest\ErrorHandler;
66

77
use Dot\ErrorHandler\ConfigProvider;
88
use Dot\ErrorHandler\ErrorHandler;
@@ -16,8 +16,6 @@ class ConfigProviderTest extends TestCase
1616

1717
protected function setUp(): void
1818
{
19-
parent::setUp();
20-
2119
$this->config = (new ConfigProvider())();
2220
}
2321

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

33
declare(strict_types=1);
44

5-
namespace Dot\Tests;
5+
namespace DotTest\ErrorHandler;
66

77
use Dot\ErrorHandler\ErrorHandler;
88
use Dot\ErrorHandler\ErrorHandlerFactory;
@@ -26,8 +26,6 @@ class ErrorHandlerFactoryTest extends TestCase
2626
*/
2727
public function setUp(): void
2828
{
29-
parent::setUp();
30-
3129
$this->container = $this->createMock(ContainerInterface::class);
3230
$this->responseFactory = fn(): ResponseInterface => $this->createMock(ResponseInterface::class);
3331
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Dot\Tests;
5+
namespace DotTest\ErrorHandler;
66

77
use Dot\ErrorHandler\ErrorHandler;
88
use Dot\ErrorHandler\ErrorHandler as Subject;
@@ -40,8 +40,6 @@ class ErrorHandlerTest extends TestCase
4040
*/
4141
public function setUp(): void
4242
{
43-
parent::setUp();
44-
4543
$this->response = $this->createMock(ResponseInterface::class);
4644
$this->serverRequest = $this->createMock(ServerRequestInterface::class);
4745
$this->body = $this->createMock(StreamInterface::class);
@@ -146,7 +144,7 @@ public function testErrorHandlingTriggersListeners(): void
146144
->method('getReasonPhrase')
147145
->willReturn('Not Implemented');
148146

149-
$listener = function (
147+
$listener = function (
150148
Throwable $error,
151149
ServerRequestInterface $request,
152150
ResponseInterface $response
@@ -155,6 +153,7 @@ public function testErrorHandlingTriggersListeners(): void
155153
$this->assertSame($this->serverRequest, $request);
156154
$this->assertSame($this->response, $response);
157155
};
156+
158157
$listener2 = clone $listener;
159158

160159
$this->subject->attachListener($listener);
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Dot\Tests;
5+
namespace DotTest\ErrorHandler;
66

77
use Dot\ErrorHandler\LogErrorHandler;
88
use Dot\ErrorHandler\LogErrorHandlerFactory;
@@ -29,12 +29,14 @@ class LogErrorHandlerFactoryTest extends TestCase
2929
*/
3030
public function setUp(): void
3131
{
32-
parent::setUp();
33-
3432
$this->container = $this->createMock(ContainerInterface::class);
3533
$this->responseFactory = fn(): ResponseInterface => $this->createMock(ResponseInterface::class);
3634
}
3735

36+
/**
37+
* @throws ContainerExceptionInterface
38+
* @throws NotFoundExceptionInterface
39+
*/
3840
public function testWillNotCreateWithoutConfig(): void
3941
{
4042
$this->container->method('get')

0 commit comments

Comments
 (0)