BrowserFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 4 1
1
<?php
2
namespace Nubs\Sensible\CommandFactory;
3
4
use Exception;
5
use Nubs\Sensible\Browser;
6
use Nubs\Sensible\Strategy\BrowserStrategy;
7
use Nubs\Which\Locator as CommandLocator;
8
9
/**
10
 * Uses the BrowserStrategy to locate an browser.
11
 */
12
class BrowserFactory
13
{
14
    use CommandFactoryTrait;
15
16
    /** @type \Nubs\Sensible\Strategy\BrowserStrategy The browser strategy. */
17
    private $_strategy;
18
19
    /**
20
     * Create the browser.
21
     *
22
     * @api
23
     * @param \Nubs\Which\Locator $commandLocator The command locator.  This
24
     *     helps locate commands using PATH.
25
     * @param string[] $browsers The names to the potential browsers.  The first
26
     *     command in the list that can be located will be used.
27
     */
28
    public function __construct(CommandLocator $commandLocator, array $browsers = ['sensible-browser', 'firefox', 'chromium-browser', 'chrome', 'elinks'])
29
    {
30
        $this->_strategy = new BrowserStrategy($browsers, $commandLocator);
31
    }
32
33
    /**
34
     * Create the browser object using the strategy.
35
     *
36
     * @api
37
     * @return \Nubs\Sensible\Browser The created browser object.
38
     * @throws \Exception if no browser can be found.
39
     */
40
    public function create()
41
    {
42
        return new Browser($this->getCommand($this->_strategy));
43
    }
44
}
45