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

Commit 210bba7

Browse files
committed
Renamed default_types to default_types_map
1 parent a621f3f commit 210bba7

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pages:
99
- "Exceptions": exception.md
1010
- "Error Handling Middleware": middleware.md
1111
- "Not Found Handler": not-found-handler.md
12+
- "Default types": default-types.md
1213
site_name: zend-problem-details
1314
site_description: 'PSR-7 Problem Details for HTTP API responses and middleware'
1415
repo_url: 'https://github.com/zendframework/zend-problem-details'

src/ProblemDetailsResponseFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,15 @@ class ProblemDetailsResponseFactory
211211
*
212212
* @var array
213213
*/
214-
private $defaultTypes;
214+
private $defaultTypesMap;
215215

216216
public function __construct(
217217
callable $responseFactory,
218218
bool $isDebug = self::EXCLUDE_THROWABLE_DETAILS,
219219
int $jsonFlags = null,
220220
bool $exceptionDetailsInResponse = false,
221221
string $defaultDetailMessage = self::DEFAULT_DETAIL_MESSAGE,
222-
array $defaultTypes = []
222+
array $defaultTypesMap = []
223223
) {
224224
// Ensures type safety of the composed factory
225225
$this->responseFactory = function () use ($responseFactory) : ResponseInterface {
@@ -238,7 +238,7 @@ public function __construct(
238238
$this->jsonFlags = $jsonFlags;
239239
$this->exceptionDetailsInResponse = $exceptionDetailsInResponse;
240240
$this->defaultDetailMessage = $defaultDetailMessage;
241-
$this->defaultTypes = $defaultTypes;
241+
$this->defaultTypesMap = $defaultTypesMap;
242242
}
243243

244244
public function createResponse(
@@ -403,7 +403,7 @@ private function createTitleFromStatus(int $status) : string
403403

404404
private function createTypeFromStatus(int $status) : string
405405
{
406-
return $this->defaultTypes[$status] ?? sprintf('https://httpstatus.es/%s', $status);
406+
return $this->defaultTypesMap[$status] ?? sprintf('https://httpstatus.es/%s', $status);
407407
}
408408

409409
private function createThrowableDetail(Throwable $e) : array

src/ProblemDetailsResponseFactoryFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public function __invoke(ContainerInterface $container) : ProblemDetailsResponse
2121

2222
$problemDetailsConfig = $config['problem-details'] ?? [];
2323
$jsonFlags = $problemDetailsConfig['json_flags'] ?? null;
24-
$defaultTypes = $problemDetailsConfig['default_types'] ?? [];
24+
$defaultTypesMap = $problemDetailsConfig['default_types_map'] ?? [];
2525

2626
return new ProblemDetailsResponseFactory(
2727
$container->get(ResponseInterface::class),
2828
$includeThrowableDetail,
2929
$jsonFlags,
3030
$includeThrowableDetail,
3131
ProblemDetailsResponseFactory::DEFAULT_DETAIL_MESSAGE,
32-
$defaultTypes
32+
$defaultTypesMap
3333
);
3434
}
3535
}

test/ProblemDetailsResponseFactoryFactoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ public function testUsesDefaultTypesSettingFromConfigWhenPresent() : void
147147
];
148148

149149
$this->container->has('config')->willReturn(true);
150-
$this->container->get('config')->willReturn(['problem-details' => ['default_types' => $expectedDefaultTypes]]);
150+
$this->container->get('config')->willReturn(
151+
['problem-details' => ['default_types_map' => $expectedDefaultTypes]]
152+
);
151153

152154
$this->container->get(ResponseInterface::class)->willReturn(function () {
153155
});
@@ -156,6 +158,6 @@ public function testUsesDefaultTypesSettingFromConfigWhenPresent() : void
156158
$factory = $factoryFactory($this->container->reveal());
157159

158160
$this->assertInstanceOf(ProblemDetailsResponseFactory::class, $factory);
159-
$this->assertAttributeSame($expectedDefaultTypes, 'defaultTypes', $factory);
161+
$this->assertAttributeSame($expectedDefaultTypes, 'defaultTypesMap', $factory);
160162
}
161163
}

test/ProblemDetailsResponseFactoryTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,23 +479,23 @@ function (array $payload) {
479479

480480
public function provideMappedStatuses() : array
481481
{
482-
$defaultTypes = [
482+
$defaultTypesMap = [
483483
404 => 'https://example.com/problem-details/error/not-found',
484484
500 => 'https://example.com/problem-details/error/internal-server-error',
485485
];
486486

487487
return [
488-
[$defaultTypes, 404, 'https://example.com/problem-details/error/not-found'],
489-
[$defaultTypes, 500, 'https://example.com/problem-details/error/internal-server-error'],
490-
[$defaultTypes, 400, 'https://httpstatus.es/400'],
488+
[$defaultTypesMap, 404, 'https://example.com/problem-details/error/not-found'],
489+
[$defaultTypesMap, 500, 'https://example.com/problem-details/error/internal-server-error'],
490+
[$defaultTypesMap, 400, 'https://httpstatus.es/400'],
491491
[[], 500, 'https://httpstatus.es/500'],
492492
];
493493
}
494494

495495
/**
496496
* @dataProvider provideMappedStatuses
497497
*/
498-
public function testTypeIsInferredFromDefaultTypesMap(array $defaultTypes, int $status, string $expectedType) : void
498+
public function testTypeIsInferredFromDefaultTypesMap(array $map, int $status, string $expectedType) : void
499499
{
500500
$this->request->getHeaderLine('Accept')->willReturn('application/json');
501501

@@ -519,7 +519,7 @@ function () {
519519
null,
520520
false,
521521
'',
522-
$defaultTypes
522+
$map
523523
);
524524

525525
$factory->createResponse($this->request->reveal(), $status, 'detail');

0 commit comments

Comments
 (0)