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.
Passed
Branch master (6b3106)
by Marko
06:06 queued 03:45
created

Tabify_Edit_Screen_Tabs   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Importance

Changes 8
Bugs 0 Features 1
Metric Value
eloc 62
c 8
b 0
f 1
dl 0
loc 165
rs 10
wmc 19

6 Methods

Rating   Name   Duplication   Size   Complexity  
A add_active_state_style() 0 14 3
A get_current_tab() 0 2 1
A __construct() 0 15 5
A get_tabs() 0 22 4
A get_tabs_with_container() 0 44 5
A get_tabs_current_tab_input() 0 2 1
1
<?php
2
3
class Tabify_Edit_Screen_Tabs {
4
	private $base_url = '';
5
	private $get_arg = 'tab';
6
7
	private $active = '';
8
9
	private $items  = array();
10
	private $type;
11
	private $javascript_support;
12
13
	/**
14
	 * Construct method to set up all internal properties
15
	 *
16
	 * @param array $items List of all items
17
	 * @param string $type How to be displayed: vertical of horizontal
18
	 * @param string $get_arg Which get argument should be used
19
	 * @param boolean $javascript_support With page refresh or not
20
	 *
21
	 * @since 0.1.0
22
	 */
23
	public function __construct( $items, $type = 'horizontal', $get_arg = 'tab', $javascript_support = true ) {
24
		if ( is_array( $items ) ) {
0 ignored issues
show
introduced by
The condition is_array($items) is always true.
Loading history...
25
			$this->items              = apply_filters( 'tabify_tabs', $items, $this, $type );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

25
			$this->items              = /** @scrutinizer ignore-call */ apply_filters( 'tabify_tabs', $items, $this, $type );
Loading history...
26
			$this->type               = $type;
27
			$this->get_arg            = $get_arg;
28
			$this->javascript_support = $javascript_support;
29
30
			if ( isset( $_REQUEST[ $this->get_arg ] ) ) {
31
				$this->active = sanitize_text_field( $_REQUEST[ $this->get_arg ] );
0 ignored issues
show
Bug introduced by
The function sanitize_text_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

31
				$this->active = /** @scrutinizer ignore-call */ sanitize_text_field( $_REQUEST[ $this->get_arg ] );
Loading history...
32
			}
33
34
			$this->base_url = remove_query_arg( $this->get_arg, $_SERVER["REQUEST_URI"] );
0 ignored issues
show
Bug introduced by
The function remove_query_arg was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

34
			$this->base_url = /** @scrutinizer ignore-call */ remove_query_arg( $this->get_arg, $_SERVER["REQUEST_URI"] );
Loading history...
35
36
			if ( empty( $this->active ) || ! isset( $items[ $this->active ] ) ) {
37
				$this->active = key( $items );
38
			}
39
		}
40
	}
41
42
	/**
43
	 * Get the current tab
44
	 *
45
	 * @return string Current tab name
46
	 *
47
	 * @since 0.1.0
48
	 */
49
	public function get_current_tab() {
50
		return $this->active;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->active also could return the type mixed which is incompatible with the documented return type string.
Loading history...
51
	}
52
53
	/**
54
	 * Get the HTML code of the tabs container including the tabs
55
	 *
56
	 * @return string The HTML of the tabs
57
	 *
58
	 * @since 0.1.0
59
	 */
60
	public function get_tabs_with_container() {
61
		$class = 'tabify-tabs tab-' .  $this->type;
62
63
		if ( ! $this->javascript_support ) {
64
			$class .= ' js-disabled';
65
		}
66
67
		$return  = '<div class="' . $class . '">';
68
69
70
		if ( 'horizontal' == $this->type ) {
71
			$return .= '<h2 class="nav-tab-wrapper">';
72
		}
73
		else {
74
			$return .= '<h2>';
75
		}
76
77
		$return .= $this->get_tabs_current_tab_input();
78
		$return .= $this->get_tabs();
79
80
		$return .= '</h2>';
81
82
		$return .= apply_filters( 'tabify_tabs_under', '', $this->type );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

82
		$return .= /** @scrutinizer ignore-call */ apply_filters( 'tabify_tabs_under', '', $this->type );
Loading history...
83
84
		$return .= '</div>';
85
86
		//When tabs are requested also enqueue the javascript and css code
87
		$required = array( 'jquery' );
88
89
		if ( 'post' == get_current_screen()->base ) {
0 ignored issues
show
Bug introduced by
The function get_current_screen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

89
		if ( 'post' == /** @scrutinizer ignore-call */ get_current_screen()->base ) {
Loading history...
90
			$required[] = 'postbox';
91
		}
92
93
		$suffix = SCRIPT_DEBUG ? '' : '.min';
0 ignored issues
show
Bug introduced by
The constant SCRIPT_DEBUG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
94
95
		wp_register_script( 'tabify-edit-screen', plugins_url( '/js/tabs' . $suffix . '.js', dirname( __FILE__ ) ), $required, '1.0' );
0 ignored issues
show
Bug introduced by
The function wp_register_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

95
		/** @scrutinizer ignore-call */ 
96
  wp_register_script( 'tabify-edit-screen', plugins_url( '/js/tabs' . $suffix . '.js', dirname( __FILE__ ) ), $required, '1.0' );
Loading history...
Bug introduced by
The function plugins_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

95
		wp_register_script( 'tabify-edit-screen', /** @scrutinizer ignore-call */ plugins_url( '/js/tabs' . $suffix . '.js', dirname( __FILE__ ) ), $required, '1.0' );
Loading history...
96
		wp_register_style( 'tabify-edit-screen', plugins_url( '/css/tabs' . $suffix . '.css', dirname( __FILE__ ) ), array(), '1.0' );
0 ignored issues
show
Bug introduced by
The function wp_register_style was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

96
		/** @scrutinizer ignore-call */ 
97
  wp_register_style( 'tabify-edit-screen', plugins_url( '/css/tabs' . $suffix . '.css', dirname( __FILE__ ) ), array(), '1.0' );
Loading history...
97
98
		wp_enqueue_script( 'tabify-edit-screen' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

98
		/** @scrutinizer ignore-call */ 
99
  wp_enqueue_script( 'tabify-edit-screen' );
Loading history...
99
		wp_enqueue_style( 'tabify-edit-screen' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_style was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

99
		/** @scrutinizer ignore-call */ 
100
  wp_enqueue_style( 'tabify-edit-screen' );
Loading history...
100
101
		$this->add_active_state_style();
102
103
		return $return;
104
	}
105
106
	/**
107
	 * Update switch background color for active state
108
	 *
109
	 * @since 0.9.6
110
	 */
111
	private function add_active_state_style() {
112
		global $_wp_admin_css_colors;
113
114
		$color = get_user_option('admin_color');
0 ignored issues
show
Bug introduced by
The function get_user_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

114
		$color = /** @scrutinizer ignore-call */ get_user_option('admin_color');
Loading history...
115
116
		if ( empty( $color ) || ! isset($_wp_admin_css_colors[ $color ] ) ) {
117
			$color = 'fresh';
118
		}
119
120
		$background = $_wp_admin_css_colors[$color]->colors[3];
121
122
		wp_add_inline_style(
0 ignored issues
show
Bug introduced by
The function wp_add_inline_style was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

122
		/** @scrutinizer ignore-call */ 
123
  wp_add_inline_style(
Loading history...
123
			'tabify-edit-screen',
124
			'.switch-checkbox:checked + .switch-label { background: ' . $background . '; }'
125
		);
126
	}
127
128
	/**
129
	 * Get the hidden input code for current tab
130
	 *
131
	 * @return string The HTML of the hidden input field
132
	 *
133
	 * @since 0.2.0
134
	 */
135
	public function get_tabs_current_tab_input() {
136
		return '<input type="hidden" class="current_tab" name="' . $this->get_arg . '" value="' . $this->active . '" />';
137
	}
138
139
	/**
140
	 * Get the HTML code of all the tabs
141
	 *
142
	 * @return string The HTML of the hidden input field
143
	 *
144
	 * @since 0.1.0
145
	 */
146
	private function get_tabs() {
147
		$return = '';
148
149
		foreach ( $this->items as $key => $args ) {
150
			if ( ! is_array( $args ) ) {
151
				$args = array(
152
					'title' => $args
153
				);
154
			}
155
156
			$title   = apply_filters( 'tabify_tabs_tab_title', $args['title'], $args, $this );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

156
			$title   = /** @scrutinizer ignore-call */ apply_filters( 'tabify_tabs_tab_title', $args['title'], $args, $this );
Loading history...
157
			$url     = esc_url( add_query_arg( $this->get_arg, $key, $this->base_url ) );
0 ignored issues
show
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

157
			$url     = /** @scrutinizer ignore-call */ esc_url( add_query_arg( $this->get_arg, $key, $this->base_url ) );
Loading history...
Bug introduced by
The function add_query_arg was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

157
			$url     = esc_url( /** @scrutinizer ignore-call */ add_query_arg( $this->get_arg, $key, $this->base_url ) );
Loading history...
158
			$classes = 'tabify-tab nav-tab';
159
160
			if ( $this->active == $key ) {
161
				$classes .= ' nav-tab-active';
162
			}
163
164
			$return .= '<a id="tab-' . $key . '" href="' . $url . '" class="' . $classes . '">' . $title . '</a>';
165
		}
166
167
		return $return;
168
	}
169
170
}
171