This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | class greatschools_getschools extends WP_Widget { |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
4 | |||
5 | |||
6 | /** |
||
7 | * __construct function. |
||
8 | * |
||
9 | * @access public |
||
10 | * @return void |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Adding a
@return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.
Adding a Please refer to the PHP core documentation on constructors. ![]() |
|||
11 | */ |
||
12 | public function __construct() { |
||
13 | |||
14 | parent::__construct( |
||
15 | 'getschools', |
||
16 | __( 'GreatSchools - Get List of Schools', 're-pro' ), |
||
17 | array( |
||
18 | 'description' => __( 'Get Schools', 're-pro' ), |
||
19 | ) |
||
20 | ); |
||
21 | |||
22 | } |
||
23 | |||
24 | /** |
||
25 | * widget function. |
||
26 | * |
||
27 | * @access public |
||
28 | * @param mixed $args |
||
29 | * @param mixed $instance |
||
30 | * @return void |
||
31 | */ |
||
32 | public function widget( $args, $instance ) { |
||
33 | |||
34 | $greatschools_title = !empty( $instance['greatschools_title'] ) ? $instance['greatschools_title'] : ''; |
||
35 | $greatschools_state = !empty( $instance['greatschools_state'] ) ? $instance['greatschools_state'] : ''; |
||
36 | $greatschools_city = !empty( $instance['greatschools_city'] ) ? $instance['greatschools_city'] : ''; |
||
37 | |||
38 | // Call our API. |
||
39 | $repro_settings = get_option( 'repro_settings' ); |
||
40 | $greatschools_apikey = $repro_settings['greatschools_apikey']; |
||
41 | |||
42 | $greatschools = new GreatSchoolsAPI( $greatschools_apikey ); |
||
43 | $schools = $greatschools->get_schools( $greatschools_state,$greatschools_city ); |
||
0 ignored issues
–
show
Are you sure the assignment to
$schools is correct as $greatschools->get_schoo...te, $greatschools_city) (which targets GreatSchoolsAPI::get_schools() ) 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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
44 | |||
45 | |||
46 | |||
47 | echo $args['before_widget']; |
||
48 | |||
49 | echo $args['before_title'] . esc_attr( $greatschools_title ) . $args['after_title']; |
||
50 | |||
51 | // var_dump($schools); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% 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. ![]() |
|||
52 | |||
53 | foreach($schools as $school) { |
||
0 ignored issues
–
show
|
|||
54 | |||
55 | foreach($school as $school_item) { |
||
56 | |||
57 | $name = $school_item['name']; |
||
58 | $type =$school_item['type']; |
||
0 ignored issues
–
show
$type is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
59 | $grade_range = $school_item['gradeRange']; |
||
0 ignored issues
–
show
$grade_range is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
60 | $state = $school_item['state']; |
||
0 ignored issues
–
show
$state is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
61 | $city = $school_item['city']; |
||
0 ignored issues
–
show
$city is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
62 | $overview_link = $school_item['overviewLink']; |
||
63 | |||
64 | echo '<li><a href="'.$overview_link.'" rel="nofollow">' . $name . '</a></li>'; |
||
65 | } |
||
66 | |||
67 | |||
68 | } |
||
69 | |||
70 | echo $args['after_widget']; |
||
71 | |||
72 | } |
||
73 | |||
74 | public function form( $instance ) { |
||
75 | |||
76 | // Set default values |
||
77 | $instance = wp_parse_args( (array) $instance, array( |
||
78 | 'greatschools_title' => '', |
||
79 | 'greatschools_state' => '', |
||
80 | 'greatschools_city' => '', |
||
81 | ) ); |
||
82 | |||
83 | // Retrieve an existing value from the database |
||
84 | $greatschools_title = !empty( $instance['greatschools_title'] ) ? $instance['greatschools_title'] : ''; |
||
85 | $greatschools_state = !empty( $instance['greatschools_state'] ) ? $instance['greatschools_state'] : ''; |
||
86 | $greatschools_city = !empty( $instance['greatschools_city'] ) ? $instance['greatschools_city'] : ''; |
||
87 | |||
88 | // Form fields |
||
89 | echo '<p>'; |
||
90 | echo ' <label for="' . $this->get_field_id( 'greatschools_title' ) . '" class="greatschools_title_label">' . __( 'Title', 're-pro' ) . '</label>'; |
||
91 | echo ' <input type="text" id="' . $this->get_field_id( 'greatschools_title' ) . '" name="' . $this->get_field_name( 'greatschools_title' ) . '" class="widefat" placeholder="' . esc_attr__( '', 're-pro' ) . '" value="' . esc_attr( $greatschools_title ) . '">'; |
||
92 | echo ' <span class="description">' . __( 'Title', 're-pro' ) . '</span>'; |
||
93 | echo '</p>'; |
||
94 | |||
95 | echo '<p>'; |
||
96 | echo ' <label for="' . $this->get_field_id( 'greatschools_state' ) . '" class="greatschools_state_label">' . __( 'State', 're-pro' ) . '</label>'; |
||
97 | echo ' <input type="text" id="' . $this->get_field_id( 'greatschools_state' ) . '" name="' . $this->get_field_name( 'greatschools_state' ) . '" class="widefat" placeholder="' . esc_attr__( '', 're-pro' ) . '" value="' . esc_attr( $greatschools_state ) . '">'; |
||
98 | echo ' <span class="description">' . __( 'State', 're-pro' ) . '</span>'; |
||
99 | echo '</p>'; |
||
100 | |||
101 | echo '<p>'; |
||
102 | echo ' <label for="' . $this->get_field_id( 'greatschools_city' ) . '" class="greatschools_city_label">' . __( 'City', 're-pro' ) . '</label>'; |
||
103 | echo ' <input type="text" id="' . $this->get_field_id( 'greatschools_city' ) . '" name="' . $this->get_field_name( 'greatschools_city' ) . '" class="widefat" placeholder="' . esc_attr__( '', 're-pro' ) . '" value="' . esc_attr( $greatschools_city ) . '">'; |
||
104 | echo ' <span class="description">' . __( 'City', 're-pro' ) . '</span>'; |
||
105 | echo '</p>'; |
||
106 | |||
107 | } |
||
108 | |||
109 | public function update( $new_instance, $old_instance ) { |
||
110 | |||
111 | $instance = $old_instance; |
||
112 | |||
113 | $instance['greatschools_title'] = !empty( $new_instance['greatschools_title'] ) ? strip_tags( $new_instance['greatschools_title'] ) : ''; |
||
114 | $instance['greatschools_state'] = !empty( $new_instance['greatschools_state'] ) ? strip_tags( $new_instance['greatschools_state'] ) : ''; |
||
115 | $instance['greatschools_city'] = !empty( $new_instance['greatschools_city'] ) ? strip_tags( $new_instance['greatschools_city'] ) : ''; |
||
116 | |||
117 | return $instance; |
||
118 | |||
119 | } |
||
120 | |||
121 | } |
||
122 | |||
123 | function greatschools_register_widgets() { |
||
124 | |||
125 | $repro_settings = get_option( 'repro_settings' ); |
||
126 | $greatschools_apikey = $repro_settings['greatschools_apikey']; |
||
127 | |||
128 | if ( ! empty( $greatschools_apikey) ) { |
||
129 | register_widget( 'greatschools_getschools' ); |
||
130 | } |
||
131 | } |
||
132 | add_action( 'widgets_init', 'greatschools_register_widgets' ); |
||
133 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.