Pager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 26.92 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A viewFile() 7 7 1
A viewData() 7 7 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;
3
4
use Symfony\Component\Process\ProcessBuilder;
5
6
/**
7
 * Wraps the pager to execute it.
8
 */
9
class Pager
10
{
11
    /** @type string The pager command to use. */
12
    private $_pagerCommand;
13
14
    /**
15
     * Initialize the pager command.
16
     *
17
     * @api
18
     * @param string $pagerCommand The pager command to use.
19
     */
20
    public function __construct($pagerCommand)
21
    {
22
        $this->_pagerCommand = $pagerCommand;
23
    }
24
25
    /**
26
     * View the given file using the symfony process builder to build the
27
     * symfony process to execute.
28
     *
29
     * @api
30
     * @param \Symfony\Component\Process\ProcessBuilder $processBuilder The
31
     *     process builder.
32
     * @param string $filePath The path to the file to view.
33
     * @return \Symfony\Component\Process\Process The already-executed process.
34
     */
35 View Code Duplication
    public function viewFile(ProcessBuilder $processBuilder, $filePath)
36
    {
37
        $proc = $processBuilder->setPrefix($this->_pagerCommand)->setArguments([$filePath])->getProcess();
38
        $proc->setTty(true)->run();
39
40
        return $proc;
41
    }
42
43
    /**
44
     * View the given data using the symfony process builder to build the
45
     * symfony process to execute.
46
     *
47
     * @api
48
     * @param \Symfony\Component\Process\ProcessBuilder $processBuilder The
49
     *     process builder.
50
     * @param string $data The data to view.
51
     * @return \Symfony\Component\Process\Process The already-executed process.
52
     */
53 View Code Duplication
    public function viewData(ProcessBuilder $processBuilder, $data)
54
    {
55
        $proc = $processBuilder->setPrefix($this->_pagerCommand)->setInput($data)->getProcess();
56
        $proc->setTty(true)->run();
57
58
        return $proc;
59
    }
60
}
61