AOperations   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parsePath() 0 17 6
1
<?php
2
3
namespace kalanis\RemoteRequest\Wrappers\Fsp;
4
5
6
use kalanis\RemoteRequest\Interfaces\IRRTranslations;
7
use kalanis\RemoteRequest\RequestException;
8
use kalanis\RemoteRequest\Traits\TLang;
9
10
11
/**
12
 * Class AOperations
13
 * @package kalanis\RemoteRequest\Wrappers\Fsp
14
 * Wrapper to plug FSP info into PHP - directory part
15
 */
16
class AOperations
17
{
18
    use TLang;
19
20
    protected Runner $runner;
21
22
    public function __construct(Runner $runner, IRRTranslations $lang)
23
    {
24
        $this->setRRLang($lang);
25
        $this->runner = $runner;
26
    }
27
28
    /**
29
     * @param string $path
30
     * @param bool $setTarget
31
     * @throws RequestException
32
     * @return string
33
     */
34
    protected function parsePath(string $path, bool $setTarget = true): string
35
    {
36
        $host = parse_url($path, PHP_URL_HOST);
37
        $port = parse_url($path, PHP_URL_PORT);
38
        $into = parse_url($path, PHP_URL_PATH);
39
        if (empty($host) || empty($into)) {
40
            throw new RequestException($this->getRRLang()->rrFspWrapMalformedPath($path));
41
        }
42
        if ($setTarget) {
43
            $this->runner->getConnectParams()->setTarget(
44
                $host,
45
                !empty($port) ? intval($port) : 21,
46
                $this->runner->getTimeout($host)
47
            );
48
        }
49
        $pre = (in_array($into[0], ['.', '\\'])) ? substr($into, 1) : $into ;
50
        return $pre;
51
    }
52
}
53