Completed
Push — master ( da5ca0...e55bc1 )
by Atanas
02:05
created

OldInput::enabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 0
dl 0
loc 2
c 0
b 0
f 0
cc 1
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace WPEmerge\Input;
4
5
use WPEmerge\Flash\Flash;
6
use WPEmerge\Support\Arr;
7
8
/**
9
 * Provide a way to get values from the previous request.
10
 */
11
class OldInput {
12
	/**
13
	 * Flash service.
14
	 *
15
	 * @var Flash
16
	 */
17
	protected $flash = null;
18
19
	/**
20
	 * Key to store the flashed data with.
21
	 *
22
	 * @var string
23
	 */
24
	protected $flash_key = '';
25
26
	/**
27
	 * Constructor.
28
	 *
29
	 * @codeCoverageIgnore
30
	 * @param Flash  $flash
31
	 * @param string $flash_key
32
	 */
33
	public function __construct( Flash $flash, $flash_key = '__wpemergeOldInput' ) {
34
		$this->flash = $flash;
35
		$this->flash_key = $flash_key;
36
	}
37
38
	/**
39
	 * Get whether the old input service is enabled.
40
	 *
41
	 * @return boolean
42
	 */
43 1
	public function enabled() {
44 1
		return $this->flash->enabled();
45
	}
46
47
	/**
48
	 * Get request value for key from the previous request.
49
	 *
50
	 * @param  string     $key
51
	 * @param  mixed      $default
52
	 * @return mixed
53
	 */
54 1
	public function get( $key, $default = null ) {
55 1
		return Arr::get( $this->flash->get( $this->flash_key, [] ), $key, $default );
56
	}
57
58
	/**
59
	 * Set input for the next request.
60
	 *
61
	 * @param array $input
62
	 */
63 1
	public function set( $input ) {
64 1
		$this->flash->add( $this->flash_key, $input );
65 1
	}
66
67
	/**
68
	 * Clear input for the next request.
69
	 *
70
	 * @return void
71
	 */
72 1
	public function clear() {
73 1
		$this->flash->clear( $this->flash_key );
74 1
	}
75
}
76