Completed
Pull Request — master (#9)
by mon
01:45
created

MapHandler::addMapEntry()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
1
<?php
2
3
namespace FileEye\MimeMap;
4
5
/**
6
 * Class for managing map singletons.
7
 */
8
abstract class MapHandler
9
{
10
    /**
11
     * The default map PHP class.
12
     */
13
    const DEFAULT_MAP_CLASS = '\FileEye\MimeMap\Map\ApacheMap';
14
15
    /**
16
     * The default map class to use.
17
     *
18
     * It can be overridden by ::setDefaultMapClass.
19
     *
20
     * @var string
21
     */
22
    protected static $defaultMapClass = MapHandler::DEFAULT_MAP_CLASS;
23
24
    /**
25
     * Sets a map class as default for new instances.
26
     *
27
     * @param string $map_class A FQCN.
28
     */
29 1
    public static function setDefaultMapClass($map_class)
30
    {
31 1
        static::$defaultMapClass = $map_class;
32 1
    }
33
34
    /**
35
     * Returns the map instance.
36
     *
37
     * @param string $map_class
38
     *   (Optional) The map FQCN to be used. If null, the default map will be
39
     *   used.
40
     *
41
     * @return AbstractMap
42
     */
43 24
    public static function map($map_class = null)
44
    {
45 24
        if (!$map_class) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $map_class of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
46 22
            $map_class = static::$defaultMapClass;
47
        }
48 24
        return $map_class::getInstance();
49
    }
50
}
51