WebAccessFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A getWebAccess() 0 14 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebThumbnailer\Application\WebAccess;
6
7
/**
8
 * Create WebAccess instances depending on PHP extensions and given URL/path.
9
 */
10
class WebAccessFactory
11
{
12
    /**
13
     * Return a new WebAccess instance, can be used for local files using a path as $url.
14
     *
15
     * @param string|null $url URL on which the WebAccess will be used (optional)
16
     *
17
     * @return WebAccess instance.
18
     */
19
    public static function getWebAccess(?string $url = null): WebAccess
20
    {
21
        // Local file
22
        if (! empty($url) && $url[0] === '/') {
23
            return new WebAccessLocal();
24
        }
25
26
        // Default for remote: cURL
27
        if (function_exists('curl_init')) {
28
            return new WebAccessCUrl();
29
        }
30
31
        // Fallback
32
        return new WebAccessPHP();
33
    }
34
}
35