Completed
Push — master ( cf8268...397f5b )
by Zack
24:22 queued 11:06
created

GravityView_Theme_Hooks_SiteOrigin   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
C merge_content_meta_keys() 0 30 8
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 73.

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
			$views->merge( \GV\View_Collection::from_content( \GV\Utils::get( $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...
49
50
			if ( empty( $widget['tabs'] ) || ! is_array( $widget['tabs'] ) ) {
51
				continue;
52
			}
53
54
			foreach ( $widget['tabs'] as $tab ) {
55
56
				// Livemesh Tabs
57
				$backup = \GV\Utils::get( $tab, 'tab_content' );
58
59
				// SiteOrigin Tabs
60
				$content = \GV\Utils::get( $tab, 'content_text', $backup );
61
62
				if( $content ) {
63
					$views->merge( \GV\View_Collection::from_content( $content ) );
64
				}
65
			}
66
		}
67
68
		return $meta_keys;
69
	}
70
71
}
72
73
new GravityView_Theme_Hooks_SiteOrigin;