Skip to content

Commit cc287dc

Browse files
authored
PhpStan: fix cUrl parameters (OpenMage#5036)
* PhpStan: fix cUrl parameters * PhpStan: DOCblock
1 parent 63fe741 commit cc287dc

File tree

10 files changed

+42
-90
lines changed

10 files changed

+42
-90
lines changed

.phpstan.dist.baseline.neon

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4926,12 +4926,6 @@ parameters:
49264926
count: 2
49274927
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php
49284928

4929-
-
4930-
rawMessage: 'Parameter #3 $value of function curl_setopt expects bool, int given.'
4931-
identifier: argument.type
4932-
count: 2
4933-
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php
4934-
49354929
-
49364930
rawMessage: 'Property Mage_Usa_Model_Shipping_Carrier_Dhl::$_request (Mage_Shipping_Model_Rate_Request|null) does not accept Varien_Object.'
49374931
identifier: assign.propertyType
@@ -5010,12 +5004,6 @@ parameters:
50105004
count: 1
50115005
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php
50125006

5013-
-
5014-
rawMessage: 'Parameter #3 $value of function curl_setopt expects bool, int given.'
5015-
identifier: argument.type
5016-
count: 2
5017-
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php
5018-
50195007
-
50205008
rawMessage: 'Property Mage_Usa_Model_Shipping_Carrier_Fedex::$_result (Mage_Shipping_Model_Rate_Result|null) does not accept Mage_Shipping_Model_Tracking_Result.'
50215009
identifier: assign.propertyType
@@ -5034,30 +5022,12 @@ parameters:
50345022
count: 1
50355023
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php
50365024

5037-
-
5038-
rawMessage: 'Parameter #1 $string of function strlen expects string, array|false given.'
5039-
identifier: argument.type
5040-
count: 1
5041-
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php
5042-
50435025
-
50445026
rawMessage: 'Parameter #2 $value of method SimpleXMLElement::addChild() expects string|null, float given.'
50455027
identifier: argument.type
50465028
count: 1
50475029
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php
50485030

5049-
-
5050-
rawMessage: 'Parameter #3 $value of function curl_setopt expects bool, int given.'
5051-
identifier: argument.type
5052-
count: 18
5053-
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php
5054-
5055-
-
5056-
rawMessage: 'Parameter #3 $value of function curl_setopt expects bool, int given.'
5057-
identifier: argument.type
5058-
count: 3
5059-
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/UpsAuth.php
5060-
50615031
-
50625032
rawMessage: 'Parameter #2 $serviceType of method Mage_Usa_Model_Shipping_Carrier_Usps::_formUsSignatureConfirmationShipmentRequest() expects string, array|bool given.'
50635033
identifier: argument.type
@@ -5988,18 +5958,6 @@ parameters:
59885958
count: 1
59895959
path: lib/Mage/DB/Mysqli.php
59905960

5991-
-
5992-
rawMessage: 'Parameter #1 $handle of function curl_setopt expects CurlHandle, resource|false given.'
5993-
identifier: argument.type
5994-
count: 1
5995-
path: lib/Mage/HTTP/Client/Curl.php
5996-
5997-
-
5998-
rawMessage: 'Parameter #1 $handle of function curl_setopt_array expects CurlHandle, resource|false given.'
5999-
identifier: argument.type
6000-
count: 1
6001-
path: lib/Mage/HTTP/Client/Curl.php
6002-
60035961
-
60045962
rawMessage: Empty array passed to foreach.
60055963
identifier: foreach.emptyArray
@@ -6276,12 +6234,6 @@ parameters:
62766234
count: 1
62776235
path: lib/Varien/Filter/Template/Tokenizer/Variable.php
62786236

6279-
-
6280-
rawMessage: 'Parameter #3 $value of function curl_setopt expects bool, int given.'
6281-
identifier: argument.type
6282-
count: 2
6283-
path: lib/Varien/Http/Adapter/Curl.php
6284-
62856237
-
62866238
rawMessage: 'Parameter #2 $enable of function imageinterlace expects bool|null, int given.'
62876239
identifier: argument.type

app/code/core/Mage/Centinel/Model/Api/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function sendHttp($url, $connectTimeout, $timeout)
3030
$ch = curl_init($url);
3131

3232
// set URL and other appropriate options
33-
curl_setopt($ch, CURLOPT_POST, 1);
33+
curl_setopt($ch, CURLOPT_POST, true);
3434
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
3535
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
36-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
37-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
36+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
37+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
3838
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
3939

4040
// Execute the request.

app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ protected function _doRequest()
539539
}
540540

