Passed
Pull Request — master (#1676)
by Arnaud
10:58 queued 04:17
created

Url   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 21
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isRemoteFileExists() 0 8 2
A isUrl() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Cecil\Util;
15
16
class Url
17
{
18
    /**
19
     * Tests if a string is an URL.
20
     */
21 1
    public static function isUrl(string $url): bool
22
    {
23 1
        return (bool) preg_match('~^(?:f|ht)tps?://~i', $url);
24
    }
25
26
    /**
27
     * Tests if a remote file exists.
28
     */
29 1
    public static function isRemoteFileExists(string $remoteFile): bool
30
    {
31 1
        $handle = @fopen($remoteFile, 'r');
32 1
        if (\is_resource($handle)) {
33 1
            return true;
34
        }
35
36
        return false;
37
    }
38
}
39