Strikewood /
omnipay-first-atlantic-commerce
| Conditions | 2 |
| Paths | 2 |
| Total Lines | 4 |
| Code Lines | 2 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| Metric | Value |
|---|---|
| c | 1 |
| b | 0 |
| f | 0 |
| dl | 0 |
| loc | 4 |
| rs | 10 |
| cc | 2 |
| eloc | 2 |
| nc | 2 |
| nop | 0 |
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Omnipay\FirstAtlanticCommerce\Message; |
||
| 4 | |||
| 5 | use Omnipay\Common\Exception\InvalidResponseException; |
||
| 6 | use Omnipay\Common\Message\RequestInterface; |
||
| 7 | use Omnipay\FirstAtlanticCommerce\Message\AbstractResponse; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * FACPG2 XML Authorize Response |
||
| 11 | */ |
||
| 12 | class AuthorizeResponse extends AbstractResponse |
||
| 13 | { |
||
| 14 | /** |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 15 | * Constructor |
||
|
0 ignored issues
–
show
|
|||
| 16 | * |
||
|
0 ignored issues
–
show
|
|||
| 17 | * @param RequestInterface $request |
||
|
0 ignored issues
–
show
|
|||
| 18 | * @param string $data |
||
|
0 ignored issues
–
show
|
|||
| 19 | */ |
||
|
0 ignored issues
–
show
|
|||
| 20 | public function __construct(RequestInterface $request, $data) |
||
|
0 ignored issues
–
show
|
|||
| 21 | { |
||
|
0 ignored issues
–
show
|
|||
| 22 | if ( empty($data) ) |
||
|
0 ignored issues
–
show
|
|||
| 23 | { |
||
|
0 ignored issues
–
show
|
|||
| 24 | throw new InvalidResponseException(); |
||
|
0 ignored issues
–
show
|
|||
| 25 | } |
||
|
0 ignored issues
–
show
|
|||
| 26 | |||
| 27 | $this->request = $request; |
||
|
0 ignored issues
–
show
|
|||
| 28 | $this->data = $this->xmlDeserialize($data); |
||
|
0 ignored issues
–
show
$data is of type string, but the function expects a object<SimpleXMLElement>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 29 | |||
| 30 | $this->verifySignature(); |
||
|
0 ignored issues
–
show
|
|||
| 31 | } |
||
|
0 ignored issues
–
show
|
|||
| 32 | |||
| 33 | /** |
||
|
0 ignored issues
–
show
|
|||
| 34 | * Verifies the signature for the response. |
||
|
0 ignored issues
–
show
|
|||
| 35 | * |
||
|
0 ignored issues
–
show
|
|||
| 36 | * @throws InvalidResponseException if the signature doesn't match |
||
|
0 ignored issues
–
show
|
|||
| 37 | * |
||
|
0 ignored issues
–
show
|
|||
| 38 | * @return void |
||
|
0 ignored issues
–
show
|
|||
| 39 | */ |
||
|
0 ignored issues
–
show
|
|||
| 40 | public function verifySignature() |
||
|
0 ignored issues
–
show
|
|||
| 41 | { |
||
|
0 ignored issues
–
show
|
|||
| 42 | if ( isset($this->data['CreditCardTransactionResults']['ResponseCode']) && ( |
||
|
0 ignored issues
–
show
|
|||
| 43 | '1' == $this->data['CreditCardTransactionResults']['ResponseCode'] || |
||
|
0 ignored issues
–
show
|
|||
| 44 | '2' == $this->data['CreditCardTransactionResults']['ResponseCode']) ) |
||
|
0 ignored issues
–
show
|
|||
| 45 | { |
||
|
0 ignored issues
–
show
|
|||
| 46 | $signature = $this->request->getMerchantPassword(); |
||
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Omnipay\Common\Message\RequestInterface as the method getMerchantPassword() does only exist in the following implementations of said interface: Omnipay\FirstAtlanticCom...Message\AbstractRequest, Omnipay\FirstAtlanticCom...essage\AuthorizeRequest, Omnipay\FirstAtlanticCom...\Message\CaptureRequest, Omnipay\FirstAtlanticCom...ssage\CreateCardRequest, Omnipay\FirstAtlanticCom...Message\PurchaseRequest, Omnipay\FirstAtlanticCom...e\Message\RefundRequest, Omnipay\FirstAtlanticCom...e\Message\StatusRequest, Omnipay\FirstAtlanticCom...tionModificationRequest, Omnipay\FirstAtlanticCom...ssage\UpdateCardRequest, Omnipay\FirstAtlanticCommerce\Message\VoidRequest.
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 47 | $signature .= $this->request->getMerchantId(); |
||
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Omnipay\Common\Message\RequestInterface as the method getMerchantId() does only exist in the following implementations of said interface: Omnipay\FirstAtlanticCom...Message\AbstractRequest, Omnipay\FirstAtlanticCom...essage\AuthorizeRequest, Omnipay\FirstAtlanticCom...\Message\CaptureRequest, Omnipay\FirstAtlanticCom...ssage\CreateCardRequest, Omnipay\FirstAtlanticCom...Message\PurchaseRequest, Omnipay\FirstAtlanticCom...e\Message\RefundRequest, Omnipay\FirstAtlanticCom...e\Message\StatusRequest, Omnipay\FirstAtlanticCom...tionModificationRequest, Omnipay\FirstAtlanticCom...ssage\UpdateCardRequest, Omnipay\FirstAtlanticCommerce\Message\VoidRequest.
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 48 | $signature .= $this->request->getAcquirerId(); |
||
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Omnipay\Common\Message\RequestInterface as the method getAcquirerId() does only exist in the following implementations of said interface: Omnipay\FirstAtlanticCom...Message\AbstractRequest, Omnipay\FirstAtlanticCom...essage\AuthorizeRequest, Omnipay\FirstAtlanticCom...\Message\CaptureRequest, Omnipay\FirstAtlanticCom...ssage\CreateCardRequest, Omnipay\FirstAtlanticCom...Message\PurchaseRequest, Omnipay\FirstAtlanticCom...e\Message\RefundRequest, Omnipay\FirstAtlanticCom...e\Message\StatusRequest, Omnipay\FirstAtlanticCom...tionModificationRequest, Omnipay\FirstAtlanticCom...ssage\UpdateCardRequest, Omnipay\FirstAtlanticCommerce\Message\VoidRequest.
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 49 | $signature .= $this->request->getTransactionId(); |
||
|
0 ignored issues
–
show
|
|||
| 50 | |||
| 51 | $signature = base64_encode( sha1($signature, true) ); |
||
|
0 ignored issues
–
show
|
|||
| 52 | |||
| 53 | if ( $signature !== $this->data['Signature'] ) { |
||
|
0 ignored issues
–
show
|
|||
| 54 | throw new InvalidResponseException('Signature verification failed'); |
||
|
0 ignored issues
–
show
|
|||
| 55 | } |
||
|
0 ignored issues
–
show
|
|||
| 56 | } |
||
|
0 ignored issues
–
show
|
|||
| 57 | } |
||
|
0 ignored issues
–
show
|
|||
| 58 | |||
| 59 | /** |
||
|
0 ignored issues
–
show
|
|||
| 60 | * Return whether or not the response was successful |
||
|
0 ignored issues
–
show
|
|||
| 61 | * |
||
|
0 ignored issues
–
show
|
|||
| 62 | * @return boolean |
||
|
0 ignored issues
–
show
|
|||
| 63 | */ |
||
|
0 ignored issues
–
show
|
|||
| 64 | public function isSuccessful() |
||
|
0 ignored issues
–
show
|
|||
| 65 | { |
||
|
0 ignored issues
–
show
|
|||
| 66 | return isset($this->data['CreditCardTransactionResults']['ResponseCode']) && '1' === $this->data['CreditCardTransactionResults']['ResponseCode']; |
||
|
0 ignored issues
–
show
|
|||
| 67 | } |
||
|
0 ignored issues
–
show
|
|||
| 68 | |||
| 69 | /** |
||
|
0 ignored issues
–
show
|
|||
| 70 | * Return the response's reason code |
||
|
0 ignored issues
–
show
|
|||
| 71 | * |
||
|
0 ignored issues
–
show
|
|||
| 72 | * @return string |
||
|
0 ignored issues
–
show
|
|||
| 73 | */ |
||
|
0 ignored issues
–
show
|
|||
| 74 | public function getCode() |
||
|
0 ignored issues
–
show
|
|||
| 75 | { |
||
|
0 ignored issues
–
show
|
|||
| 76 | return isset($this->data['CreditCardTransactionResults']['ReasonCode']) ? $this->data['CreditCardTransactionResults']['ReasonCode'] : null; |
||
|
0 ignored issues
–
show
|
|||
| 77 | } |
||
|
0 ignored issues
–
show
|
|||
| 78 | |||
| 79 | /** |
||
|
0 ignored issues
–
show
|
|||
| 80 | * Return the response's reason message |
||
|
0 ignored issues
–
show
|
|||
| 81 | * |
||
|
0 ignored issues
–
show
|
|||
| 82 | * @return string |
||
|
0 ignored issues
–
show
|
|||
| 83 | */ |
||
|
0 ignored issues
–
show
|
|||
| 84 | public function getMessage() |
||
|
0 ignored issues
–
show
|
|||
| 85 | { |
||
|
0 ignored issues
–
show
|
|||
| 86 | return isset($this->data['CreditCardTransactionResults']['ReasonCodeDescription']) ? $this->data['CreditCardTransactionResults']['ReasonCodeDescription'] : null; |
||
|
0 ignored issues
–
show
|
|||
| 87 | } |
||
|
0 ignored issues
–
show
|
|||
| 88 | |||
| 89 | /** |
||
|
0 ignored issues
–
show
|
|||
| 90 | * Return transaction reference |
||
|
0 ignored issues
–
show
|
|||
| 91 | * |
||
|
0 ignored issues
–
show
|
|||
| 92 | * @return string |
||
|
0 ignored issues
–
show
|
|||
| 93 | */ |
||
|
0 ignored issues
–
show
|
|||
| 94 | public function getTransactionReference() |
||
|
0 ignored issues
–
show
|
|||
| 95 | { |
||
|
0 ignored issues
–
show
|
|||
| 96 | return isset($this->data['CreditCardTransactionResults']['ReferenceNumber']) ? $this->data['CreditCardTransactionResults']['ReferenceNumber'] : null; |
||
|
0 ignored issues
–
show
|
|||
| 97 | } |
||
|
0 ignored issues
–
show
|
|||
| 98 | } |
||
| 99 |