WebAccessFactory::getWebAccess()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 1
dl 0
loc 14
rs 10
c 0
b 0
f 0
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