diff --git a/psalm.xml b/psalm.xml index cf33380..b099f1b 100644 --- a/psalm.xml +++ b/psalm.xml @@ -28,6 +28,7 @@ + diff --git a/src/CreditCard.php b/src/CreditCard.php index ccf905b..5552d37 100644 --- a/src/CreditCard.php +++ b/src/CreditCard.php @@ -10,7 +10,6 @@ class CreditCard extends \Omnipay\Common\CreditCard /** * Gets the card brand. Returns the brand that was set if one was set, * otherwise determines the brand from the card number. - * * @return string|null */ public function getBrand() diff --git a/src/ExtendedGateway.php b/src/ExtendedGateway.php index a3da322..25006ee 100644 --- a/src/ExtendedGateway.php +++ b/src/ExtendedGateway.php @@ -77,13 +77,13 @@ public function fetchSubscription(array $parameters = array()) * parameters passed. * * @param array $parameters - * @return \Omnipay\BlueSnap\Message\AbstractRequest + * @return \Omnipay\BlueSnap\Message\FetchSubscriptionsRequest */ public function fetchSubscriptions(array $parameters = array()) { if (isset($parameters['customerReference'])) { /** - * @var \Omnipay\BlueSnap\Message\AbstractRequest + * @var \Omnipay\BlueSnap\Message\FetchSubscriptionsRequest */ return $this->createRequest( '\Omnipay\BlueSnap\Message\ExtendedFetchSubscriptionsRequest', diff --git a/src/Message/Response.php b/src/Message/Response.php index 993ff68..76f7cf8 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -106,8 +106,9 @@ public function getMessage() if ($this->data instanceof SimpleXMLElement && isset($this->data->message->description)) { return (string) $this->data->message->description; } - // some error responses are plain text instead of XML - return (string) $this->data; + if (is_string($this->data)) { + return $this->data; + } // some error responses are plain text instead of XML } return null; @@ -391,7 +392,7 @@ public function getNextChargeDate() */ public function getTransactions() { - if (!isset($this->data['data'])) { + if (!is_array($this->data) || !isset($this->data['data'])) { return null; } $transactions = array(); diff --git a/tests/Framework/DataFaker.php b/tests/Framework/DataFaker.php index df19966..65f8795 100644 --- a/tests/Framework/DataFaker.php +++ b/tests/Framework/DataFaker.php @@ -282,7 +282,7 @@ public function password() public function customerReference() { do { - $result = $this->randomCharacters(self::DIGITS, $this->intBetween(6, 10)); + $result = $this->randomCharacters(self::DIGITS, $this->intBetween(6, 9)); } while ($result == 0); return $result; } @@ -295,7 +295,7 @@ public function customerReference() public function transactionReference() { do { - $result = $this->randomCharacters(self::DIGITS, $this->intBetween(6, 10)); + $result = $this->randomCharacters(self::DIGITS, $this->intBetween(6, 9)); } while ($result == 0); return $result; } @@ -308,7 +308,7 @@ public function transactionReference() public function subscriptionReference() { do { - $result = $this->randomCharacters(self::DIGITS, $this->intBetween(6, 10)); + $result = $this->randomCharacters(self::DIGITS, $this->intBetween(6, 9)); } while ($result == 0); return $result; } @@ -321,7 +321,7 @@ public function subscriptionReference() public function subscriptionChargeReference() { do { - $result = $this->randomCharacters(self::DIGITS, $this->intBetween(3, 10)); + $result = $this->randomCharacters(self::DIGITS, $this->intBetween(3, 9)); } while ($result == 0); return $result; } @@ -347,7 +347,7 @@ public function storeReference() public function planReference() { do { - $result = $this->randomCharacters(self::DIGITS, $this->intBetween(6, 10)); + $result = $this->randomCharacters(self::DIGITS, $this->intBetween(6, 9)); } while ($result == 0); return $result; } diff --git a/tests/Framework/TestCase.php b/tests/Framework/TestCase.php index dc395c3..d02f9ad 100644 --- a/tests/Framework/TestCase.php +++ b/tests/Framework/TestCase.php @@ -85,7 +85,7 @@ public function getMockHttpResponse($path, $substitutions = array()) * then the function will replace all instances of '[NAME]' in the * response with 'Fake Name'. Substitutions are not required. * - * @param array|string $paths + * @param array|string $paths * @param array $substitutions * * @return MockPlugin @@ -95,8 +95,12 @@ public function setMockHttpResponse($paths, $substitutions = array()) $this->substitutableMockHttpRequests = array(); $that = $this; $mock = new MockPlugin(null, true); - $this->getHttpClient()->getEventDispatcher()->removeSubscriber($mock); - $mock->getEventDispatcher()->addListener( + /** @var \Symfony\Component\EventDispatcher\EventDispatcher */ + $event_dispatcher = $this->getHttpClient()->getEventDispatcher(); + $event_dispatcher->removeSubscriber($mock); + /** @var \Symfony\Component\EventDispatcher\EventDispatcher */ + $mock_event_dispatcher = $mock->getEventDispatcher(); + $mock_event_dispatcher->addListener( 'mock.request', // @codingStandardsIgnoreStart /** @@ -120,7 +124,7 @@ function (Event $event) use ($that) { $mock->addResponse($this->getMockHttpResponse($path, $substitutions) ?: ''); } - $this->getHttpClient()->getEventDispatcher()->addSubscriber($mock); + $event_dispatcher->addSubscriber($mock); return $mock; } diff --git a/tests/Message/ExtendedFetchSubscriptionsRequestTest.php b/tests/Message/ExtendedFetchSubscriptionsRequestTest.php index f4cbd95..0777e30 100644 --- a/tests/Message/ExtendedFetchSubscriptionsRequestTest.php +++ b/tests/Message/ExtendedFetchSubscriptionsRequestTest.php @@ -116,7 +116,7 @@ public function testSendSuccess() $this->assertFalse($response->isRedirect()); $this->assertSame('200', $response->getCode()); $subscriptions = $response->getSubscriptions(); - $this->assertSame(2, count($subscriptions)); + $this->assertCount(2, $subscriptions); if ($subscriptions) { foreach ($subscriptions as $i => $subscription) { $fakeSubscription = $fakeSubscriptions[intval($i) + 1]; diff --git a/tests/Message/ExtendedFetchTransactionRequestTest.php b/tests/Message/ExtendedFetchTransactionRequestTest.php index a3bbd82..58b27cf 100644 --- a/tests/Message/ExtendedFetchTransactionRequestTest.php +++ b/tests/Message/ExtendedFetchTransactionRequestTest.php @@ -88,8 +88,8 @@ public function testSendSuccess() $fakeCard = $this->faker->card(); $cardBrand = $fakeCard->getBrand(); $cardLastFour = $fakeCard->getNumberLastFour(); - $expiryMonth = $fakeCard->getExpiryMonth(); - $expiryYear = $fakeCard->getExpiryYear(); + $expiryMonth = (string) $fakeCard->getExpiryMonth(); + $expiryYear = (string) $fakeCard->getExpiryYear(); $firstName = $fakeCard->getFirstName(); $lastName = $fakeCard->getLastName(); $email = $fakeCard->getEmail(); @@ -152,8 +152,8 @@ public function testSendSuccess() } $this->assertSame($cardLastFour, $card->getNumberLastFour()); $this->assertSame($cardBrand, $card->getBrand()); - $this->assertSame($expiryMonth, $card->getExpiryMonth()); - $this->assertSame($expiryYear, $card->getExpiryYear()); + $this->assertSame($expiryMonth, (string) $card->getExpiryMonth()); + $this->assertSame($expiryYear, (string) $card->getExpiryYear()); $this->assertSame($firstName, $card->getFirstName()); $this->assertSame($lastName, $card->getLastName()); $this->assertSame($email, $card->getEmail()); diff --git a/tests/Message/FetchCanceledSubscriptionsRequestTest.php b/tests/Message/FetchCanceledSubscriptionsRequestTest.php index 539fe32..58a76fe 100644 --- a/tests/Message/FetchCanceledSubscriptionsRequestTest.php +++ b/tests/Message/FetchCanceledSubscriptionsRequestTest.php @@ -201,7 +201,7 @@ public function testSendSuccess() $this->assertFalse($response->isRedirect()); $this->assertSame('200', $response->getCode()); $subscriptions = $response->getSubscriptions(); - $this->assertSame(2, count($subscriptions)); + $this->assertCount(2, $subscriptions); if ($subscriptions) { foreach ($subscriptions as $i => $subscription) { $fakeSubscription = $fakeSubscriptions[intval($i) + 1]; diff --git a/tests/Message/FetchSubscriptionsRequestTest.php b/tests/Message/FetchSubscriptionsRequestTest.php index 8bbf2d7..ce1c12a 100644 --- a/tests/Message/FetchSubscriptionsRequestTest.php +++ b/tests/Message/FetchSubscriptionsRequestTest.php @@ -158,7 +158,7 @@ public function testSendSuccess() $this->assertFalse($response->isRedirect()); $this->assertSame('200', $response->getCode()); $subscriptions = $response->getSubscriptions(); - $this->assertSame(2, count($subscriptions)); + $this->assertCount(2, $subscriptions); if ($subscriptions) { foreach ($subscriptions as $i => $subscription) { $fakeSubscription = $fakeSubscriptions[intval($i) + 1]; diff --git a/tests/Message/FetchTransactionsRequestTest.php b/tests/Message/FetchTransactionsRequestTest.php index 72aaed1..a374fe8 100644 --- a/tests/Message/FetchTransactionsRequestTest.php +++ b/tests/Message/FetchTransactionsRequestTest.php @@ -161,7 +161,7 @@ public function testSendSuccess() $this->assertFalse($response->isRedirect()); $this->assertSame('200', $response->getCode()); $transactions = $response->getTransactions(); - $this->assertSame(2, count($transactions)); + $this->assertCount(2, $transactions); if ($transactions) { foreach ($transactions as $i => $transaction) { $fakeTransaction = $fakeTransactions[intval($i) + 1];