EditorFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
namespace Nubs\Sensible\CommandFactory;
3
4
use Exception;
5
use Habitat\Environment\Environment;
6
use Nubs\Sensible\Editor;
7
use Nubs\Sensible\Strategy\EditorStrategy;
8
use Nubs\Which\Locator as CommandLocator;
9
10
/**
11
 * Uses the EditorStrategy to locate an editor.
12
 */
13 View Code Duplication
class EditorFactory
14
{
15
    use CommandFactoryTrait;
16
17
    /** @type \Nubs\Sensible\Strategy\PagerStrategy The pager strategy. */
18
    private $_strategy;
19
20
    /**
21
     * Create the editor.
22
     *
23
     * @api
24
     * @param \Nubs\Which\Locator $commandLocator The command locator.  This
25
     *     helps locate commands using PATH.
26
     * @param string[] $editors The names to the potential editors.  The first
27
     *     command in the list that can be located will be used.
28
     * @param \Habitat\Environment\Environment $environment The environment
29
     *     variable wrapper.  Defaults to null, which just uses the built-in
30
     *     getenv.
31
     */
32
    public function __construct(CommandLocator $commandLocator, array $editors = ['sensible-editor', 'nano', 'vim', 'ed'], Environment $environment = null)
33
    {
34
        $this->_strategy = new EditorStrategy($editors, $commandLocator, $environment);
35
    }
36
37
    /**
38
     * Create the editor object using the strategy.
39
     *
40
     * @api
41
     * @return \Nubs\Sensible\Editor The created editor object.
42
     * @throws \Exception if no editor can be found.
43
     */
44
    public function create()
45
    {
46
        return new Editor($this->getCommand($this->_strategy));
47
    }
48
}
49