Passed
Push — master ( 410431...1494d3 )
by Atanas
03:46
created

OldInput::store()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A OldInput::set() 0 3 1
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 2
	protected $flash_key = '';
25 2
26
	/**
27
	 * Constructor.
28
	 *
29
	 * @codeCoverageIgnore
30
	 * @param Flash  $flash
31
	 * @param string $flash_key
32
	 */
33 2
	public function __construct( Flash $flash, $flash_key = '__wpemergeOldInput' ) {
34 2
		$this->flash = $flash;
35 2
		$this->flash_key = $flash_key;
36 2
	}
37 2
38
	/**
39
	 * Get whether the old input service is enabled.
40
	 *
41
	 * @return boolean.
0 ignored issues
show
Documentation introduced by
The doc-type boolean. could not be parsed: Unknown type name "boolean." at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
42
	 */
43 1
	public function enabled() {
44
		return $this->flash->enabled();
45
	}
46
47
	/**
48
	 * Get request value for key from the previous request.
49
	 *
50 1
	 * @param  string     $key
51 1
	 * @param  mixed      $default
52
	 * @return mixed
53
	 */
54
	public function get( $key, $default = null ) {
55
		return Arr::get( $this->flash->get( $this->flash_key, [] ), $key, $default );
56
	}
57
58 1
	/**
59
	 * Set input for the next request.
60
	 *
61
	 * @param array $input
62
	 */
63
	public function set( $input ) {
64
		$this->flash->add( $this->flash_key, $input );
65 1
	}
66 1
67
	/**
68
	 * Clear input for the next request.
69
	 *
70
	 * @return void
71
	 */
72
	public function clear() {
73
		$this->flash->clear( $this->flash_key );
74
	}
75
}
76