Completed
Push — develop ( 5248b0...221cfd )
by Zack
16:23
created

merge_content_meta_keys()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 4
nop 3
dl 0
loc 17
rs 8.8571
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 19 and the first side effect is on line 60.

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
/**
3
 * Add SiteOrigin plugin theme compatibility to GravityView
4
 *
5
 * @file      class-gravityview-theme-hooks-siteorigin.php
6
 * @package   GravityView
7
 * @license   GPL2+
8
 * @author    Katz Web Services, Inc.
9
 * @link      http://gravityview.co
10
 * @copyright Copyright 2015, Katz Web Services, Inc.
11
 *
12
 * @since 2.0.7
13
 */
14
15
/**
16
 * @inheritDoc
17
 * @since 2.0.7
18
 */
19
class GravityView_Theme_Hooks_SiteOrigin extends GravityView_Plugin_and_Theme_Hooks {
20
21
	protected $constant_name = 'SITEORIGIN_PANELS_VERSION';
22
23
	protected $class_name = 'SiteOrigin_Panels';
24
25
	protected $content_meta_keys = array(
26
		'panels_data'
27
	);
28
29
	/**
30
	 * Add support for SiteOrigin storage of widget information
31
	 *
32
	 * @since 2.0.7
33
	 *
34
	 * @param array $meta_keys
35
	 * @param null $post
36
	 * @param \GV\View_Collection $views
37
	 *
38
	 * @return array
39
	 */
40
	function merge_content_meta_keys( $meta_keys = array(), $post = null, & $views = null ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
41
42
		if( empty( $post->panels_data ) || empty( $post->panels_data['widgets'] ) ) {
43
			return $meta_keys;
44
		}
45
46
		foreach ( (array) $post->panels_data['widgets'] as $widget ) {
47
48
			if ( empty( $widget['text'] ) ) {
49
				continue;
50
			}
51
52
			$views->merge( \GV\View_Collection::from_content( $widget['text'] ) );
0 ignored issues
show
Bug introduced by
It seems like $views is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
53
		}
54
55
		return $meta_keys;
56
	}
57
58
}
59
60
new GravityView_Theme_Hooks_SiteOrigin;