EditorFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A create() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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