IniLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 75
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setRemoteFilename() 0 11 2
A getRemoteIniUrl() 0 4 1
A getRemoteTimeUrl() 0 4 1
A getRemoteVersionUrl() 0 4 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace BrowscapPHP\Helper;
5
6
/**
7
 * class to load the browscap.ini
8
 */
9
final class IniLoader implements IniLoaderInterface
10
{
11
    /**
12
     * The location from which download the ini file. The placeholder for the file should be represented by a %s.
13
     *
14
     * @var string
15
     */
16
    private const REMOTE_INI_URI = 'http://browscap.org/stream?q=%q';
17
18
    /**
19
     * The location to use to check out if a new version of the browscap.ini file is available.
20
     *
21
     * @var string
22
     */
23
    private const REMOTE_TIME_URI = 'http://browscap.org/version';
24
25
    /**
26
     * @var string
27
     */
28
    private const REMOTE_VERSION_URI = 'http://browscap.org/version-number';
29
30
    /**
31
     * @var string
32
     */
33
    private $remoteFilename = IniLoaderInterface::PHP_INI;
34
35
    /**
36
     * sets the name of the local ini file
37
     *
38
     * @param string $name the file name
39
     *
40
     * @throws \BrowscapPHP\Helper\Exception
41
     */
42 2
    public function setRemoteFilename(string $name) : void
43
    {
44 2
        if (empty($name)) {
45 1
            throw new Exception(
46 1
                'the filename can not be empty',
47 1
                Exception::INI_FILE_MISSING
48
            );
49
        }
50
51 1
        $this->remoteFilename = $name;
52 1
    }
53
54
    /**
55
     * returns the of the remote location for updating the ini file
56
     *
57
     * @return string
58
     */
59 1
    public function getRemoteIniUrl() : string
60
    {
61 1
        return str_replace('%q', $this->remoteFilename, self::REMOTE_INI_URI);
62
    }
63
64
    /**
65
     * returns the of the remote location for checking the version of the ini file
66
     *
67
     * @return string
68
     */
69 1
    public function getRemoteTimeUrl() : string
70
    {
71 1
        return self::REMOTE_TIME_URI;
72
    }
73
74
    /**
75
     * returns the of the remote location for checking the version of the ini file
76
     *
77
     * @return string
78
     */
79
    public function getRemoteVersionUrl() : string
80
    {
81
        return self::REMOTE_VERSION_URI;
82
    }
83
}
84