Skip to content

Commit d0e3c85

Browse files
committed
[PHPStan] Fixed reported errors
1 parent bd800f0 commit d0e3c85

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

code_samples/collaboration/src/Collaboration/Cart/CartResolverDecorator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ public function resolveCart(?User $user = null): CartInterface
3535

3636
private function getSharedCart(): ?CartInterface
3737
{
38-
/** @var \App\Collaboration\Cart\CartSession $session */
3938
try {
4039
$session = $this->sessionService->getSessionByToken(
4140
$this->requestStack->getSession()->get(PermissionResolverDecorator::COLLABORATION_SESSION_ID)
4241
);
4342

43+
if (!$session instanceof CartSession) {
44+
return null;
45+
}
46+
4447
return $session->getCart();
4548
} catch (NotFoundException|\Ibexa\ProductCatalog\Exception\UnauthorizedException $e) {
4649
return null;

code_samples/collaboration/src/Collaboration/Cart/Mapper/CartProxyMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function createCartProxy(string $identifier): CartInterface
3333
&$initializer
3434
) use ($identifier): bool {
3535
$initializer = null;
36-
$wrappedObject = $this->repository->sudo(fn () => $this->cartService->getCart($identifier));
36+
$wrappedObject = $this->repository->sudo(fn (): CartInterface => $this->cartService->getCart($identifier));
3737

3838
return true;
3939
};

code_samples/collaboration/src/Collaboration/Cart/Mapper/CartSessionPersistenceMapper.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ final class CartSessionPersistenceMapper implements SessionPersistenceMapperInte
2525
public function toPersistenceCreateStruct(
2626
SessionCreateStruct $createStruct
2727
): PersistenceSessionCreateStruct {
28+
$token = $createStruct->getToken();
29+
$owner = $createStruct->getOwner();
30+
$hasPublicLink = $createStruct->hasPublicLink();
31+
32+
assert($token !== null);
33+
assert($owner !== null);
34+
assert($hasPublicLink !== null);
35+
2836
return new CartSessionCreateStruct(
29-
$createStruct->getToken(),
37+
$token,
3038
$createStruct->getCart()->getIdentifier(),
31-
$createStruct->getOwner()->getUserId(),
39+
$owner->getUserId(),
3240
$createStruct->isActive(),
33-
$createStruct->hasPublicLink(),
41+
$hasPublicLink,
3442
new \DateTimeImmutable(),
3543
new \DateTimeImmutable()
3644
);

code_samples/collaboration/src/Collaboration/Cart/PermissionResolverDecorator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public function __construct(
3333

3434
public function canUser(PolicyInterface $policy): bool
3535
{
36-
if ($this->nested === false && $this->isCartPolicy($policy) && $this->isSharedCart($policy->getObject())) {
36+
$object = $policy->getObject();
37+
if ($this->nested === false && $this->isCartPolicy($policy) && $object instanceof CartInterface && $this->isSharedCart($object)) {
3738
return true;
3839
}
3940

@@ -42,7 +43,8 @@ public function canUser(PolicyInterface $policy): bool
4243

4344
public function assertPolicy(PolicyInterface $policy): void
4445
{
45-
if ($this->nested === false && $this->isCartPolicy($policy) && $this->isSharedCart($policy->getObject())) {
46+
$object = $policy->getObject();
47+
if ($this->nested === false && $this->isCartPolicy($policy) && $object instanceof CartInterface && $this->isSharedCart($object)) {
4648
return;
4749
}
4850

code_samples/collaboration/src/Controller/ShareCartCreateController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Ibexa\Contracts\Cart\CartResolverInterface;
1515
use Ibexa\Contracts\Collaboration\Participant\ExternalParticipantCreateStruct;
1616
use Ibexa\Contracts\Collaboration\SessionServiceInterface;
17+
use InvalidArgumentException;
1718
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1819
use Symfony\Component\HttpFoundation\Request;
1920
use Symfony\Component\HttpFoundation\Response;
@@ -52,10 +53,15 @@ public function __invoke(Request $request): Response
5253
new CartSessionCreateStruct($cart)
5354
);
5455

56+
$email = $data->getEmail();
57+
if ($email === null) {
58+
throw new InvalidArgumentException('Email cannot be null');
59+
}
60+
5561
$this->sessionService->addParticipant(
5662
$session,
5763
new ExternalParticipantCreateStruct(
58-
$data->getEmail(),
64+
$email,
5965
CartSessionType::SCOPE_EDIT
6066
)
6167
);

code_samples/collaboration/src/Form/Type/ShareCartType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Symfony\Component\Form\FormBuilderInterface;
1515
use Symfony\Component\OptionsResolver\OptionsResolver;
1616

17+
/**
18+
* @extends AbstractType<ShareCartData>
19+
*/
1720
final class ShareCartType extends AbstractType
1821
{
1922
public function buildForm(FormBuilderInterface $builder, array $options): void

0 commit comments

Comments
 (0)