Passed
Push — master ( 222a88...547f19 )
by Andrea Marco
02:49 queued 12s
created

EndpointAware::isEndpoint()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 3
nc 3
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Cerbero\LazyJson\Concerns;
4
5
/**
6
 * The endpoint aware trait.
7
 *
8
 */
9
trait EndpointAware
10
{
11
    /**
12
     * Determine whether the given item may point to an endpoint
13
     *
14
     * @param mixed $item
15
     * @return bool
16
     */
17 10
    public function isEndpoint($item): bool
18
    {
19 10
        if (!is_string($item) || ($url = parse_url($item)) === false) {
20 7
            return false;
21
        }
22
23 4
        return in_array($url['scheme'] ?? null, ['http', 'https']) && isset($url['host']);
24
    }
25
}
26