Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 18df547

Browse files
committed
Ensures internal API documentation is complete
- Adds return type hints where needed. - Adds docblocks and/or `@param`/`@return` annotations where needed.
1 parent da3a523 commit 18df547

11 files changed

+47
-47
lines changed

src/CommonProblemDetailsException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public function toArray() : array
8787
return $problem;
8888
}
8989

90+
/**
91+
* Allow serialization via json_encode().
92+
*
93+
* @return array
94+
*/
9095
public function jsonSerialize()
9196
{
9297
return $this->toArray();

src/ConfigProvider.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
namespace ProblemDetails;
44

55
/**
6-
* The configuration provider for the ProblemDetails module
6+
* Configuration provider for the package.
77
*
88
* @see https://docs.zendframework.com/zend-component-installer/
99
*/
1010
class ConfigProvider
1111
{
1212
/**
13-
* Returns the configuration array
14-
*
15-
* To add a bit of a structure, each section is defined in a separate
16-
* method which returns an array with its configuration.
17-
*
18-
* @return array
13+
* Returns the configuration array.
1914
*/
2015
public function __invoke() : array
2116
{
@@ -25,9 +20,7 @@ public function __invoke() : array
2520
}
2621

2722
/**
28-
* Returns the container dependencies
29-
*
30-
* @return array
23+
* Returns the container dependencies.
3124
*/
3225
public function getDependencies() : array
3326
{

src/ProblemDetailsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use JsonSerializable;
66

77
/**
8-
* Define an exception type for generating Problem Details.
8+
* Defines an exception type for generating Problem Details.
99
*/
1010
interface ProblemDetailsException extends JsonSerializable
1111
{

src/ProblemDetailsMiddleware.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(ProblemDetailsResponseFactory $responseFactory = nul
2929
/**
3030
* {@inheritDoc}
3131
*/
32-
public function process(ServerRequestInterface $request, DelegateInterface $delegate) : ResponseInterface
32+
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
3333
{
3434
// If we cannot provide a representation, act as a no-op.
3535
if (! $this->canActAsErrorHandler($request)) {
@@ -52,12 +52,14 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele
5252
return $response;
5353
}
5454

55+
/**
56+
* Can the middleware act as an error handler?
57+
*
58+
* Returns a boolean false if negotiation fails.
59+
*/
5560
private function canActAsErrorHandler(ServerRequestInterface $request) : bool
5661
{
5762
$accept = $request->getHeaderLine('Accept') ?: '*/*';
58-
if (empty($accept)) {
59-
return false;
60-
}
6163

6264
return null !== (new Negotiator())
6365
->getBest($accept, ProblemDetailsResponseFactory::NEGOTIATION_PRIORITIES);

test/ConfigProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class ConfigProviderTest extends TestCase
1313
{
14-
public function testReturnsExpectedDependencies()
14+
public function testReturnsExpectedDependencies() : void
1515
{
1616
$provider = new ConfigProvider();
1717
$config = $provider();

test/ProblemDetailsAssertionsTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
trait ProblemDetailsAssertionsTrait
99
{
10-
public function assertProblemDetails(array $expected, array $details)
10+
public function assertProblemDetails(array $expected, array $details) : void
1111
{
1212
foreach ($expected as $key => $value) {
1313
$this->assertArrayHasKey(
@@ -25,7 +25,7 @@ public function assertProblemDetails(array $expected, array $details)
2525
}
2626
}
2727

28-
public function assertExceptionDetails(Throwable $e, array $details)
28+
public function assertExceptionDetails(Throwable $e, array $details) : void
2929
{
3030
$this->assertArrayHasKey('class', $details);
3131
$this->assertSame(get_class($e), $details['class']);

test/ProblemDetailsExceptionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ProblemDetailsExceptionTest extends TestCase
1616
'foo' => 'bar',
1717
];
1818

19-
protected function setUp()
19+
protected function setUp() : void
2020
{
2121
$this->exception = new class (
2222
$this->status,
@@ -38,7 +38,7 @@ public function __construct(int $status, string $detail, string $title, string $
3838
};
3939
}
4040

41-
public function testCanPullDetailsIndividually()
41+
public function testCanPullDetailsIndividually() : void
4242
{
4343
$this->assertEquals($this->status, $this->exception->getStatus());
4444
$this->assertEquals($this->detail, $this->exception->getDetail());
@@ -47,7 +47,7 @@ public function testCanPullDetailsIndividually()
4747
$this->assertEquals($this->additional, $this->exception->getAdditionalData());
4848
}
4949

50-
public function testCanCastDetailsToArray()
50+
public function testCanCastDetailsToArray() : void
5151
{
5252
$this->assertEquals([
5353
'status' => $this->status,
@@ -58,7 +58,7 @@ public function testCanCastDetailsToArray()
5858
], $this->exception->toArray());
5959
}
6060

61-
public function testIsJsonSerializable()
61+
public function testIsJsonSerializable() : void
6262
{
6363
$problem = json_decode(json_encode($this->exception), true);
6464

test/ProblemDetailsMiddlewareFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
class ProblemDetailsMiddlewareFactoryTest extends TestCase
1212
{
13-
protected function setUp()
13+
protected function setUp() : void
1414
{
1515
$this->container = $this->prophesize(ContainerInterface::class);
1616
$this->factory = new ProblemDetailsMiddlewareFactory();
1717
}
1818

19-
public function testCreatesMiddlewareWithoutResponseFactoryIfServiceDoesNotExist()
19+
public function testCreatesMiddlewareWithoutResponseFactoryIfServiceDoesNotExist() : void
2020
{
2121
$this->container->has(ProblemDetailsResponseFactory::class)->willReturn(false);
2222
$this->container->get(ProblemDetailsResponseFactory::class)->shouldNotBeCalled();
@@ -31,7 +31,7 @@ public function testCreatesMiddlewareWithoutResponseFactoryIfServiceDoesNotExist
3131
);
3232
}
3333

34-
public function testCreatesMiddlewareUsingResponseFactoryService()
34+
public function testCreatesMiddlewareUsingResponseFactoryService() : void
3535
{
3636
$responseFactory = $this->prophesize(ProblemDetailsResponseFactory::class)->reveal();
3737
$this->container->has(ProblemDetailsResponseFactory::class)->willReturn(true);

test/ProblemDetailsMiddlewareTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class ProblemDetailsMiddlewareTest extends TestCase
1616
{
1717
use ProblemDetailsAssertionsTrait;
1818

19-
protected function setUp()
19+
protected function setUp() : void
2020
{
2121
$this->request = $this->prophesize(ServerRequestInterface::class);
2222
$this->responseFactory = $this->prophesize(ProblemDetailsResponseFactory::class);
2323
$this->middleware = new ProblemDetailsMiddleware($this->responseFactory->reveal());
2424
}
2525

26-
public function acceptHeaders()
26+
public function acceptHeaders() : array
2727
{
2828
return [
2929
'empty' => [''],
@@ -34,7 +34,7 @@ public function acceptHeaders()
3434
];
3535
}
3636

37-
public function testSuccessfulDelegationReturnsDelegateResponse()
37+
public function testSuccessfulDelegationReturnsDelegateResponse() : void
3838
{
3939
$response = $this->prophesize(ResponseInterface::class);
4040
$delegate = $this->prophesize(DelegateInterface::class);
@@ -52,7 +52,7 @@ public function testSuccessfulDelegationReturnsDelegateResponse()
5252
/**
5353
* @dataProvider acceptHeaders
5454
*/
55-
public function testDelegateNotReturningResponseResultsInProblemDetails(string $accept)
55+
public function testDelegateNotReturningResponseResultsInProblemDetails(string $accept) : void
5656
{
5757
$this->request->getHeaderLine('Accept')->willReturn($accept);
5858

@@ -74,7 +74,7 @@ public function testDelegateNotReturningResponseResultsInProblemDetails(string $
7474
/**
7575
* @dataProvider acceptHeaders
7676
*/
77-
public function testThrowableRaisedByDelegateResultsInProblemDetails(string $accept)
77+
public function testThrowableRaisedByDelegateResultsInProblemDetails(string $accept) : void
7878
{
7979
$this->request->getHeaderLine('Accept')->willReturn($accept);
8080

@@ -98,7 +98,7 @@ public function testThrowableRaisedByDelegateResultsInProblemDetails(string $acc
9898
/**
9999
* @dataProvider acceptHeaders
100100
*/
101-
public function testMiddlewareRegistersErrorHandlerToConvertErrorsToProblemDetails(string $accept)
101+
public function testMiddlewareRegistersErrorHandlerToConvertErrorsToProblemDetails(string $accept) : void
102102
{
103103
$this->request->getHeaderLine('Accept')->willReturn($accept);
104104

@@ -124,7 +124,7 @@ public function testMiddlewareRegistersErrorHandlerToConvertErrorsToProblemDetai
124124
$this->assertSame($expected, $result);
125125
}
126126

127-
public function testRethrowsCaughtExceptionIfUnableToNegotiateAcceptHeader()
127+
public function testRethrowsCaughtExceptionIfUnableToNegotiateAcceptHeader() : void
128128
{
129129
$this->request->getHeaderLine('Accept')->willReturn('text/html');
130130
$exception = new TestAsset\RuntimeException('Thrown!', 507);

test/ProblemDetailsResponseFactoryFactoryTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
class ProblemDetailsResponseFactoryFactoryTest extends TestCase
1414
{
15-
protected function setUp()
15+
protected function setUp() : void
1616
{
1717
$this->container = $this->prophesize(ContainerInterface::class);
1818
}
1919

20-
public function testLackOfOptionalServicesResultsInFactoryUsingDefaults()
20+
public function testLackOfOptionalServicesResultsInFactoryUsingDefaults() : void
2121
{
2222
$this->container->has('config')->willReturn(false);
2323
$this->container->has(ResponseInterface::class)->willReturn(false);
@@ -38,7 +38,7 @@ public function testLackOfOptionalServicesResultsInFactoryUsingDefaults()
3838
$this->assertAttributeInstanceOf(Closure::class, 'bodyFactory', $factory);
3939
}
4040

41-
public function testUsesDebugSettingFromConfigWhenPresent()
41+
public function testUsesDebugSettingFromConfigWhenPresent() : void
4242
{
4343
$this->container->has('config')->willReturn(true);
4444
$this->container->get('config')->willReturn(['debug' => true]);
@@ -53,7 +53,7 @@ public function testUsesDebugSettingFromConfigWhenPresent()
5353
$this->assertAttributeSame(ProblemDetailsResponseFactory::INCLUDE_THROWABLE_DETAILS, 'isDebug', $factory);
5454
}
5555

56-
public function testUsesJsonFlagsSettingFromConfigWhenPresent()
56+
public function testUsesJsonFlagsSettingFromConfigWhenPresent() : void
5757
{
5858
$this->container->has('config')->willReturn(true);
5959
$this->container->get('config')->willReturn(['problem-details' => ['json_flags' => JSON_PRETTY_PRINT]]);
@@ -68,7 +68,7 @@ public function testUsesJsonFlagsSettingFromConfigWhenPresent()
6868
$this->assertAttributeSame(JSON_PRETTY_PRINT, 'jsonFlags', $factory);
6969
}
7070

71-
public function testUsesResponseServiceFromContainerWhenPresent()
71+
public function testUsesResponseServiceFromContainerWhenPresent() : void
7272
{
7373
$response = $this->prophesize(ResponseInterface::class)->reveal();
7474

@@ -84,7 +84,7 @@ public function testUsesResponseServiceFromContainerWhenPresent()
8484
$this->assertAttributeSame($response, 'response', $factory);
8585
}
8686

87-
public function testUsesStreamFactoryServiceFromContainerWhenPresent()
87+
public function testUsesStreamFactoryServiceFromContainerWhenPresent() : void
8888
{
8989
// @codingStandardsIgnoreStart
9090
$streamFactory = function () { };

0 commit comments

Comments
 (0)