Passed
Push — master ( 73f345...78312e )
by Radu
01:42
created

RequestUrlTrait::getShortUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace WebServCo\Framework\Traits;
3
4
trait RequestUrlTrait
5
{
6
    public function getAppUrl()
7
    {
8
        if (\WebServCo\Framework\Framework::isCLI()) {
9
            return false;
10
        }
11
        return $this->getSchema() .
0 ignored issues
show
Bug introduced by
It seems like getSchema() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

11
        return $this->/** @scrutinizer ignore-call */ getSchema() .
Loading history...
12
        '://' .
13
        $this->getHost() .
0 ignored issues
show
Bug introduced by
It seems like getHost() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
        $this->/** @scrutinizer ignore-call */ 
14
               getHost() .
Loading history...
14
        $this->path .
0 ignored issues
show
Bug Best Practice introduced by
The property path does not exist on WebServCo\Framework\Traits\RequestUrlTrait. Did you maybe forget to declare it?
Loading history...
15
        DIRECTORY_SEPARATOR;
16
    }
17
    
18
    public function getShortUrl()
19
    {
20
        $url = $this->getAppUrl();
21
        $url .= $this->getTarget();
0 ignored issues
show
Bug introduced by
It seems like getTarget() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        $url .= $this->/** @scrutinizer ignore-call */ getTarget();
Loading history...
22
        $url .= $this->getSuffix();
0 ignored issues
show
Bug introduced by
It seems like getSuffix() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $url .= $this->/** @scrutinizer ignore-call */ getSuffix();
Loading history...
23
        return $url;
24
    }
25
    
26
    public function getUrl($removeParameters = [])
27
    {
28
        $url = $this->getShortUrl();
29
        $query = $this->getQuery();
0 ignored issues
show
Bug introduced by
It seems like getQuery() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        /** @scrutinizer ignore-call */ 
30
        $query = $this->getQuery();
Loading history...
30
        foreach ($removeParameters as $item) {
31
            if (array_key_exists($item, $query)) {
32
                unset($query[$item]);
33
            }
34
        }
35
        $url .= $this->queryToString($query);
36
        return $url;
37
    }
38
    
39
    public function queryToString($query = [])
40
    {
41
        if (empty($query)) {
42
            return false;
43
        }
44
        $queries = [];
45
        foreach ($query as $k => $v) {
46
            $queries[] = sprintf('%s=%s', $k, $v);
47
        }
48
        return '?' . implode('&', $queries);
49
    }
50
}
51