FormArtisan::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace WFV\Artisan;
3
defined( 'ABSPATH' ) || die();
4
5
use WFV\Agent\InspectionAgent;
6
use WFV\Contract\ArtisanInterface;
7
use WFV\Collection\ErrorCollection;
8
use WFV\Collection\InputCollection;
9
use WFV\Collection\RuleCollection;
10
11
use WFV\FormComposite;
12
13
/**
14
 *
15
 *
16
 * @since 0.10.0
17
 */
18
class FormArtisan implements ArtisanInterface {
19
20
	/**
21
	 *
22
	 *
23
	 * @since 0.11.3
24
	 * @var string
25
	 */
26
	public $action;
27
28
	/**
29
	 *
30
	 *
31
	 * @since 0.10.0
32
	 * @var array
33
	 */
34
	public $collection = array();
35
36
	/**
37
	 *
38
	 *
39
	 * @since 0.10.0
40
	 * @access protected
41
	 * @var array
42
	 */
43
	protected $config = array();
44
45
	/**
46
	 *
47
	 *
48
	 * @since 0.10.0
49
	 * @access protected
50
	 * @var \WFV\FormComposite
51
	 */
52
	protected $form;
53
54
	/**
55
	 *
56
	 *
57
	 * @since 0.11.0
58
	 *
59
	 * @param array $config
60
	 * @param string $action
61
	 */
62
	public function __construct( array $config, $action ) {
63
		$this->config = $config;
64
		$this->action = $action;
65
	}
66
67
	/**
68
	 * Return the final Form instance
69
	 *
70
	 * @since 0.10.0
71
	 *
72
	 * @return WFV\FormComposite
73
	 */
74
	public function actualize() {
75
		return $this->form;
76
	}
77
78
	/**
79
	 * Creates the instance of FormComposite
80
	 *
81
	 * @since 0.10.0
82
	 *
83
	 * @param string $action
0 ignored issues
show
Bug introduced by
There is no parameter named $action. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
84
	 * @return WFV\Artisan\FormArtisan
85
	 */
86
	public function create() {
87
		$this->form = new FormComposite( $this );
88
		return $this;
89
	}
90
91
	/**
92
	 * Create instance of ErrorCollection
93
	 * Save it in $collection array property
94
	 *
95
	 * @since 0.10.0
96
	 *
97
	 * @return WFV\Artisan\FormArtisan
98
	 */
99
	public function errors() {
100
		$this->collection['errors'] = new ErrorCollection( $this->labels() );
101
		return $this;
102
	}
103
104
	/**
105
	 * Create instance of InputCollection
106
	 * Save it in $collection array property
107
	 *
108
	 * @since 0.10.0
109
	 *
110
	 * @return WFV\Artisan\FormArtisan
111
	 */
112
	public function input() {
113
		$guard = new InspectionAgent( $this->action );
114
		$this->collection['input'] = new InputCollection( $guard );
115
		return $this;
116
	}
117
118
	/**
119
	 * Create instance of RuleCollection
120
	 * Save it in $collection array property
121
	 *
122
	 * @since 0.10.0
123
	 *
124
	 * @return WFV\Artisan\FormArtisan
125
	 */
126
	public function rules() {
127
		$this->collection['rules'] = new RuleCollection( $this->config );
128
		return $this;
129
	}
130
131
	/**
132
	 * Returns an array of human friendly field labels
133
	 *  as defined in the config array
134
	 *
135
	 * @since 0.11.0
136
	 * @access protected
137
	 *
138
	 * @return array
139
	 */
140
	protected function labels() {
141
		return array_map( function( $item ) {
142
			return $item['label'];
143
		}, $this->config);
144
	}
145
}
146