541541
$ch = curl_init();
542-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
542+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
543543
curl_setopt($ch, CURLOPT_URL, $url);
544544
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->getConfigFlag('verify_peer'));
545545
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
@@ -1041,7 +1041,7 @@ protected function _getXMLTracking($trackings)
10411041
}
10421042

10431043
$ch = curl_init();
1044-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1044+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
10451045
curl_setopt($ch, CURLOPT_URL, $url);
10461046
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->getConfigFlag('verify_peer'));
10471047
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,9 @@ protected function _getXmlQuotes()
649649
}
650650

651651
$ch = curl_init();
652-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
652+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
653653
curl_setopt($ch, CURLOPT_URL, $url);
654-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
654+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
655655
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
656656
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
657657
$responseBody = curl_exec($ch);

app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ protected function _setFreeMethodRequest($freeMethod)
355355
*
356356
* @param string $code
357357
* @param string $origin
358-
* @return array|false
358+
* @return string|false
359359
*/
360360
public function getShipmentByCode($code, $origin = null)
361361
{
@@ -798,9 +798,9 @@ protected function _getXmlQuotes()
798798
$debugData = ['request' => $xmlRequest];
799799
$ch = curl_init();
800800
curl_setopt($ch, CURLOPT_URL, $url);
801-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
802-
curl_setopt($ch, CURLOPT_HEADER, 0);
803-
curl_setopt($ch, CURLOPT_POST, 1);
801+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
802+
curl_setopt($ch, CURLOPT_HEADER, false);
803+
curl_setopt($ch, CURLOPT_POST, true);
804804
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
805805
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
806806
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->getConfigFlag('verify_peer'));
@@ -1016,9 +1016,9 @@ protected function _getXmlTracking($trackings)
10161016

10171017
$ch = curl_init();
10181018
curl_setopt($ch, CURLOPT_URL, $url);
1019-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1020-
curl_setopt($ch, CURLOPT_HEADER, 0);
1021-
curl_setopt($ch, CURLOPT_POST, 1);
1019+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1020+
curl_setopt($ch, CURLOPT_HEADER, false);
1021+
curl_setopt($ch, CURLOPT_POST, true);
10221022
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
10231023
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
10241024
$xmlResponse = curl_exec($ch);
@@ -1592,9 +1592,9 @@ protected function _sendShipmentAcceptRequest(SimpleXMLElement $shipmentConfirmR
15921592
}
15931593

15941594
$ch = curl_init($url);
1595-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1596-
curl_setopt($ch, CURLOPT_HEADER, 0);
1597-
curl_setopt($ch, CURLOPT_POST, 1);
1595+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1596+
curl_setopt($ch, CURLOPT_HEADER, false);
1597+
curl_setopt($ch, CURLOPT_POST, true);
15981598
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_xmlAccessRequest . $xmlRequest->asXML());
15991599
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
16001600
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->getConfigFlag('verify_peer'));
@@ -1700,9 +1700,9 @@ protected function _doShipmentRequestRest(Varien_Object $request): Varien_Object
17001700

17011701
$ch = curl_init();
17021702
curl_setopt($ch, CURLOPT_URL, $shipConfirmUrl);
1703-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1704-
curl_setopt($ch, CURLOPT_HEADER, 0);
1705-
curl_setopt($ch, CURLOPT_POST, 1);
1703+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1704+
curl_setopt($ch, CURLOPT_HEADER, false);
1705+
curl_setopt($ch, CURLOPT_POST, true);
17061706
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
17071707
curl_setopt($ch, CURLOPT_POSTFIELDS, $rawJsonRequest);
17081708
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
@@ -2013,9 +2013,9 @@ protected function _doShipmentRequestXML(Varien_Object $request): Varien_Object
20132013
$debugData = ['request' => $xmlRequest];
20142014
$ch = curl_init();
20152015
curl_setopt($ch, CURLOPT_URL, $url);
2016-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
2017-
curl_setopt($ch, CURLOPT_HEADER, 0);
2018-
curl_setopt($ch, CURLOPT_POST, 1);
2016+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2017+
curl_setopt($ch, CURLOPT_HEADER, false);
2018+
curl_setopt($ch, CURLOPT_POST, true);
20192019
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
20202020
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
20212021
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->getConfigFlag('verify_peer'));
@@ -2342,9 +2342,9 @@ protected function _getRestQuotes()
23422342

23432343
$ch = curl_init();
23442344
curl_setopt($ch, CURLOPT_URL, $url . $version . '/' . $requestOption);
2345-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
2346-
curl_setopt($ch, CURLOPT_HEADER, 0);
2347-
curl_setopt($ch, CURLOPT_POST, 1);
2345+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2346+
curl_setopt($ch, CURLOPT_HEADER, false);
2347+
curl_setopt($ch, CURLOPT_POST, true);
23482348
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
23492349
curl_setopt($ch, CURLOPT_POSTFIELDS, $ratePayload);
23502350
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

