Pager::__construct()   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 1
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