Skip to content

Commit ce8fa2f

Browse files
committed
Fix phpstan new errors
1 parent c8df4b3 commit ce8fa2f

5 files changed

Lines changed: 38 additions & 16 deletions

File tree

src/Action/Api/WebhookEvent/AbstractPaymentAction.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public function execute($request): void
3030
RequestNotSupportedException::assertSupports($this, $request);
3131

3232
$eventWrapper = $request->getEventWrapper();
33+
// This should never be the case but phpstan don't know
34+
// about the tests made in the `supports()` method
35+
if (null === $eventWrapper) {
36+
return;
37+
}
3338
$event = $eventWrapper->getEvent();
3439

3540
/** @var Session|PaymentIntent|SetupIntent $sessionModeObject */

src/Action/CaptureAction.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Prometee\PayumStripe\Action;
66

77
use ArrayAccess;
8+
use LogicException;
89
use Payum\Core\Action\ActionInterface;
910
use Payum\Core\Bridge\Spl\ArrayObject;
10-
use Payum\Core\Exception\LogicException;
1111
use Payum\Core\Exception\RequestNotSupportedException;
1212
use Payum\Core\GatewayAwareInterface;
1313
use Payum\Core\GatewayAwareTrait;
@@ -36,7 +36,7 @@ public function execute($request): void
3636

3737
if (false === $model->offsetExists('id')) {
3838
// 0. Create another token to allow payment webhooks to use `Notify`
39-
$token = $request->getToken();
39+
$token = $this->getRequestToken($request);
4040
$notifyToken = $this->tokenFactory->createNotifyToken(
4141
$token->getGatewayName(),
4242
$token->getDetails()
@@ -144,4 +144,20 @@ protected function detectModeData(ArrayObject $model): string
144144

145145
return 'payment_intent_data';
146146
}
147+
148+
/**
149+
* @param Capture $request
150+
*
151+
* @return TokenInterface
152+
*/
153+
private function getRequestToken(Capture $request): TokenInterface
154+
{
155+
$token = $request->getToken();
156+
157+
if (null === $token) {
158+
throw new LogicException('The request token should not be null !');
159+
}
160+
161+
return $token;
162+
}
147163
}

src/Request/Api/ConstructEvent.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,42 @@
44

55
namespace Prometee\PayumStripe\Request\Api;
66

7+
use LogicException;
78
use Payum\Core\Request\Generic;
89
use Prometee\PayumStripe\Wrapper\EventWrapperInterface;
910

1011
class ConstructEvent extends Generic
1112
{
12-
/** @var null|string */
13+
/** @var string */
1314
private $webhookSecretKey;
1415
/** @var string */
1516
private $sigHeader;
1617

1718
/**
1819
* @param string $payload
1920
* @param string $sigHeader
20-
* @param string|null $webhookSecretKey
21+
* @param string $webhookSecretKey
2122
*/
2223
public function __construct(
2324
string $payload,
2425
string $sigHeader,
25-
string $webhookSecretKey = null
26+
string $webhookSecretKey
2627
) {
2728
parent::__construct($payload);
2829
$this->sigHeader = $sigHeader;
2930
$this->webhookSecretKey = $webhookSecretKey;
3031
}
3132

3233
/**
33-
* @return string|null
34+
* @return string
3435
*/
35-
public function getPayload(): ?string
36+
public function getPayload(): string
3637
{
3738
if (is_string($this->getModel())) {
3839
return (string) $this->getModel();
3940
}
4041

41-
return null;
42+
throw new LogicException('The payload is not a string !');
4243
}
4344

4445
public function setPayload(string $payload): void
@@ -47,17 +48,17 @@ public function setPayload(string $payload): void
4748
}
4849

4950
/**
50-
* @param string|null $webhookSecretKey
51+
* @param string $webhookSecretKey
5152
*/
52-
public function setWebhookSecretKey(?string $webhookSecretKey): void
53+
public function setWebhookSecretKey(string $webhookSecretKey): void
5354
{
5455
$this->webhookSecretKey = $webhookSecretKey;
5556
}
5657

5758
/**
58-
* @return string|null
59+
* @return string
5960
*/
60-
public function getWebhookSecretKey(): ?string
61+
public function getWebhookSecretKey(): string
6162
{
6263
return $this->webhookSecretKey;
6364
}

tests/Action/Api/ConstructEventActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function shouldThrowExceptionWhenInvalidPayloadIsRequested()
3131
{
3232
$payload = '';
3333
$sigHeader = '';
34-
$webhookSecretKey = null;
34+
$webhookSecretKey = '';
3535

3636
$action = new ConstructEventAction();
3737

tests/Request/Api/ConstructEventTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class ConstructEventTest extends TestCase
1515
*/
1616
public function shouldBeSubClassOfGeneric()
1717
{
18-
$constructEvent = new ConstructEvent('', '');
18+
$constructEvent = new ConstructEvent('', '', '');
1919

2020
$this->assertInstanceOf(Generic::class, $constructEvent);
2121
}
@@ -24,9 +24,9 @@ public function testSetWebhookSecretKey()
2424
{
2525
$constructEvent = new ConstructEvent('', '', '');
2626

27-
$constructEvent->setWebhookSecretKey(null);
27+
$constructEvent->setWebhookSecretKey('my_whsec');
2828

29-
$this->assertEquals(null, $constructEvent->getWebhookSecretKey());
29+
$this->assertEquals('my_whsec', $constructEvent->getWebhookSecretKey());
3030
}
3131

3232
public function testGetWebhookSecretKey()

0 commit comments

Comments
 (0)