Issues (4138)

classes/integrations/class-articles.php (17 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
namespace lsx_health_plan\classes;
3
4
/**
5
 * Contains the related articles functions post type
6
 *
7
 * @package lsx-health-plan
8
 */
9
class Articles {
10
11
	/**
12
	 * Holds class instance
13
	 *
14
	 * @var      object \lsx_health_plan\classes\Articles()
15
	 */
16
	protected static $instance = null;
17
18
	/**
19
	 * An array of the post types for the Global Defaults field.
20
	 *
21
	 * @var array
22
	 */
23
	//public $default_types = array( 'exercise', 'recipe', 'meal', 'workout', 'plan' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
No space found before comment text; expected "// public $default_types = array( 'exercise', 'recipe', 'meal', 'workout', 'plan' );" but found "//public $default_types = array( 'exercise', 'recipe', 'meal', 'workout', 'plan' );"
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
24
25
	/**
26
	 * Constructor.
27
	 */
28
	public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
29
		$this->default_types = array(
0 ignored issues
show
Bug Best Practice introduced by
The property default_types does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
			\lsx_health_plan\functions\get_option( 'endpoint_meal', 'meal' ),
31
			\lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ),
32
			\lsx_health_plan\functions\get_option( 'endpoint_recipe_single', 'recipe' ),
33
			\lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ),
34
			\lsx_health_plan\functions\get_option( 'endpoint_plan', 'plan' ),
35
		);
36
		add_action( 'cmb2_admin_init', array( $this, 'related_articles_metabox' ) );
37
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
38
39
	/**
40
	 * Return an instance of this class.
41
	 *
42
	 * @since 1.0.0
43
	 *
44
	 * @return    object \lsx_health_plan\classes\Articles()    A single instance of this class.
45
	 */
46
	public static function get_instance() {
47
		// If the single instance hasn't been set, set it now.
48
		if ( null === self::$instance ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
49
			self::$instance = new self();
50
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
51
		return self::$instance;
52
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
53
54
	/**
55
	 * Define the related articles member metabox and field configurations.
56
	 */
57
	public function related_articles_metabox() {
58
		foreach ( $this->default_types as $type => $default_type ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
59
			$cmb = new_cmb2_box(
60
				array(
61
					'id'           => $default_type . '_related_articles_metabox',
0 ignored issues
show
Are you sure $default_type of type array|mixed can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
					'id'           => /** @scrutinizer ignore-type */ $default_type . '_related_articles_metabox',
Loading history...
62
					'title'        => __( 'Related Articles', 'lsx-health-plan' ),
63
					'object_types' => array( $default_type ), // Post type.
64
					'context'      => 'normal',
65
					'priority'     => 'low',
66
					'show_names'   => true,
67
				)
68
			);
69
70
			$cmb->add_field(
71
				array(
72
					'name'       => __( 'Related Articles', 'lsx-health-plan' ),
73
					'desc'       => __( 'Connect the related articles that applies to this ', 'lsx-health-plan' ) . $default_type,
74
					'id'         => $default_type . '_connected_articles',
75
					'type'       => 'post_search_ajax',
76
					'limit'      => 3,
77
					'sortable'   => true,
78
					'query_args' => array(
79
						'post_type'      => array( 'post' ),
80
						'post_status'    => array( 'publish' ),
81
						'posts_per_page' => 3,
82
					),
83
				)
84
			);
85
		}
86
87
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
88
89
}
90