Passed
Push — master ( cb8425...ce0b78 )
by
unknown
01:40
created

OldInput::store()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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