BrowserFactory::create()   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
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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