PhpSetting::getIniPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Crossjoin\Browscap\Source\Ini;
5
6
use Crossjoin\Browscap\Exception\SourceConditionNotSatisfiedException;
7
use Crossjoin\Browscap\Exception\SourceUnavailableException;
8
use Crossjoin\Browscap\Source\SourceFactoryInterface;
9
10
/**
11
 * Class PhpSetting
12
 *
13
 * @package Crossjoin\Browscap\Source\Ini
14
 * @author Christoph Ziegenberg <[email protected]>
15
 * @link https://github.com/crossjoin/browscap
16
 */
17
class PhpSetting extends File implements SourceFactoryInterface
18
{
19
    /**
20
     * PhpBrowscapIni constructor.
21
     *
22
     * @throws SourceConditionNotSatisfiedException
23
     * @throws SourceUnavailableException
24
     */
25
    public function __construct()
26
    {
27
        $iniPath = $this->getIniPath();
28
        if ($iniPath !== '') {
29
            parent::__construct($iniPath);
30
        } else {
31
            throw new SourceConditionNotSatisfiedException(
32
                "Browscap file not configured in php configuration (see 'browscap' directive).",
33
                1458977060
34
            );
35
        }
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    protected function getIniPath() : string
42
    {
43
        return (string)ini_get('browscap');
44
    }
45
}
46