GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 526d65...193e4b )
by Marko
01:37
created

Tabify_Edit_Screen_Feature_Detection::get_metaboxes()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 5
nop 1
1
<?php
2
3
class Tabify_Edit_Screen_Feature_Detection {
4
5
	public function __construct() {
6
		// Actions to return JSON output on post type new/edit screen
7
		add_action( 'current_screen', array( $this, 'head_action_begin' ) );
8
9
		// Hook for requesting missing hooks
10
		add_action( 'tabify_add_meta_boxes', array( $this, 'add_missing_meta_boxes' ) );
11
12
		// Checking & storing unattached meta boxes on the edit page
13
		add_action( 'tabify_unattached_metaboxes', array( $this, 'unattached_metaboxes' ) );
14
	}
15
16
17
	public function head_action_begin( $screen ) {
0 ignored issues
show
Coding Style introduced by
head_action_begin uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
18
		if ( ( 'post' == $screen->base || 'media' == $screen->base ) && isset( $_GET['tes_metaboxes'] ) ) {
19
			ob_end_clean(); // For when warnings are displayed
20
			ob_start();
21
22
			add_filter( 'tabify_tab_posttype_show', '__return_true', 1000 );
23
			add_action( 'admin_head', array( $this, 'head_action' ), 110 );
24
		}
25
		else if ( 'settings_page_tabify-edit-screen' == $screen->base ) {
26
			$this->enqueue_script();
27
		}
28
	}
29
30
	private function enqueue_script() {
31
		wp_register_script( 'tabify-edit-screen-detection', plugins_url( '/detection.js', __FILE__ ), array( 'jquery' ), '1.0' );
32
		wp_enqueue_script( 'tabify-edit-screen-detection' );
33
34
		$posttype_links = array();
35
36
		$args = array(
37
			'show_ui' => true
38
		);
39
		$posttypes_objects = get_post_types( $args, 'objects' );
40
		$posttypes_objects = apply_filters( 'tabify_posttypes', $posttypes_objects );
41
42
		foreach ( $posttypes_objects as $posttype ) {
43
			if ( get_transient( 'tabify_detection_' . $posttype->name ) !== false ) {
44
				continue;
45
			}
46
47
			$args = array(
48
				'post_type'      => $posttype->name,
49
				'orderby'        => 'rand',
50
				'posts_per_page' => '1',
51
				'post_status'    => 'any'
52
			);
53
			$post = get_posts( $args );
54
55
			if ( ! empty( $post ) ) {
56
				$url = get_edit_post_link( $post[0], 'raw' );
57
				$url = add_query_arg( 'tes_metaboxes', 'true', $url );
58
				$posttype_links[ $posttype->name ] = $url;
59
			}
60
		}
61
62
		wp_localize_script( 'tabify-edit-screen-detection', 'tabify_detection', array(
63
			'posttype_links' => $posttype_links
64
		) );
65
	}
66
67
	public function head_action() {
68
		global $wp_meta_boxes;
69
70
		$screen = get_current_screen();
71
72
		ob_end_clean();
73
74
		echo wp_json_encode( get_transient( 'tabify_detection_' . $screen->post_type ) );
75
76
		exit;
77
	}
78
79
80
	public function add_missing_meta_boxes( $post_type ) {
81
		if ( is_array( $metaboxes = get_transient( 'tabify_detection_' . $post_type ) ) ) {
82
			foreach ( $metaboxes as $id => $metabox ) {
83
				if ( ! isset( $wp_meta_boxes[ $post_type ][ $metabox->context ][ $metabox->priority ][ $id ] ) ) {
84
					add_meta_box( $id, $metabox->title, '__return_false', $post_type, $metabox->priority, $metabox->context );
85
				}
86
			}
87
		}
88
	}
89
90
	public function unattached_metaboxes( $unattached_metaboxes ) {
91
		global $wp_meta_boxes;
92
93
		$screen = get_current_screen();
94
95
		if ( get_transient( 'tabify_detection_' . $screen->post_type ) !== false ) {
96
			return;
97
		}
98
99
		$metaboxes = array();
100
101
		if ( $unattached_metaboxes ) {
102
			$metaboxes = $this->get_metaboxes( $screen->post_type );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $metaboxes is correct as $this->get_metaboxes($screen->post_type) (which targets Tabify_Edit_Screen_Featu...ection::get_metaboxes()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
103
104
			foreach ( $metaboxes as $metabox_id => $metabox ) {
0 ignored issues
show
Bug introduced by
The expression $metaboxes of type null is not traversable.
Loading history...
105
				if ( ! isset( $unattached_metaboxes[ $metabox_id ] )  ) {
106
					unset( $metaboxes[ $metabox_id ] );
107
				}
108
			}
109
		}
110
111
		set_transient( 'tabify_detection_' . $screen->post_type, $metaboxes, WEEK_IN_SECONDS );
112
	}
113
114
	private function get_metaboxes( $post_type ) {
115
		$metaboxes = array();
116
117
		foreach ( $wp_meta_boxes[ $post_type ] as $context => $priorities ) {
0 ignored issues
show
Bug introduced by
The variable $wp_meta_boxes does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
118
			foreach ( $priorities as $priority => $_metaboxes ) {
119
				foreach ( $_metaboxes as $metabox ) {
120
					// Metabox has been removed
121
					if ( ! isset( $metabox['id'] ) ) {
122
						continue;
123
					}
124
125
					$metaboxes[ $metabox['id'] ] = (object) array(
126
						'title'    => $metabox['title'],
127
						'priority' => $priority,
128
						'context'  => $context
129
					);
130
				}
131
			}
132
		}
133
	}
134
135
}