Skip to content

Commit 6a5c9ab

Browse files
authored
Merge pull request #1440 from meyerbaptiste/fix_cs_missing_return_statement
Fix missing return statement
2 parents 96db7e2 + 11cb9c6 commit 6a5c9ab

File tree

8 files changed

+402
-106
lines changed

8 files changed

+402
-106
lines changed

.php_cs.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ return PhpCsFixer\Config::create()
4343
'throw',
4444
'use',
4545
],
46-
'no_unreachable_default_argument_value' => true,
4746
'no_useless_else' => true,
4847
'no_useless_return' => true,
4948
'ordered_imports' => true,

src/Bridge/NelmioApiDoc/Extractor/AnnotationsProvider/ApiPlatformProvider.php

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,19 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName
5353
*/
5454
public function getAnnotations(): array
5555
{
56-
$hydraDoc = $this->documentationNormalizer->normalize(new Documentation($this->resourceNameCollectionFactory->create()));
57-
$entrypointHydraDoc = $this->getResourceHydraDoc($hydraDoc, '#Entrypoint');
56+
$resourceNameCollection = $this->resourceNameCollectionFactory->create();
57+
$hydraDoc = $this->documentationNormalizer->normalize(new Documentation($resourceNameCollection));
58+
if (empty($hydraDoc)) {
59+
return [];
60+
}
5861

59-
if (empty($hydraDoc) || null === $entrypointHydraDoc) {
62+
$entrypointHydraDoc = $this->getResourceHydraDoc($hydraDoc, '#Entrypoint');
63+
if (null === $entrypointHydraDoc) {
6064
return [];
6165
}
6266

6367
$annotations = [];
64-
foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) {
68+
foreach ($resourceNameCollection as $resourceClass) {
6569
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
6670

6771
$prefixedShortName = ($iri = $resourceMetadata->getIri()) ? $iri : '#'.$resourceMetadata->getShortName();
@@ -112,9 +116,9 @@ private function getApiDoc(bool $collection, string $resourceClass, ResourceMeta
112116

113117
$data = [
114118
'resource' => $route->getPath(),
115-
'description' => $operationHydraDoc['hydra:title'],
116-
'resourceDescription' => $resourceHydraDoc['hydra:title'],
117-
'section' => $resourceHydraDoc['hydra:title'],
119+
'description' => $operationHydraDoc['hydra:title'] ?? '',
120+
'resourceDescription' => $resourceHydraDoc['hydra:title'] ?? '',
121+
'section' => $resourceHydraDoc['hydra:title'] ?? '',
118122
];
119123

120124
if (isset($operationHydraDoc['expects']) && 'owl:Nothing' !== $operationHydraDoc['expects']) {
@@ -154,11 +158,17 @@ private function getApiDoc(bool $collection, string $resourceClass, ResourceMeta
154158
*/
155159
private function getResourceHydraDoc(array $hydraApiDoc, string $prefixedShortName)
156160
{
161+
if (!isset($hydraApiDoc['hydra:supportedClass']) || !is_array($hydraApiDoc['hydra:supportedClass'])) {
162+
return null;
163+
}
164+
157165
foreach ($hydraApiDoc['hydra:supportedClass'] as $supportedClass) {
158-
if ($supportedClass['@id'] === $prefixedShortName) {
166+
if (isset($supportedClass['@id']) && $supportedClass['@id'] === $prefixedShortName) {
159167
return $supportedClass;
160168
}
161169
}
170+
171+
return null;
162172
}
163173

164174
/**
@@ -167,15 +177,21 @@ private function getResourceHydraDoc(array $hydraApiDoc, string $prefixedShortNa
167177
* @param string $method
168178
* @param array $hydraDoc
169179
*
170-
* @return array|null
180+
* @return array
171181
*/
172-
private function getOperationHydraDoc(string $method, array $hydraDoc)
182+
private function getOperationHydraDoc(string $method, array $hydraDoc): array
173183
{
184+
if (!isset($hydraDoc['hydra:supportedOperation']) || !is_array($hydraDoc['hydra:supportedOperation'])) {
185+
return [];
186+
}
187+
174188
foreach ($hydraDoc['hydra:supportedOperation'] as $supportedOperation) {
175189
if ($supportedOperation['hydra:method'] === $method) {
176190
return $supportedOperation;
177191
}
178192
}
193+
194+
return [];
179195
}
180196

181197
/**
@@ -185,17 +201,23 @@ private function getOperationHydraDoc(string $method, array $hydraDoc)
185201
* @param string $method
186202
* @param array $hydraEntrypointDoc
187203
*
188-
* @return array|null
204+
* @return array
189205
*/
190-
private function getCollectionOperationHydraDoc(string $shortName, string $method, array $hydraEntrypointDoc)
206+
private function getCollectionOperationHydraDoc(string $shortName, string $method, array $hydraEntrypointDoc): array
191207
{
208+
if (!isset($hydraEntrypointDoc['hydra:supportedProperty']) || !is_array($hydraEntrypointDoc['hydra:supportedProperty'])) {
209+
return [];
210+
}
211+
192212
$propertyName = '#Entrypoint/'.lcfirst($shortName);
193213

194214
foreach ($hydraEntrypointDoc['hydra:supportedProperty'] as $supportedProperty) {
195-
$hydraProperty = $supportedProperty['hydra:property'];
196-
if ($hydraProperty['@id'] === $propertyName) {
197-
return $this->getOperationHydraDoc($method, $hydraProperty);
215+
if (isset($supportedProperty['hydra:property']['@id'])
216+
&& $supportedProperty['hydra:property']['@id'] === $propertyName) {
217+
return $this->getOperationHydraDoc($method, $supportedProperty['hydra:property']);
198218
}
199219
}
220+
221+
return [];
200222
}
201223
}

src/DataProvider/ChainCollectionDataProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ public function getCollection(string $resourceClass, string $operationName = nul
4444
continue;
4545
}
4646
}
47+
48+
return [];
4749
}
4850
}

src/DataProvider/ChainItemDataProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ public function getItem(string $resourceClass, $id, string $operationName = null
4444
continue;
4545
}
4646
}
47+
48+
return null;
4749
}
4850
}

src/Hal/Serializer/ItemNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
8181
/**
8282
* {@inheritdoc}
8383
*/
84-
protected function getAttributes($object, $format, array $context)
84+
protected function getAttributes($object, $format = null, array $context)
8585
{
8686
return $this->getComponents($object, $format, $context)['states'];
8787
}

src/Hydra/Serializer/DocumentationNormalizer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ private function getRange(PropertyMetadata $propertyMetadata)
324324
}
325325
break;
326326
}
327+
328+
return null;
327329
}
328330

329331
/**

0 commit comments

Comments
 (0)