Completed
Push — master ( af77e8...7d9d07 )
by Zack
11s
created

Form_Collection::add()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
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 12 and the first side effect is on line 6.

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 GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6
	die();
7
}
8
9
/**
10
 * A collection of \GV\Form objects.
11
 */
12
class Form_Collection extends Collection {
13
	/**
14
	 * Add a \GV\Form to this collection.
15
	 *
16
	 * @param \GV\Form $form The form to add to the internal array.
17
	 *
18
	 * @throws \InvalidArgumentException if $form is not of type \GV\Form.
19
	 *
20
	 * @api
21
	 * @since future
22
	 * @return void
23
	 */
24 1
	public function add( $form ) {
25 1
		if ( ! $form instanceof Form ) {
26 1
			throw new \InvalidArgumentException( 'Form_Collections can only contain objects of type \GV\Form.' );
27
		}
28 1
		parent::add( $form );
29 1
	}
30
31
	/**
32
	 * Get a \GV\Form from this list.
33
	 *
34
	 * @param int $form_id The ID of the form to get.
35
	 * @param string $backend The form backend identifier, allows for multiple form backends in the future. Unused until then.
36
	 *
37
	 * @api
38
	 * @since future
39
	 *
40
	 * @return \GV\Form|null The \GV\Form with the $form_id as the ID, or null if not found.
41
	 */
42 1
	public function get( $form_id, $backend = 'gravityforms' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $backend is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43 1
		foreach ( $this->all() as $form ) {
44 1
			if ( $form->ID == $form_id ) {
45 1
				return $form;
46
			}
47
		}
48 1
		return null;
49
	}
50
}
51