Skip to content

Commit df37bbc

Browse files
committed
Fix CS errors
1 parent a0a1bee commit df37bbc

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor/
55
composer.lock
66
tmp
77
.phpunit.result.cache
8+
.phpunit.cache

src/Listener/JsonApiListener.php

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,18 @@ public function beforeHandle(EventInterface $event): void
138138
* `?include=` query parameter was passed because that would override/break previously generated data.
139139
*
140140
* @param \Cake\Event\EventInterface $event Event
141-
* @return null
141+
* @return void
142142
*/
143-
public function afterFind(EventInterface $event)
143+
public function afterFind(EventInterface $event): void
144144
{
145145
if (!$this->_request()->is('get')) {
146-
return null;
146+
return;
147147
}
148148

149149
// set property so we can check inside `_renderWithResources()`
150150
if (!empty($event->getSubject()->query->getContain())) {
151151
$this->_ControllerHasSetContain = true;
152-
153-
return null;
154152
}
155-
156-
if ($this->getConfig('include')) {
157-
return null;
158-
}
159-
160-
return null;
161153
}
162154

163155
/**
@@ -203,16 +195,12 @@ public function beforeSave(EventInterface $event): void
203195
// hasMany found in the entity, extract ids from the request data
204196
$primaryResourceId = $this->_controller()->getRequest()->getData('id');
205197

206-
/**
207-
* @var array $hasManyIds
208-
*/
198+
/** @var array $hasManyIds */
209199
$hasManyIds = Hash::extract($this->_controller()->getRequest()->getData($key), '{n}.id');
210200
$hasManyTable = $this->getTableLocator()->get($associationName);
211201

212202
// query database only for hasMany that match both passed id and the id of the primary resource
213-
/**
214-
* @var string $entityForeignKey
215-
*/
203+
/** @var string $entityForeignKey */
216204
$entityForeignKey = $hasManyTable->getAssociation($entity->getSource())->getForeignKey();
217205
$primaryKey = current((array)$hasManyTable->getPrimaryKey());
218206
$query = $hasManyTable->find()
@@ -245,17 +233,21 @@ public function beforeSave(EventInterface $event): void
245233
* afterSave() event.
246234
*
247235
* @param \Cake\Event\EventInterface $event Event
248-
* @return bool|null
236+
* @return void
249237
*/
250-
public function afterSave(EventInterface $event): ?bool
238+
public function afterSave(EventInterface $event): void
251239
{
252240
if (!$event->getSubject()->success) {
253-
return false;
241+
$event->setResult(false);
242+
243+
return;
254244
}
255245

256246
// `created` will be set for add actions, `id` for edit actions
257247
if (!$event->getSubject()->created && !$event->getSubject()->id) {
258-
return false;
248+
$event->setResult(false);
249+
250+
return;
259251
}
260252

261253
// The `add`action (new Resource) MUST respond with HTTP Status Code 201,
@@ -269,8 +261,6 @@ public function afterSave(EventInterface $event): ?bool
269261
*/
270262
$subject = $event->getSubject();
271263
$this->render($subject);
272-
273-
return null;
274264
}
275265

276266
/**
@@ -281,17 +271,17 @@ public function afterSave(EventInterface $event): ?bool
281271
* been implemented here yet. http://jsonapi.org/format/#crud-deleting
282272
*
283273
* @param \Cake\Event\EventInterface $event Event
284-
* @return bool|null
274+
* @return void
285275
*/
286-
public function afterDelete(EventInterface $event): ?bool
276+
public function afterDelete(EventInterface $event): void
287277
{
288278
if (!$event->getSubject()->success) {
289-
return false;
279+
$event->setResult(false);
280+
281+
return;
290282
}
291283

292284
$this->_controller()->setResponse($this->_controller()->getResponse()->withStatus(204));
293-
294-
return null;
295285
}
296286

297287
/**

src/Schema/JsonApi/DynamicEntitySchema.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function getType(): string
8989
* @param \Cake\ORM\Entity $resource Entity
9090
* @return string
9191
* @psalm-suppress MoreSpecificImplementedParamType
92+
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
9293
*/
9394
public function getId($resource): ?string
9495
{
@@ -161,6 +162,7 @@ protected function entityToShallowArray(EntityInterface $entity): array
161162
* @param \Neomerx\JsonApi\Contracts\Schema\ContextInterface $context The Context
162163
* @return array
163164
* @psalm-suppress MoreSpecificImplementedParamType
165+
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
164166
*/
165167
public function getAttributes($resource, ContextInterface $context): iterable
166168
{
@@ -205,6 +207,7 @@ public function getAttributes($resource, ContextInterface $context): iterable
205207
* @param \Neomerx\JsonApi\Contracts\Schema\ContextInterface $context The Context
206208
* @return array
207209
* @psalm-suppress MoreSpecificImplementedParamType
210+
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
208211
*/
209212
public function getRelationships($resource, ContextInterface $context): iterable
210213
{
@@ -282,6 +285,7 @@ public function getRelationships($resource, ContextInterface $context): iterable
282285
* @param \Cake\ORM\Entity|null $resource Entity, null only to be compatible with the Neomerx method
283286
* @return string
284287
* @psalm-suppress MoreSpecificImplementedParamType
288+
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
285289
*/
286290
public function getSelfSubUrl($resource = null): string
287291
{
@@ -326,6 +330,7 @@ protected function getAssociationByProperty(string $name): ?Association
326330
* @param string $name Relationship name in lowercase singular or plural
327331
* @return \Neomerx\JsonApi\Contracts\Schema\LinkInterface
328332
* @psalm-suppress MoreSpecificImplementedParamType
333+
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
329334
*/
330335
public function getRelationshipSelfLink($resource, string $name): LinkInterface
331336
{
@@ -366,6 +371,7 @@ public function getRelationshipSelfLink($resource, string $name): LinkInterface
366371
* @param string $name Relationship name in lowercase singular or plural
367372
* @return \Neomerx\JsonApi\Contracts\Schema\LinkInterface
368373
* @psalm-suppress MoreSpecificImplementedParamType
374+
* @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
369375
*/
370376
public function getRelationshipRelatedLink($resource, string $name): LinkInterface
371377
{

tests/TestCase/Listener/JsonApiListenerTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,15 @@ public function testAfterSave()
252252

253253
// assert nothing happens if `success` is false
254254
$event->getSubject()->success = false;
255-
$this->assertFalse($this->callProtectedMethod('afterSave', [$event], $listener));
255+
$this->callProtectedMethod('afterSave', [$event], $listener);
256+
$this->assertFalse($event->getResult());
256257

257258
// assert nothing happens if `success` is true but both `created` and `id` are false
258259
$event->getSubject()->success = true;
259260
$event->getSubject()->created = false;
260261
$event->getSubject()->id = false;
261-
$this->assertFalse($this->callProtectedMethod('afterSave', [$event], $listener));
262+
$this->callProtectedMethod('afterSave', [$event], $listener);
263+
$this->assertFalse($event->getResult());
262264

263265
// assert success
264266
$table = $this->fetchTable('Countries');
@@ -331,7 +333,8 @@ public function testAfterDelete()
331333

332334
// assert nothing happens if `success` is false
333335
$event->getSubject()->success = false;
334-
$this->assertFalse($this->callProtectedMethod('afterDelete', [$event], $listener));
336+
$this->callProtectedMethod('afterDelete', [$event], $listener);
337+
$this->assertFalse($event->getResult());
335338

336339
$event->getSubject()->success = true;
337340
$this->assertNull($this->callProtectedMethod('afterDelete', [$event], $listener));

0 commit comments

Comments
 (0)