Completed
Push — master ( 589d3f...c5163f )
by Zack
12:27 queued 08:09
created

View::offsetGet()   D

Complexity

Conditions 10
Paths 10

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 10.6591

Importance

Changes 0
Metric Value
cc 10
eloc 18
nc 10
nop 1
dl 0
loc 25
ccs 13
cts 16
cp 0.8125
crap 10.6591
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 17 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
 * The default GravityView View class.
11
 *
12
 * Houses all base View functionality.
13
 *
14
 * Can be accessed as an array for old compatibility's sake
15
 *  in line with the elements inside the \GravityView_View_Data::$views array.
16
 */
17
class View implements \ArrayAccess {
18
19
	/**
20
	 * @var \WP_Post The backing post instance.
21
	 */
22
	private $post;
23
24
	/**
25
	 * @var \GV\View_Settings The settings.
26
	 *
27
	 * @api
28
	 * @since future
29
	 */
30
	public $settings;
31
32
	/**
33
	 * @var \GV\Form The backing form for this view.
34
	 *
35
	 * Contains the form that is sourced for entries in this view.
36
	 *
37
	 * @api
38
	 * @since future
39
	 */
40
	public $form;
41
42
	/**
43
	 * @var \GV\Field_Collection The fields for this view.
44
	 *
45
	 * Contains all the fields that are attached to this view.
46
	 *
47
	 * @api
48
	 * @since future
49
	 */
50
	public $fields;
51
52
	/**
53
	 * @var \GV\View_Template The template attached to this view.
54
	 */
55
	public $template;
56
57
	/**
58
	 * The constructor.
59
	 */
60 3
	public function __construct() {
61 3
		$this->settings = new View_Settings();
62 3
		$this->fields = new Field_Collection();
63 3
	}
64
65
	/**
66
	 * Register the gravityview WordPress Custom Post Type.
67
	 *
68
	 * @internal
69
	 * @return void
70
	 */
71
	public static function register_post_type() {
72
73
		/** Register only once */
74
		if ( post_type_exists( 'gravityview' ) ) {
75
			return;
76
		}
77
78
		/**
79
		 * @filter `gravityview_is_hierarchical` Make GravityView Views hierarchical by returning TRUE
80
		 * This will allow for Views to be nested with Parents and also allows for menu order to be set in the Page Attributes metabox
81
		 * @since 1.13
82
		 * @param boolean $is_hierarchical Default: false
83
		 */
84
		$is_hierarchical = (bool)apply_filters( 'gravityview_is_hierarchical', false );
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
85
86
		$supports = array( 'title', 'revisions' );
87
88
		if ( $is_hierarchical ) {
89
			$supports[] = 'page-attributes';
90
		}
91
92
		/**
93
		 * @filter  `gravityview_post_type_supports` Modify post type support values for `gravityview` post type
94
		 * @see add_post_type_support()
95
		 * @since 1.15.2
96
		 * @param array $supports Array of features associated with a functional area of the edit screen. Default: 'title', 'revisions'. If $is_hierarchical, also 'page-attributes'
97
		 * @param[in] boolean $is_hierarchical Do Views support parent/child relationships? See `gravityview_is_hierarchical` filter.
98
		 */
99
		$supports = apply_filters( 'gravityview_post_type_support', $supports, $is_hierarchical );
100
101
		/** Register Custom Post Type - gravityview */
102
		$labels = array(
103
			'name'                => _x( 'Views', 'Post Type General Name', 'gravityview' ),
104
			'singular_name'       => _x( 'View', 'Post Type Singular Name', 'gravityview' ),
105
			'menu_name'           => _x( 'Views', 'Menu name', 'gravityview' ),
106
			'parent_item_colon'   => __( 'Parent View:', 'gravityview' ),
107
			'all_items'           => __( 'All Views', 'gravityview' ),
108
			'view_item'           => _x( 'View', 'View Item', 'gravityview' ),
109
			'add_new_item'        => __( 'Add New View', 'gravityview' ),
110
			'add_new'             => __( 'New View', 'gravityview' ),
111
			'edit_item'           => __( 'Edit View', 'gravityview' ),
112
			'update_item'         => __( 'Update View', 'gravityview' ),
113
			'search_items'        => __( 'Search Views', 'gravityview' ),
114
			'not_found'           => \GravityView_Admin::no_views_text(),
115
			'not_found_in_trash'  => __( 'No Views found in Trash', 'gravityview' ),
116
			'filter_items_list'     => __( 'Filter Views list', 'gravityview' ),
117
			'items_list_navigation' => __( 'Views list navigation', 'gravityview' ),
118
			'items_list'            => __( 'Views list', 'gravityview' ),
119
			'view_items'            => __( 'See Views', 'gravityview' ),
120
			'attributes'            => __( 'View Attributes', 'gravityview' ),
121
		);
122
		$args = array(
123
			'label'               => __( 'view', 'gravityview' ),
124
			'description'         => __( 'Create views based on a Gravity Forms form', 'gravityview' ),
125
			'labels'              => $labels,
126
			'supports'            => $supports,
127
			'hierarchical'        => $is_hierarchical,
128
			/**
129
			 * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode?
130
			 * @see https://codex.wordpress.org/Function_Reference/register_post_type#public
131
			 * @since 1.15.2
132
			 * @param[in,out] boolean `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded via shortcode. Default: `true`
133
			 * @param int $view_id The ID of the View currently being requested. `0` for general setting
134
			 */
135
			'public'              => apply_filters( 'gravityview_direct_access', gravityview()->plugin->is_compatible(), 0 ),
136
			'show_ui'             => gravityview()->plugin->is_compatible(),
137
			'show_in_menu'        => gravityview()->plugin->is_compatible(),
138
			'show_in_nav_menus'   => true,
139
			'show_in_admin_bar'   => true,
140
			'menu_position'       => 17,
141
			'menu_icon'           => '',
142
			'can_export'          => true,
143
			/**
144
			 * @filter `gravityview_has_archive` Enable Custom Post Type archive?
145
			 * @since 1.7.3
146
			 * @param boolean False: don't have frontend archive; True: yes, have archive. Default: false
147
			 */
148
			'has_archive'         => apply_filters( 'gravityview_has_archive', false ),
149
			'exclude_from_search' => true,
150
			'rewrite'             => array(
151
				/**
152
				 * @filter `gravityview_slug` Modify the url part for a View.
153
				 * @see http://docs.gravityview.co/article/62-changing-the-view-slug
154
				 * @param string $slug The slug shown in the URL
155
				 */
156
				'slug' => apply_filters( 'gravityview_slug', 'view' ),
157
158
				/**
159
				 * @filter `gravityview/post_type/with_front` Should the permalink structure
160
				 *  be prepended with the front base.
161
				 *  (example: if your permalink structure is /blog/, then your links will be: false->/view/, true->/blog/view/).
162
				 *  Defaults to true.
163
				 * @see https://codex.wordpress.org/Function_Reference/register_post_type
164
				 * @since future
165
				 * @param bool $with_front
166
				 */
167
				'with_front' => apply_filters( 'gravityview/post_type/with_front', true ),
168
			),
169
			'capability_type'     => 'gravityview',
170
			'map_meta_cap'        => true,
171
		);
172
173
		register_post_type( 'gravityview', $args );
174
	}
175
176
177
	/**
178
	 * Construct a \GV\View instance from a \WP_Post.
179
	 *
180
	 * @param $post The \WP_Post instance to wrap.
181
	 *
182
	 * @api
183
	 * @since future
184
	 * @return \GV\View|null An instance around this \WP_Post if valid, null otherwise.
185
	 */
186 4
	public static function from_post( $post ) {
187 4
		if ( ! $post || get_post_type( $post ) != 'gravityview' ) {
0 ignored issues
show
introduced by
Found "!= '". Use Yoda Condition checks, you must
Loading history...
188 1
			gravityview()->log->error( 'Only gravityview post types can be \GV\View instances.' );
189 1
			return null;
190
		}
191
192 4
		$view = new self();
193 4
		$view->post = $post;
194
195
		/** Get connected form. */
196 4
		$view->form = GF_Form::by_id( $view->_gravityview_form_id );
0 ignored issues
show
Documentation introduced by
The property _gravityview_form_id does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
197 4
		if ( ! $view->form ) {
198
			gravityview()->log->error( 'View #{view_id} tried attaching non-existent Form #{form_id} to it.', array(
199
				'view_id' => $view->ID,
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
200
				'form_id' => $view->_gravityview_form_id ? : 0,
0 ignored issues
show
Documentation introduced by
The property _gravityview_form_id does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
201
			) );
202
		}
203
204
		/**
205
		* @filter `gravityview/configuration/fields` Filter the View fields' configuration array
206
		* @since 1.6.5
207
		*
208
		* @param $fields array Multi-array of fields with first level being the field zones
209
		* @param $view_id int The View the fields are being pulled for
210
		*/
211 4
		$configuration = apply_filters( 'gravityview/configuration/fields', (array)$view->_gravityview_directory_fields, $view->ID );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
212
213
		/** Get all fields. */
214 4
		$view->fields = Field_Collection::from_configuration( $configuration );
215
216
		/** The settings. */
217 4
		$view->settings->update( gravityview_get_template_settings( $view->ID ) );
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
218
219
		/** Set the template. */
220 4
		$view->template = new \GV\View_Template( $view->_gravityview_directory_template );
0 ignored issues
show
Bug introduced by
The property _gravityview_directory_template does not seem to exist. Did you mean template?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
221
222
		/**
223
		 * @deprecated
224
		 *
225
		 * The data here has been moved to various keys in a \GV\View instance.
226
		 * As a compatibilty layer we allow array access over any \GV\View instance with these keys.
227
		 *
228
		 * This data is immutable (for now).
229
		 *
230
		 * @see \GV\View::offsetGet() for internal mappings.
231
		 */
232 4
		$view->_data = array(
0 ignored issues
show
Bug introduced by
The property _data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
233
			/**
234
			 * @deprecated
235
			 * @see \GV\View::$ID
236
			 */
237
			// 'id' => $view->ID,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
238
239
			/**
240
			 * @deprecated
241
			 * @see \GV\View::$ID
242
			 */
243
			// 'view_id' => $view->ID,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
244
245
			/**
246
			 * @deprecated
247
			 * @see \GV\View::$form
248
			 */
249
			// 'form' => gravityview_get_form( $view->_gravityview_form_id ),
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
250
251
			/**
252
			 * @deprecated
253
			 * @see \GV\View::$form::$ID
254
			 */
255
			// 'form_id' => $view->_gravityview_form_id,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
256
257
			/**
258
			 * @deprecated
259
			 * @see \GV\View::$settings
260
			 */
261
			// 'atts' => $view->settings->as_atts(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
262
263
			/**
264
			 * @deprecated
265
			 * @see \GV\View::$fields
266
			 */
267
			// 'fields' => \GravityView_View_Data::getInstance()->get_fields( $view->ID ),
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
268
269
			/**
270
			 * @deprecated
271
			 * @see \GV\View::$template::$ID
272
			 */
273
			// 'template_id' => gravityview_get_template_id( $view->ID ),
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
274
275 4
			'widgets' => gravityview_get_directory_widgets( $view->ID ),
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
276
		);
277
278 4
		return $view;
279
	}
280
281
	/**
282
	 * Construct a \GV\View instance from a post ID.
283
	 *
284
	 * @param int|string $post_id The post ID.
285
	 *
286
	 * @api
287
	 * @since future
288
	 * @return \GV\View|null An instance around this \WP_Post or null if not found.
289
	 */
290 4
	public static function by_id( $post_id ) {
291 4
		if ( ! $post_id || ! $post = get_post( $post_id ) ) {
292 1
			return null;
293
		}
294 4
		return self::from_post( $post );
295
	}
296
297
	/**
298
	 * Determines if a view exists to begin with.
299
	 *
300
	 * @param int|\WP_Post|null $view_id The WordPress post ID, a \WP_Post object or null for global $post;
0 ignored issues
show
Bug introduced by
There is no parameter named $view_id. 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...
301
	 *
302
	 * @api
303
	 * @since future
304
	 * @return bool Whether the post exists or not.
305
	 */
306 4
	public static function exists( $view ) {
307 4
		return get_post_type( $view ) == 'gravityview';
308
	}
309
310
	/**
311
	 * ArrayAccess compatibility layer with GravityView_View_Data::$views
312
	 *
313
	 * @internal
314
	 * @deprecated
315
	 * @since future
316
	 * @return bool Whether the offset exists or not, limited to GravityView_View_Data::$views element keys.
317
	 */
318 1
	public function offsetExists( $offset ) {
0 ignored issues
show
Coding Style introduced by
The function name offsetExists is in camel caps, but expected offset_exists instead as per the coding standard.
Loading history...
319 1
		$data_keys = array( 'id', 'view_id', 'form_id', 'template_id', 'atts', 'fields', 'widgets', 'form' );
320 1
		return in_array( $offset, $data_keys );
321
	}
322
323
	/**
324
	 * ArrayAccess compatibility layer with GravityView_View_Data::$views
325
	 *
326
	 * Maps the old keys to the new data;
327
	 *
328
	 * @internal
329
	 * @deprecated
330
	 * @since future
331
	 *
332
	 * @return mixed The value of the requested view data key limited to GravityView_View_Data::$views element keys.
333
	 */
334 1
	public function offsetGet( $offset ) {
0 ignored issues
show
Coding Style introduced by
The function name offsetGet is in camel caps, but expected offset_get instead as per the coding standard.
Loading history...
335
		
336 1
		gravityview()->log->notice( 'This is a \GV\View object should not be accessed as an array.' );
337
338 1
		if ( ! isset( $this[$offset] ) ) {
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
339
			return null;
340
		}
341
342
		switch ( $offset ) {
343 1
			case 'id':
344 1
			case 'view_id':
345 1
				return $this->ID;
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
346 1
			case 'form':
347 1
				return $this->form;
348 1
			case 'form_id':
349 1
				return $this->form ? $this->form->ID : null;
350 1
			case 'atts':
351
				return $this->as_atts();
0 ignored issues
show
Bug introduced by
The method as_atts() does not seem to exist on object<GV\View>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
352 1
			case 'template_id':
353 1
				return $this->template ? $this->template->ID : null;
354
			default:
355
				/** @todo move the rest out and get rid of _data completely! */
356
				return $this->_data[$offset];
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
357
		}
358
	}
359
360
	/**
361
	 * ArrayAccess compatibility layer with GravityView_View_Data::$views
362
	 *
363
	 * @internal
364
	 * @deprecated
365
	 * @since future
366
	 *
367
	 * @return void
368
	 */
369 1
	public function offsetSet( $offset, $value ) {
0 ignored issues
show
Coding Style introduced by
The function name offsetSet is in camel caps, but expected offset_set instead as per the coding standard.
Loading history...
370 1
		gravityview()->log->error( 'The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.' );
371 1
	}
372
373
	/**
374
	 * ArrayAccess compatibility layer with GravityView_View_Data::$views
375
	 *
376
	 * @internal
377
	 * @deprecated
378
	 * @since future
379
	 * @return void
380
	 */
381 1
	public function offsetUnset( $offset ) {
0 ignored issues
show
Coding Style introduced by
The function name offsetUnset is in camel caps, but expected offset_unset instead as per the coding standard.
Loading history...
382 1
		gravityview()->log->error( 'The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.' );
383 1
	}
384
385
	/**
386
	 * Be compatible with the old data object.
387
	 *
388
	 * Some external code expects an array (doing things like foreach on this, or array_keys)
389
	 *  so let's return an array in the old format for such cases. Do not use unless using
390
	 *  for back-compatibility.
391
	 *
392
	 * @internal
393
	 * @deprecated
394
	 * @since future
395
	 * @return array
396
	 */
397 1
	public function as_data() {
398 1
		return array_merge(
399 1
			array( 'id' => $this->ID ),
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
400 1
			array( 'view_id' => $this->ID ),
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<GV\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
401 1
			array( 'form_id' => $this->form ? $this->form->ID : null ),
402 1
			array( 'form' => $this->form ? gravityview_get_form( $this->form->ID ) : null ),
403 1
			array( 'atts' => $this->settings->as_atts() ),
0 ignored issues
show
Deprecated Code introduced by
The method GV\View_Settings::as_atts() has been deprecated.

This method has been deprecated.

Loading history...
404 1
			array( 'fields' => $this->fields->by_visible()->as_configuration() ),
405 1
			array( 'template_id' => $this->template? $this->template->ID : null ),
406 1
			$this->_data
407
		);
408
	}
409
410 3
	public function __get( $key ) {
411 3
		return $this->post->$key;
412
	}
413
}
414