PlatformLocatorFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 8 3
1
<?php
2
namespace Nubs\Which\LocatorFactory;
3
4
use Habitat\Environment\Environment;
5
use Icecave\Isolator\Isolator;
6
7
/**
8
 * Factory that uses the current platform to determine whether to use the
9
 * PosixLocatorFactory or the WindowsLocatorFactory.
10
 */
11
class PlatformLocatorFactory implements LocatorFactoryInterface
12
{
13
    /** @type \Nubs\Which\LocatorFactory\LocatorFactoryInterface The platform-specific factory. */
14
    private $_platformFactory;
15
16
    /**
17
     * Creates the factory to wrap the platform-specific factory.
18
     *
19
     * @api
20
     * @param \Icecave\Isolator\Isolator $isolator The isolator object to
21
     *     override environment variable lookup.
22
     */
23
    public function  __construct(Isolator $isolator = null)
24
    {
25
        if ($isolator ? $isolator->defined('PHP_WINDOWS_VERSION_BUILD') : defined('PHP_WINDOWS_VERSION_BUILD')) {
26
            $this->_platformFactory = new WindowsLocatorFactory();
27
        } else {
28
            $this->_platformFactory = new PosixLocatorFactory();
29
        }
30
    }
31
32
    /**
33
     * Create a locator using the platform-specific factory.
34
     *
35
     * @api
36
     * @param \Habitat\Environment\Environment $environment The environment
37
     *     variable wrapper.  Defaults to null which just uses PHP's built-in
38
     *     getenv.
39
     * @return \Nubs\Which\Locator The locator.
40
     */
41
    public function create(Environment $environment = null)
42
    {
43
        return $this->_platformFactory->create($environment);
44
    }
45
}
46