Total Lines | 1 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Metric | Value |
---|---|
c | 2 |
b | 0 |
f | 0 |
dl | 0 |
loc | 1 |
nc | 1 |
1 | <?php |
||
2 | |||
3 | namespace Omnipay\FirstAtlanticCommerce\Message; |
||
4 | |||
5 | use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest; |
||
6 | use Omnipay\FirstAtlanticCommerce\CreditCard; |
||
7 | use Omnipay\FirstAtlanticCommerce\ParameterTrait; |
||
8 | use SimpleXMLElement; |
||
9 | |||
10 | abstract class AbstractRequest extends BaseAbstractRequest |
||
11 | { |
||
12 | use ParameterTrait; |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
13 | |||
14 | /** |
||
0 ignored issues
–
show
|
|||
15 | * FACPG2 live endpoint URL |
||
0 ignored issues
–
show
|
|||
16 | * |
||
0 ignored issues
–
show
|
|||
17 | * @var string |
||
0 ignored issues
–
show
|
|||
18 | */ |
||
0 ignored issues
–
show
|
|||
19 | protected $liveEndpoint = 'https://marlin.firstatlanticcommerce.com/PGServiceXML/'; |
||
0 ignored issues
–
show
|
|||
20 | |||
21 | /** |
||
0 ignored issues
–
show
|
|||
22 | * FACPG2 test endpoint URL |
||
0 ignored issues
–
show
|
|||
23 | * |
||
0 ignored issues
–
show
|
|||
24 | * @var string |
||
0 ignored issues
–
show
|
|||
25 | */ |
||
0 ignored issues
–
show
|
|||
26 | protected $testEndpoint = 'https://ecm.firstatlanticcommerce.com/PGServiceXML/'; |
||
0 ignored issues
–
show
|
|||
27 | |||
28 | /** |
||
0 ignored issues
–
show
|
|||
29 | * FACPG2 XML namespace |
||
0 ignored issues
–
show
|
|||
30 | * |
||
0 ignored issues
–
show
|
|||
31 | * @var string |
||
0 ignored issues
–
show
|
|||
32 | */ |
||
0 ignored issues
–
show
|
|||
33 | protected $namespace = 'http://schemas.firstatlanticcommerce.com/gateway/data'; |
||
0 ignored issues
–
show
|
|||
34 | |||
35 | /** |
||
0 ignored issues
–
show
|
|||
36 | * FACPG2 XML root |
||
0 ignored issues
–
show
|
|||
37 | * |
||
0 ignored issues
–
show
|
|||
38 | * @var string |
||
0 ignored issues
–
show
|
|||
39 | */ |
||
0 ignored issues
–
show
|
|||
40 | protected $requestName; |
||
0 ignored issues
–
show
|
|||
41 | |||
42 | /** |
||
0 ignored issues
–
show
|
|||
43 | * Returns the amount formatted to match FAC's expectations. |
||
0 ignored issues
–
show
|
|||
44 | * |
||
0 ignored issues
–
show
|
|||
45 | * @return string The amount padded with zeros on the left to 12 digits and no decimal place. |
||
0 ignored issues
–
show
|
|||
46 | */ |
||
0 ignored issues
–
show
|
|||
47 | protected function formatAmount() |
||
0 ignored issues
–
show
|
|||
48 | { |
||
0 ignored issues
–
show
|
|||
49 | $amount = $this->getAmount(); |
||
0 ignored issues
–
show
|
|||
50 | |||
51 | $amount = str_replace('.', '', $amount); |
||
0 ignored issues
–
show
|
|||
52 | $amount = str_pad($amount, 12, '0', STR_PAD_LEFT); |
||
0 ignored issues
–
show
|
|||
53 | |||
54 | return $amount; |
||
0 ignored issues
–
show
|
|||
55 | } |
||
0 ignored issues
–
show
|
|||
56 | |||
57 | /** |
||
0 ignored issues
–
show
|
|||
58 | * Returns the live or test endpoint depending on TestMode. |
||
0 ignored issues
–
show
|
|||
59 | * |
||
0 ignored issues
–
show
|
|||
60 | * @return string Endpoint URL |
||
0 ignored issues
–
show
|
|||
61 | */ |
||
0 ignored issues
–
show
|
|||
62 | protected function getEndpoint() |
||
0 ignored issues
–
show
|
|||
63 | { |
||
0 ignored issues
–
show
|
|||
64 | return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; |
||
0 ignored issues
–
show
|
|||
65 | } |
||
0 ignored issues
–
show
|
|||
66 | |||
67 | /** |
||
0 ignored issues
–
show
|
|||
68 | * Return the response object |
||
0 ignored issues
–
show
|
|||
69 | * |
||
0 ignored issues
–
show
|
|||
70 | * @param \SimpleXMLElement $xml Response xml object |
||
0 ignored issues
–
show
|
|||
71 | * |
||
0 ignored issues
–
show
|
|||
72 | * @return ResponseInterface |
||
0 ignored issues
–
show
|
|||
73 | */ |
||
0 ignored issues
–
show
|
|||
74 | abstract protected function newResponse($xml); |
||
0 ignored issues
–
show
|
|||
75 | |||
76 | /** |
||
0 ignored issues
–
show
|
|||
77 | * Send the request payload |
||
0 ignored issues
–
show
|
|||
78 | * |
||
0 ignored issues
–
show
|
|||
79 | * @param array $data Request payload |
||
0 ignored issues
–
show
|
|||
80 | * |
||
0 ignored issues
–
show
|
|||
81 | * @return ResponseInterface |
||
0 ignored issues
–
show
|
|||
82 | */ |
||
0 ignored issues
–
show
|
|||
83 | public function sendData($data) |
||
0 ignored issues
–
show
|
|||
84 | { |
||
0 ignored issues
–
show
|
|||
85 | $httpResponse = $this->httpClient->post( |
||
0 ignored issues
–
show
|
|||
86 | $this->getEndpoint(), |
||
0 ignored issues
–
show
|
|||
87 | ['Content-Type' => 'text/xml; charset=utf-8'], |
||
0 ignored issues
–
show
|
|||
88 | $this->xmlSerialize($data) |
||
0 ignored issues
–
show
It seems like
$this->xmlSerialize($data) targeting Omnipay\FirstAtlanticCom...Request::xmlSerialize() can also be of type false ; however, Guzzle\Http\ClientInterface::post() does only seem to accept array|object<Guzzle\Comm...tityBodyInterface>|null , did you maybe forget to handle an error condition?
![]() |
|||
89 | )->send(); |
||
0 ignored issues
–
show
|
|||
90 | |||
91 | return $this->response = $this->newResponse( $httpResponse->xml() ); |
||
0 ignored issues
–
show
It seems like
$this->newResponse($httpResponse->xml()) of type object<Omnipay\FirstAtla...sage\ResponseInterface> is incompatible with the declared type object<Omnipay\Common\Message\ResponseInterface> of property $response .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() The return type of
return $this->response =...($httpResponse->xml()); (Omnipay\FirstAtlanticCom...ssage\ResponseInterface ) is incompatible with the return type declared by the interface Omnipay\Common\Message\RequestInterface::sendData of type Omnipay\Common\Message\ResponseInterface .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
92 | } |
||
0 ignored issues
–
show
|
|||
93 | |||
94 | /** |
||
0 ignored issues
–
show
|
|||
95 | * Serializes an array into XML |
||
0 ignored issues
–
show
|
|||
96 | * |
||
0 ignored issues
–
show
|
|||
97 | * @param array $data Array to serialize into XML. |
||
0 ignored issues
–
show
|
|||
98 | * @param \SimpleXMLElement $xml SimpleXMLElement object. |
||
0 ignored issues
–
show
Should the type for parameter
$xml not be SimpleXMLElement|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
99 | * |
||
0 ignored issues
–
show
|
|||
100 | * @return string XML |
||
0 ignored issues
–
show
|
|||
101 | */ |
||
0 ignored issues
–
show
|
|||
102 | protected function xmlSerialize($data, $xml = null) |
||
0 ignored issues
–
show
|
|||
103 | { |
||
0 ignored issues
–
show
|
|||
104 | if ( !$xml instanceof SimpleXMLElement ) |
||
0 ignored issues
–
show
|
|||
105 | { |
||
0 ignored issues
–
show
|
|||
106 | $xml = new SimpleXMLElement('<'. $this->requestName .' xmlns="'. $this->namespace .'" />'); |
||
0 ignored issues
–
show
|
|||
107 | } |
||
0 ignored issues
–
show
|
|||
108 | |||
109 | foreach ($data as $key => $value) |
||
0 ignored issues
–
show
|
|||
110 | { |
||
0 ignored issues
–
show
|
|||
111 | if ( !isset($value) ) |
||
0 ignored issues
–
show
|
|||
112 | { |
||
0 ignored issues
–
show
|
|||
113 | continue; |
||
0 ignored issues
–
show
|
|||
114 | } |
||
0 ignored issues
–
show
|
|||
115 | |||
116 | if ( is_array($value) ) |
||
0 ignored issues
–
show
|
|||
117 | { |
||
0 ignored issues
–
show
|
|||
118 | $node = $xml->addChild($key); |
||
0 ignored issues
–
show
|
|||
119 | $this->xmlSerialize($value, $node); |
||
0 ignored issues
–
show
|
|||
120 | } |
||
0 ignored issues
–
show
|
|||
121 | else |
||
0 ignored issues
–
show
|
|||
122 | { |
||
0 ignored issues
–
show
|
|||
123 | $xml->addChild($key, $value); |
||
0 ignored issues
–
show
|
|||
124 | } |
||
0 ignored issues
–
show
|
|||
125 | } |
||
0 ignored issues
–
show
|
|||
126 | |||
127 | return $xml->asXML(); |
||
0 ignored issues
–
show
|
|||
128 | } |
||
0 ignored issues
–
show
|
|||
129 | |||
130 | /** |
||
0 ignored issues
–
show
|
|||
131 | * Sets the card. |
||
0 ignored issues
–
show
|
|||
132 | * |
||
0 ignored issues
–
show
|
|||
133 | * @param CreditCard $value |
||
0 ignored issues
–
show
|
|||
134 | * |
||
0 ignored issues
–
show
|
|||
135 | * @return AbstractRequest Provides a fluent interface |
||
0 ignored issues
–
show
|
|||
136 | */ |
||
0 ignored issues
–
show
|
|||
137 | public function setCard($value) |
||
0 ignored issues
–
show
|
|||
138 | { |
||
0 ignored issues
–
show
|
|||
139 | if ($value && !$value instanceof CreditCard) |
||
0 ignored issues
–
show
|
|||
140 | { |
||
0 ignored issues
–
show
|
|||
141 | $value = new CreditCard($value); |
||
0 ignored issues
–
show
|
|||
142 | } |
||
0 ignored issues
–
show
|
|||
143 | |||
144 | return $this->setParameter('card', $value); |
||
0 ignored issues
–
show
|
|||
145 | } |
||
0 ignored issues
–
show
|
|||
146 | } |
||
147 |