Completed
Push — min-php71 ( f5a25a )
by James
05:53
created

IniLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 81
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 81
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 13 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
10
{
11
    const PHP_INI_LITE = 'Lite_PHP_BrowscapINI';
12
    const PHP_INI_FULL = 'Full_PHP_BrowscapINI';
13
    const PHP_INI      = 'PHP_BrowscapINI';
14
15
    /**
16
     * The location from which download the ini file. The placeholder for the file should be represented by a %s.
17
     *
18
     * @var string
19
     */
20
    private $remoteIniUrl     = 'http://browscap.org/stream?q=%q';
21
22
    /**
23
     * The location to use to check out if a new version of the browscap.ini file is available.
24
     * @var string
25
     */
26
    private $remoteTimeUrl    = 'http://browscap.org/version';
27
28
    /**
29
     * @var string
30
     */
31
    private $remoteVersionUrl = 'http://browscap.org/version-number';
32
33
    /**
34
     * @var string
35
     */
36
    private $remoteFilename = self::PHP_INI;
37
38
    /**
39
     * sets the name of the local ini file
40
     *
41
     * @param string $name the file name
42
     *
43
     * @throws \BrowscapPHP\Helper\Exception
44
     * @return \BrowscapPHP\Helper\IniLoader
45
     */
46 3
    public function setRemoteFilename(string $name)
47
    {
48 3
        if (empty($name)) {
49 1
            throw new Exception(
50 1
                'the filename can not be empty',
51 1
                Exception::INI_FILE_MISSING
52
            );
53
        }
54
55 2
        $this->remoteFilename = $name;
56
57 2
        return $this;
58
    }
59
60
    /**
61
     * returns the of the remote location for updating the ini file
62
     *
63
     * @return string
64
     */
65 1
    public function getRemoteIniUrl() : string
66
    {
67 1
        return str_replace('%q', $this->remoteFilename, $this->remoteIniUrl);
68
    }
69
70
    /**
71
     * returns the of the remote location for checking the version of the ini file
72
     *
73
     * @return string
74
     */
75 1
    public function getRemoteTimeUrl() : string
76
    {
77 1
        return $this->remoteTimeUrl;
78
    }
79
80
    /**
81
     * returns the of the remote location for checking the version of the ini file
82
     *
83
     * @return string
84
     */
85
    public function getRemoteVersionUrl() : string
86
    {
87
        return $this->remoteVersionUrl;
88
    }
89
}
90