FSocket   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A remotePointer() 0 12 4
1
<?php
2
3
namespace kalanis\RemoteRequest\Sockets;
4
5
6
use kalanis\RemoteRequest\Interfaces\IConnectionParams;
7
use kalanis\RemoteRequest\RequestException;
8
9
10
/**
11
 * Class FSocket
12
 * @package kalanis\RemoteRequest\Sockets
13
 * Network pointer to the remote server - method Fsocket
14
 */
15
class FSocket extends ASocket
16
{
17
    /**
18
     * @param IConnectionParams $params
19
     * @throws RequestException
20
     * @return resource
21
     * @codeCoverageIgnore because accessing remote source
22
     */
23
    protected function remotePointer(IConnectionParams $params)
24
    {
25
        // Make the request to the server
26
        // If possible, securely post using HTTPS, your PHP server will need to be SSL enabled
27
        $timeout = is_null($params->getTimeout()) ? 10.0 : floatval($params->getTimeout()); // do NOT ask - php7 + phpstan
28
        if (!$filePointer = fsockopen($params->getSchema() . $params->getHost(), intval($params->getPort()), $errno, $errStr, $timeout)) {
29
            throw new RequestException($this->getRRLang()->rrSocketCannotConnect());
30
        }
31
        if (!is_null($params->getTimeout())) {
32
            stream_set_timeout($filePointer, intval($params->getTimeout()));
33
        }
34
        return $filePointer;
35
    }
36
}
37