Skip to content

Commit b80950f

Browse files
authored
Improve (#10)
1 parent a029d8d commit b80950f

9 files changed

+41
-37
lines changed

src/App/Helper/ArrayAppendHelperTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait ArrayAppendHelperTrait
1313
*
1414
* @return array
1515
*/
16-
protected function appendIfValueHaveSiblings(string $key, array $value, array $doc = [])
16+
protected function appendIfValueHaveSiblings(string $key, array $value, array $doc = []) : array
1717
{
1818
return $this->appendIf((count($value) > 0), $key, $value, $doc);
1919
}
@@ -25,7 +25,7 @@ protected function appendIfValueHaveSiblings(string $key, array $value, array $d
2525
*
2626
* @return array
2727
*/
28-
protected function appendIfValueNotNull(string $key, $value, array $doc = [])
28+
protected function appendIfValueNotNull(string $key, $value, array $doc = []) : array
2929
{
3030
return $this->appendIf((null !== $value), $key, $value, $doc);
3131
}
@@ -38,7 +38,7 @@ protected function appendIfValueNotNull(string $key, $value, array $doc = [])
3838
*
3939
* @return array
4040
*/
41-
protected function appendIf(bool $doAppend, string $key, $value, array $doc = [])
41+
protected function appendIf(bool $doAppend, string $key, $value, array $doc = []) : array
4242
{
4343
if (true === $doAppend) {
4444
$doc[$key] = $value;

src/App/Normalizer/Component/ErrorDocNormalizer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ public function __construct(
2626
}
2727

2828
/**
29-
* {@inheritdoc}
29+
* @param ErrorDoc $errorDoc
30+
*
31+
* @return array
3032
*
3133
* @throws \ReflectionException
3234
*/
33-
public function normalize(ErrorDoc $errorDoc)
35+
public function normalize(ErrorDoc $errorDoc) : array
3436
{
3537
$requiredDoc = ['required' => ['code']];
3638
$properties = [

src/App/Normalizer/Component/ExternalSchemaListDocNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939
*
4040
* @throws \ReflectionException
4141
*/
42-
public function normalize(ServerDoc $doc)
42+
public function normalize(ServerDoc $doc) : array
4343
{
4444
return array_merge(
4545
$this->getMethodsExternalSchemaList($doc),
@@ -55,7 +55,7 @@ public function normalize(ServerDoc $doc)
5555
*
5656
* @throws \ReflectionException
5757
*/
58-
protected function getMethodsExternalSchemaList(ServerDoc $doc)
58+
protected function getMethodsExternalSchemaList(ServerDoc $doc) : array
5959
{
6060
$list = [];
6161
foreach ($doc->getMethodList() as $method) {
@@ -73,7 +73,7 @@ protected function getMethodsExternalSchemaList(ServerDoc $doc)
7373
*
7474
* @throws \ReflectionException
7575
*/
76-
protected function getMethodErrorsExternalSchemaList(ServerDoc $doc)
76+
protected function getMethodErrorsExternalSchemaList(ServerDoc $doc) : array
7777
{
7878
$list = [];
7979
foreach ($doc->getMethodList() as $method) {
@@ -97,7 +97,7 @@ protected function getMethodErrorsExternalSchemaList(ServerDoc $doc)
9797
*
9898
* @throws \ReflectionException
9999
*/
100-
protected function getServerErrorsExtraSchemaList(ServerDoc $doc)
100+
protected function getServerErrorsExtraSchemaList(ServerDoc $doc) : array
101101
{
102102
$list = [];
103103
foreach ($doc->getGlobalErrorList() as $errorDoc) {

src/App/Normalizer/Component/RequestDocNormalizer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ public function __construct(
2727
}
2828

2929
/**
30-
* {@inheritdoc}
30+
* @param MethodDoc $method
31+
*
32+
* @return array
3133
*/
32-
public function normalize(MethodDoc $method)
34+
public function normalize(MethodDoc $method) : array
3335
{
3436
$operationProperties = ['method' => ['example' => $method->getMethodName()]];
3537

src/App/Normalizer/Component/ResponseDocNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
*
3737
* @return array
3838
*/
39-
public function normalize(MethodDoc $method, array $extraErrorDefinitionIdRefList = [])
39+
public function normalize(MethodDoc $method, array $extraErrorDefinitionIdRefList = []) : array
4040
{
4141
$responseErrorShape = [];
4242
$errorArrayDoc = $this->getMethodErrorArrayDoc($method, $extraErrorDefinitionIdRefList);
@@ -63,7 +63,7 @@ public function normalize(MethodDoc $method, array $extraErrorDefinitionIdRefLis
6363
*
6464
* @return array
6565
*/
66-
protected function getMethodResultArrayDoc(MethodDoc $method)
66+
protected function getMethodResultArrayDoc(MethodDoc $method) : array
6767
{
6868
if (null !== $method->getResultDoc()) {
6969
$result = [
@@ -87,7 +87,7 @@ protected function getMethodResultArrayDoc(MethodDoc $method)
8787
*
8888
* @return array
8989
*/
90-
protected function getMethodErrorArrayDoc(MethodDoc $method, array $extraErrorDefinitionIdRefList = [])
90+
protected function getMethodErrorArrayDoc(MethodDoc $method, array $extraErrorDefinitionIdRefList = []) : array
9191
{
9292
$self = $this;
9393

src/App/Normalizer/Component/SchemaTypeNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SchemaTypeNormalizer
1515
*
1616
* @throws \ReflectionException
1717
*/
18-
public function normalize(TypeDoc $doc)
18+
public function normalize(TypeDoc $doc) : string
1919
{
2020
$type = str_replace('Doc', '', lcfirst((new \ReflectionClass($doc))->getShortName()));
2121
// translate type

src/App/Normalizer/Component/ShapeNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ShapeNormalizer
99
/**
1010
* @return array
1111
*/
12-
public function getRequestShapeDefinition()
12+
public function getRequestShapeDefinition() : array
1313
{
1414
return [
1515
'type' => 'object',
@@ -42,7 +42,7 @@ public function getRequestShapeDefinition()
4242
/**
4343
* @return array
4444
*/
45-
public function getResponseShapeDefinition()
45+
public function getResponseShapeDefinition() : array
4646
{
4747
return [
4848
'type' => 'object',
@@ -74,7 +74,7 @@ public function getResponseShapeDefinition()
7474
/**
7575
* @return array
7676
*/
77-
public function getErrorShapeDefinition()
77+
public function getErrorShapeDefinition() : array
7878
{
7979
return [
8080
'type' => 'object',

src/App/Normalizer/Component/TypeDocNormalizer.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(SchemaTypeNormalizer $schemaTypeNormalizer)
3434
*
3535
* @throws \ReflectionException
3636
*/
37-
public function normalize(TypeDoc $doc)
37+
public function normalize(TypeDoc $doc) : array
3838
{
3939
$siblingsDoc = $paramDocRequired = [];
4040

@@ -47,24 +47,24 @@ public function normalize(TypeDoc $doc)
4747
$format = ($doc instanceof StringDoc ? $doc->getFormat() : null);
4848

4949
return $this->appendIfValueNotNull('description', $doc->getDescription())
50-
+ ['type' => $this->schemaTypeNormalizer->normalize($doc)]
51-
+ $this->appendIfValueNotNull('format', $format)
52-
+ ['nullable' => $doc->isNullable()]
53-
+ $paramDocRequired
54-
+ $this->appendIfValueNotNull('default', $doc->getDefault())
55-
+ $this->appendIfValueNotNull('example', $doc->getExample())
56-
+ $this->appendIfValueHaveSiblings('enum', array_values($doc->getAllowedValueList()))
57-
+ $this->getMinMaxDoc($doc)
58-
+ $siblingsDoc
59-
;
50+
+ ['type' => $this->schemaTypeNormalizer->normalize($doc)]
51+
+ $this->appendIfValueNotNull('format', $format)
52+
+ ['nullable' => $doc->isNullable()]
53+
+ $paramDocRequired
54+
+ $this->appendIfValueNotNull('default', $doc->getDefault())
55+
+ $this->appendIfValueNotNull('example', $doc->getExample())
56+
+ $this->appendIfValueHaveSiblings('enum', array_values($doc->getAllowedValueList()))
57+
+ $this->getMinMaxDoc($doc)
58+
+ $siblingsDoc
59+
;
6060
}
6161

6262
/**
6363
* @param TypeDoc $doc
6464
*
6565
* @return array
6666
*/
67-
protected function getMinMaxDoc(TypeDoc $doc)
67+
protected function getMinMaxDoc(TypeDoc $doc) : array
6868
{
6969
$paramDocMinMax = [];
7070
if ($doc instanceof StringDoc) {
@@ -93,7 +93,7 @@ protected function getMinMaxDoc(TypeDoc $doc)
9393
*
9494
* @throws \ReflectionException
9595
*/
96-
protected function appendArrayDoc(TypeDoc $doc, array $siblingsDoc)
96+
protected function appendArrayDoc(TypeDoc $doc, array $siblingsDoc) : array
9797
{
9898
// CollectionDoc should be managed as ArrayDoc
9999
if (!$doc instanceof ArrayDoc && get_class($doc) !== CollectionDoc::class) {
@@ -117,7 +117,7 @@ protected function appendArrayDoc(TypeDoc $doc, array $siblingsDoc)
117117
*
118118
* @return array
119119
*/
120-
protected function appendObjectDoc(TypeDoc $doc, array $siblingsDoc, array $paramDocRequired)
120+
protected function appendObjectDoc(TypeDoc $doc, array $siblingsDoc, array $paramDocRequired) : array
121121
{
122122
if (!$doc instanceof ObjectDoc) {
123123
return [$siblingsDoc, $paramDocRequired];
@@ -162,7 +162,7 @@ function (array $carry, TypeDoc $sibling) {
162162
*
163163
* @return string
164164
*/
165-
protected function guessItemsType(array $siblingList)
165+
protected function guessItemsType(array $siblingList) : string
166166
{
167167
$self = $this;
168168
$uniqueTypeList = array_unique(
@@ -188,7 +188,7 @@ function (TypeDoc $sibling) use ($self) {
188188
*
189189
* @return array
190190
*/
191-
protected function appendNumberMinMax(NumberDoc $doc, array $paramDocMinMax)
191+
protected function appendNumberMinMax(NumberDoc $doc, array $paramDocMinMax) : array
192192
{
193193
$paramDocMinMax = $this->appendIfValueNotNull('minimum', $doc->getMin(), $paramDocMinMax);
194194
$paramDocMinMax = $this->appendIf(

src/App/Resolver/DefinitionRefResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DefinitionRefResolver
2020
*
2121
* @return string
2222
*/
23-
public function getMethodDefinitionId(MethodDoc $method, $definitionType)
23+
public function getMethodDefinitionId(MethodDoc $method, $definitionType) : string
2424
{
2525
$base = 'UNKNONWN_METHOD-%s';
2626
switch ($definitionType) {
@@ -41,7 +41,7 @@ public function getMethodDefinitionId(MethodDoc $method, $definitionType)
4141
*
4242
* @return string
4343
*/
44-
public function getErrorDefinitionId(ErrorDoc $error, $definitionType)
44+
public function getErrorDefinitionId(ErrorDoc $error, $definitionType) : string
4545
{
4646
$base = 'UNKNONWN_ERROR-%s';
4747
switch ($definitionType) {
@@ -61,7 +61,7 @@ public function getErrorDefinitionId(ErrorDoc $error, $definitionType)
6161
*
6262
* @return string
6363
*/
64-
public function getDefinitionRef(string $path)
64+
public function getDefinitionRef(string $path) : string
6565
{
6666
return sprintf('#/components/schemas/%s', $path);
6767
}

0 commit comments

Comments
 (0)