Passed
Pull Request — master (#427)
by
unknown
03:22
created

CurlCli::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Helper\Connection;
28
29
/**
30
 * Helper class for connections with cli curl
31
 */
32
class CurlCli
33
{
34
    /**
35
     * @var \Magento\Framework\Shell
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Shell was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
     */
37
    protected $shell;
38
39
    /**
40
     * Constructor
41
     *
42
     * @param \Magento\Framework\Shell $shell
43
     */
44
    public function __construct(
45
        \Magento\Framework\Shell $shell
46
    ) {
47
        $this->shell = $shell;
48
    }
49
50
    /**
51
     * Determine if this connection type can be used on the given server
52
     *
53
     * @return bool
54
     */
55
    public function isApplicable()
56
    {
57
        if (file_exists("/usr/local/bin/curl") || file_exists("/usr/bin/curl")) {
58
            return true;
59
        }
60
        return false;
61
    }
62
63
    /**
64
     * Send cli Curl request
65
     *
66
     * @param  array $aParsedRequestUrl
67
     * @return array
68
     */
69
    public function sendCurlCliRequest($aParsedRequestUrl)
70
    {
71
        if (!$this->isApplicable()) {
72
            return ["errormessage" => "Cli-Curl is not applicable on this server."];
73
        }
74
75
        $sCurlPath = file_exists("/usr/local/bin/curl") ? "/usr/local/bin/curl" : "/usr/bin/curl";
76
77
        $sPostUrl = $aParsedRequestUrl['scheme']."://".$aParsedRequestUrl['host'].$aParsedRequestUrl['path'];
78
        $sPostData = $aParsedRequestUrl['query'];
79
80
        $sCommand = $sCurlPath." -m 45 -s -k -d \"".$sPostData."\" ".$sPostUrl;
81
82
        try {
83
            $sResponse = $this->shell->execute($sCommand);
84
            $aResponse = explode(PHP_EOL, $sResponse);
85
        } catch(\Exception $exc) {
86
            $aResponse = ["connection-type: 2 - errormessage=curl error(".$exc->getMessage().")"];
87
        }
88
        return $aResponse;
89
    }
90
}
91