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->make( $alias ) |
||
11 | : $app; |
||
12 | } |
||
13 | |||
14 | /** |
||
15 | * @return \WP_Screen|object |
||
16 | */ |
||
17 | function glsr_current_screen() { |
||
18 | if( function_exists( 'get_current_screen' )) { |
||
19 | $screen = get_current_screen(); |
||
20 | } |
||
21 | return empty( $screen ) |
||
22 | ? (object)array_fill_keys( ['base', 'id', 'post_type'], null ) |
||
23 | : $screen; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @return \GeminiLabs\SiteReviews\Database |
||
28 | */ |
||
29 | function glsr_db() { |
||
30 | return glsr( 'Database' ); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param mixed ...$vars |
||
35 | * @return void |
||
36 | */ |
||
37 | function glsr_debug( ...$vars ) { |
||
38 | if( count( $vars ) == 1 ) { |
||
39 | $value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); |
||
40 | printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); |
||
41 | } |
||
42 | else { |
||
43 | echo '<div class="glsr-debug-group">'; |
||
44 | foreach( $vars as $var ) { |
||
45 | glsr_debug( $var ); |
||
46 | } |
||
47 | echo '</div>'; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return \GeminiLabs\SiteReviews\Modules\Logger |
||
53 | */ |
||
54 | function glsr_log() { |
||
55 | $args = func_get_args(); |
||
56 | $context = isset( $args[1] ) |
||
57 | ? $args[1] |
||
58 | : []; |
||
59 | $logger = glsr( 'Modules\Logger' ); |
||
60 | return !empty( $args ) |
||
61 | ? $logger->log( 'debug', $args[0], $context ) |
||
62 | : $logger; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param string $path |
||
67 | * @param mixed $fallback |
||
68 | * @return string|array |
||
69 | */ |
||
70 | function glsr_get_option( $path = '', $fallback = '' ) { |
||
71 | return glsr( 'Database\OptionManager' )->get( 'settings.'.$path, $fallback ); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @return array |
||
76 | */ |
||
77 | function glsr_get_options() { |
||
78 | return glsr( 'Database\OptionManager' )->get( 'settings' ); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param int $post_id |
||
83 | * @return void|object |
||
84 | */ |
||
85 | // function glsr_get_review( $post_id ) { |
||
0 ignored issues
–
show
|
|||
86 | // return glsr( 'Database' )->getReview( get_post( $post_id )); |
||
87 | // } |
||
88 | |||
89 | /** |
||
90 | * @return array |
||
91 | */ |
||
92 | // 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. ![]() |
|||
93 | // return glsr( 'Database' )->getReviews( $args ); |
||
94 | // } |
||
95 |
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.