Passed
Push — master ( 517cb3...2c2725 )
by Atanas
02:15
created

OldInput::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace WPEmerge\Input;
4
5
use 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
	 * Key to store the flashed data with
14
	 *
15
	 * @var string
16
	 */
17
	const FLASH_KEY = '__wpEmergeOldInput';
18
19
	/**
20
	 * Get all previously flashed request data
21
	 *
22
	 * @return array
23
	 */
24 2
	public function all() {
25 2
		return Flash::peek( static::FLASH_KEY );
26
	}
27
28
	/**
29
	 * Get any previously flashed request data value
30
	 *
31
	 * @see Arr::get()
32
	 */
33 2
	public function get() {
34 2
		$arguments = array_merge( [
35 2
			static::all(),
36 2
		], func_get_args() );
37 2
		return call_user_func_array( [Arr::class, 'get'], $arguments );
38
	}
39
40
	/**
41
	 * Clear previously stored input
42
	 */
43 1
	public function clear() {
44
		// @codeCoverageIgnoreStart
45
		if ( ! Flash::enabled() ) {
46
			return;
47
		}
48
		// @codeCoverageIgnoreEnd
49
50 1
		Flash::clear( static::FLASH_KEY );
51 1
	}
52
53
	/**
54
	 * Store the current input
55
	 *
56
	 * @param array $input
57
	 */
58 1
	public function store( $input ) {
59
		// @codeCoverageIgnoreStart
60
		if ( ! Flash::enabled() ) {
61
			return;
62
		}
63
		// @codeCoverageIgnoreEnd
64
65 1
		Flash::add( static::FLASH_KEY, $input );
66 1
	}
67
}
68