Passed
Push — master ( 554ad1...33081a )
by Paul
04:37
created

helpers.php (2 issues)

1
<?php
2
defined( 'WPINC' ) || die;
3
4
/**
5
 * @return mixed
6
 */
7
function glsr( $alias = null ) {
8
	$app = \GeminiLabs\SiteReviews\Application::load();
9
	return empty( $alias )
10
		? $app
11
		: $app->make( $alias );
12
}
13
14
/**
15
 * get_current_screen() is unreliable because it is not defined on all admin pages
16
 * @return \WP_Screen|object
17
 */
18
function glsr_current_screen() {
19
	if( function_exists( 'get_current_screen' )) {
20
		$screen = get_current_screen();
21
	}
22
	return empty( $screen )
23
		? (object)array_fill_keys( ['base', 'id', 'post_type'], null )
24
		: $screen;
25
}
26
27
/**
28
 * @return \GeminiLabs\SiteReviews\Database
29
 */
30
function glsr_db() {
31
	return glsr( 'Database' );
32
}
33
34
/**
35
 * @param mixed ...$vars
36
 * @return void
37
 */
38
function glsr_debug( ...$vars ) {
39
	if( count( $vars ) == 1 ) {
40
		$value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' );
41
		printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value );
42
	}
43
	else {
44
		echo '<div class="glsr-debug-group">';
45
		foreach( $vars as $var ) {
46
			glsr_debug( $var );
47
		}
48
		echo '</div>';
49
	}
50
}
51
52
/**
53
 * @return \GeminiLabs\SiteReviews\Modules\Logger
54
 */
55
function glsr_log() {
56
	$args = func_get_args();
57
	$context = isset( $args[1] )
58
		? $args[1]
59
		: [];
60
	$logger = glsr( 'Modules\Logger' );
61
	return empty( $args )
62
		? $logger
63
		: $logger->log( 'debug', $args[0], $context );
64
}
65
66
/**
67
 * This function prevents the taxonomy object from containing class recursion
68
 * @return void
69
 * @callback register_taxonomy() "meta_box_cb"
70
 */
71
function glsr_categories_meta_box( $post, $box ) {
72
	glsr( 'Controllers\EditorController' )->renderTaxonomyMetabox( $post, $box );
73
}
74
75
/**
76
 * @param string $option_path
77
 * @param mixed $fallback
78
 * @return string|array
79
 */
80
function glsr_get_option( $option_path = '', $fallback = '' ) {
81
	return glsr( 'Database\OptionManager' )->get( 'settings.'.$option_path, $fallback );
82
}
83
84
/**
85
 * @return array
86
 */
87
function glsr_get_options() {
88
	return glsr( 'Database\OptionManager' )->get( 'settings' );
89
}
90
91
/**
92
 * @param int $post_id
93
 * @return void|object
94
 */
95
// function glsr_get_review( $post_id ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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...
96
// 	return glsr( 'Database' )->getReview( get_post( $post_id ));
97
// }
98
99
/**
100
 * @return array
101
 */
102
// function glsr_get_reviews( array $args = array() ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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...
103
// 	return glsr( 'Database' )->getReviews( $args );
104
// }
105