app/code/core/Mage/Usa/Model/Shipping/Carrier/UpsAuth.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function getAccessToken(string $clientId, string $clientSecret, string $c
4242
]);
4343
$ch = curl_init();
4444
curl_setopt($ch, CURLOPT_URL, $clientUrl);
45-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
46-
curl_setopt($ch, CURLOPT_HEADER, 0);
47-
curl_setopt($ch, CURLOPT_POST, 1);
45+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
46+
curl_setopt($ch, CURLOPT_HEADER, false);
47+
curl_setopt($ch, CURLOPT_POST, true);
4848
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
4949
curl_setopt($ch, CURLOPT_POSTFIELDS, $authPayload);
5050
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

lib/3Dsecure/CentinelClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ public function sendHttp($url, $connectTimeout, $timeout)
9696
$ch = curl_init($url);
9797

9898
// set URL and other appropriate options
99-
curl_setopt($ch, CURLOPT_POST, 1);
99+
curl_setopt($ch, CURLOPT_POST, true);
100100
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
101101
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
102-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
102+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
103103
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
104104
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
105105

lib/Mage/HTTP/Client/Curl.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Mage_HTTP_Client_Curl implements Mage_HTTP_IClient
8282

8383
/**
8484
* Curl
85-
* @var false|resource
85+
* @var CurlHandle
8686
*/
8787
protected $_ch;
8888

@@ -129,8 +129,8 @@ public function setHeaders($headers)
129129
/**
130130
* Add header
131131
*
132-
* @param $name name, ex. "Location"
133-
* @param $value value ex. "http://google.com"
132+
* @param string $name name, ex. "Location"
133+
* @param string $value value ex. "http://google.com"
134134
*/
135135
public function addHeader($name, $value)
136136
{
@@ -362,7 +362,7 @@ protected function makeRequest($method, $uri, $params = [])
362362
$this->curlOption(CURLOPT_PORT, $this->_port);
363363
}
364364

365-
//$this->curlOption(CURLOPT_HEADER, 1);
365+
//$this->curlOption(CURLOPT_HEADER, true);
366366
$this->curlOption(CURLOPT_RETURNTRANSFER, 1);
367367
$this->curlOption(CURLOPT_HEADERFUNCTION, [$this,'parseHeaders']);
368368

@@ -480,8 +480,8 @@ public function setOptions($arr)
480480
/**
481481
* Set curl option
482482
*/
483-
public function setOption($name, $value)
483+
public function setOption($key, $value)
484484
{
485-
$this->_curlUserOptions[$name] = $value;
485+
$this->_curlUserOptions[$key] = $value;
486486
}
487487
}

lib/Mage/HTTP/Client/Socket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public function setHeaders($headers)
125125
/**
126126
* Add header
127127
*
128-
* @param $name name, ex. "Location"
129-
* @param $value value ex. "http://google.com"
128+
* @param string $name name, ex. "Location"
129+
* @param string $value value ex. "http://google.com"
130130
*/
131131
public function addHeader($name, $value)
132132
{

lib/Varien/Http/Adapter/Curl.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function _applyConfig()
6363
}
6464

6565
$verifyPeer = $this->_config['verifypeer'] ?? 0;
66-
curl_setopt($this->_getResource(), CURLOPT_SSL_VERIFYPEER, $verifyPeer);
66+
curl_setopt($this->_getResource(), CURLOPT_SSL_VERIFYPEER, (bool) $verifyPeer);
6767

6868
$verifyHost = $this->_config['verifyhost'] ?? 0;
6969
curl_setopt($this->_getResource(), CURLOPT_SSL_VERIFYHOST, $verifyHost);
@@ -288,8 +288,8 @@ public function multiRequest($urls, $options = [])
288288
foreach ($urls as $key => $url) {
289289
$handles[$key] = curl_init();
290290
curl_setopt($handles[$key], CURLOPT_URL, $url);
291-
curl_setopt($handles[$key], CURLOPT_HEADER, 0);
292-
curl_setopt($handles[$key], CURLOPT_RETURNTRANSFER, 1);
291+
curl_setopt($handles[$key], CURLOPT_HEADER, false);
292+
curl_setopt($handles[$key], CURLOPT_RETURNTRANSFER, true);
293293
if (!empty($options)) {
294294
curl_setopt_array($handles[$key], $options);
295295
}

0 commit comments

Comments
 (0)