Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | class Jetpack_Tiled_Gallery_Shape { |
||
| 3 | static $shapes_used = array(); |
||
| 4 | |||
| 5 | public function __construct( $images ) { |
||
| 6 | $this->images = $images; |
||
|
0 ignored issues
–
show
|
|||
| 7 | $this->images_left = count( $images ); |
||
|
0 ignored issues
–
show
The property
images_left does not seem to exist. Did you mean images?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 8 | } |
||
| 9 | |||
| 10 | public function sum_ratios( $number_of_images = 3 ) { |
||
| 11 | return array_sum( array_slice( wp_list_pluck( $this->images, 'ratio' ), 0, $number_of_images ) ); |
||
| 12 | } |
||
| 13 | |||
| 14 | public function next_images_are_symmetric() { |
||
| 15 | return $this->images_left > 2 && $this->images[0]->ratio == $this->images[2]->ratio; |
||
| 16 | } |
||
| 17 | |||
| 18 | public function is_not_as_previous( $n = 1 ) { |
||
| 19 | return ! in_array( get_class( $this ), array_slice( self::$shapes_used, -$n ) ); |
||
| 20 | } |
||
| 21 | |||
| 22 | public function is_wide_theme() { |
||
| 23 | return Jetpack::get_content_width() > 1000; |
||
| 24 | } |
||
| 25 | |||
| 26 | public function image_is_landscape( $image ) { |
||
| 27 | return $image->ratio >= 1 && $image->ratio < 2; |
||
| 28 | } |
||
| 29 | |||
| 30 | public function image_is_portrait( $image ) { |
||
| 31 | return $image->ratio < 1; |
||
| 32 | } |
||
| 33 | |||
| 34 | public function image_is_panoramic( $image ) { |
||
| 35 | return $image->ratio >= 2; |
||
| 36 | } |
||
| 37 | |||
| 38 | public static function set_last_shape( $last_shape ) { |
||
| 39 | self::$shapes_used[] = $last_shape; |
||
| 40 | } |
||
| 41 | |||
| 42 | public static function reset_last_shape() { |
||
| 43 | self::$shapes_used = array(); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | class Jetpack_Tiled_Gallery_Three extends Jetpack_Tiled_Gallery_Shape { |
||
|
0 ignored issues
–
show
|
|||
| 48 | public $shape = array( 1, 1, 1 ); |
||
| 49 | |||
| 50 | public function is_possible() { |
||
| 51 | $ratio = $this->sum_ratios( 3 ); |
||
| 52 | $has_enough_images = $this->images_left >= 3 && ! in_array( $this->images_left, array( 4, 6 ) ); |
||
|
0 ignored issues
–
show
The property
images_left does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 53 | return $has_enough_images && $this->is_not_as_previous( 3 ) && |
||
| 54 | ( ( $ratio < 2.5 ) || ( $ratio < 5 && $this->next_images_are_symmetric() ) || $this->is_wide_theme() ); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | View Code Duplication | class Jetpack_Tiled_Gallery_Four extends Jetpack_Tiled_Gallery_Shape { |
|
|
0 ignored issues
–
show
This class seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 59 | public $shape = array( 1, 1, 1, 1 ); |
||
| 60 | |||
| 61 | public function is_possible() { |
||
| 62 | return $this->is_not_as_previous() && |
||
| 63 | ( |
||
| 64 | ( $this->sum_ratios( 4 ) < 3.5 && $this->images_left > 5 ) || |
||
| 65 | ( $this->sum_ratios( 4 ) < 7 && $this->images_left == 4 ) |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | View Code Duplication | class Jetpack_Tiled_Gallery_Five extends Jetpack_Tiled_Gallery_Shape { |
|
|
0 ignored issues
–
show
This class seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 71 | public $shape = array( 1, 1, 1, 1, 1 ); |
||
| 72 | |||
| 73 | public function is_possible() { |
||
| 74 | return $this->is_wide_theme() && $this->is_not_as_previous() && $this->sum_ratios( 5 ) < 5 && |
||
| 75 | ( $this->images_left == 5 || ( $this->images_left != 10 && $this->images_left > 6 ) ); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | View Code Duplication | class Jetpack_Tiled_Gallery_Two_One extends Jetpack_Tiled_Gallery_Shape { |
|
|
0 ignored issues
–
show
This class seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 80 | public $shape = array( 2, 1 ); |
||
| 81 | |||
| 82 | public function is_possible() { |
||
| 83 | return $this->is_not_as_previous( 3 ) && $this->images_left >= 2 && |
||
|
0 ignored issues
–
show
The property
images_left does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 84 | $this->images[2]->ratio < 1.6 && $this->images[0]->ratio >= 0.9 && $this->images[0]->ratio < 2.0 && $this->images[1]->ratio >= 0.9 && $this->images[1]->ratio < 2.0; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | View Code Duplication | class Jetpack_Tiled_Gallery_One_Two extends Jetpack_Tiled_Gallery_Shape { |
|
|
0 ignored issues
–
show
This class seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 89 | public $shape = array( 1, 2 ); |
||
| 90 | |||
| 91 | public function is_possible() { |
||
| 92 | return $this->is_not_as_previous( 3 ) && $this->images_left >= 2 && |
||
|
0 ignored issues
–
show
The property
images_left does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 93 | $this->images[0]->ratio < 1.6 && $this->images[1]->ratio >= 0.9 && $this->images[1]->ratio < 2.0 && $this->images[2]->ratio >= 0.9 && $this->images[2]->ratio < 2.0; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | class Jetpack_Tiled_Gallery_One_Three extends Jetpack_Tiled_Gallery_Shape { |
||
|
0 ignored issues
–
show
|
|||
| 98 | public $shape = array( 1, 3 ); |
||
| 99 | |||
| 100 | public function is_possible() { |
||
| 101 | return $this->is_not_as_previous( 3 ) && $this->images_left > 3 && |
||
|
0 ignored issues
–
show
The property
images_left does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 102 | $this->image_is_portrait( $this->images[0] ) && |
||
| 103 | $this->image_is_landscape( $this->images[1] ) && |
||
| 104 | $this->image_is_landscape( $this->images[2] ) && |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 105 | $this->image_is_landscape( $this->images[3] ); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | class Jetpack_Tiled_Gallery_Three_One extends Jetpack_Tiled_Gallery_Shape { |
||
|
0 ignored issues
–
show
|
|||
| 110 | public $shape = array( 3, 1 ); |
||
| 111 | |||
| 112 | public function is_possible() { |
||
| 113 | return $this->is_not_as_previous( 3 ) && $this->images_left > 3 && |
||
|
0 ignored issues
–
show
The property
images_left does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 114 | $this->image_is_portrait( $this->images[3] ) && |
||
| 115 | $this->image_is_landscape( $this->images[0] ) && |
||
| 116 | $this->image_is_landscape( $this->images[1] ) && |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 117 | $this->image_is_landscape( $this->images[2] ); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | class Jetpack_Tiled_Gallery_Panoramic extends Jetpack_Tiled_Gallery_Shape { |
||
|
0 ignored issues
–
show
|
|||
| 122 | public $shape = array( 1 ); |
||
| 123 | |||
| 124 | public function is_possible() { |
||
| 125 | return $this->image_is_panoramic( $this->images[0] ); |
||
|
0 ignored issues
–
show
The property
images does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | View Code Duplication | class Jetpack_Tiled_Gallery_Symmetric_Row extends Jetpack_Tiled_Gallery_Shape { |
|
| 130 | public $shape = array( 1, 2, 1 ); |
||
| 131 | |||
| 132 | public function is_possible() { |
||
| 133 | return $this->is_not_as_previous( 5 ) && |
||
| 134 | $this->images_left > 3 && |
||
| 135 | $this->images_left != 5 && |
||
| 136 | $this->image_is_portrait( $this->images[0] ) && |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 137 | $this->image_is_landscape( $this->images[1] ) && |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 138 | $this->image_is_landscape( $this->images[2] ) && |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 139 | $this->image_is_portrait( $this->images[3] ); |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 140 | } |
||
| 141 | } |
||
| 142 | View Code Duplication | class Jetpack_Tiled_Gallery_Reverse_Symmetric_Row extends Jetpack_Tiled_Gallery_Shape { |
|
| 143 | public $shape = array( 2, 1, 2 ); |
||
| 144 | |||
| 145 | public function is_possible() { |
||
| 146 | return $this->is_not_as_previous( 5 ) && $this->images_left > 15 && |
||
|
0 ignored issues
–
show
The property
images_left does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 147 | $this->image_is_landscape( $this->images[0] ) && |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 148 | $this->image_is_landscape( $this->images[1] ) && |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 149 | $this->image_is_portrait( $this->images[2] ) && |
||
| 150 | $this->image_is_landscape( $this->images[3] ) && |
||
| 151 | $this->image_is_landscape( $this->images[4] ); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | class Jetpack_Tiled_Gallery_Long_Symmetric_Row extends Jetpack_Tiled_Gallery_Shape { |
||
| 156 | public $shape = array( 3, 1, 3 ); |
||
| 157 | |||
| 158 | public function is_possible() { |
||
| 159 | return $this->is_not_as_previous( 5 ) && $this->images_left > 15 && |
||
|
0 ignored issues
–
show
The property
images_left does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 160 | $this->image_is_landscape( $this->images[0] ) && |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 161 | $this->image_is_landscape( $this->images[1] ) && |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 162 | $this->image_is_landscape( $this->images[2] ) && |
||
| 163 | $this->image_is_portrait( $this->images[3] ) && |
||
| 164 | $this->image_is_landscape( $this->images[4] ) && |
||
| 165 | $this->image_is_landscape( $this->images[5] ) && |
||
| 166 | $this->image_is_landscape( $this->images[6] ); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | class Jetpack_Tiled_Gallery_Three_Columns extends Jetpack_Tiled_Gallery_Shape { |
||
| 171 | public $shape = array(); |
||
| 172 | |||
| 173 | public function __construct( $images ) { |
||
| 174 | parent::__construct( $images ); |
||
| 175 | |||
| 176 | $total_ratio = $this->sum_ratios( $this->images_left ); |
||
|
0 ignored issues
–
show
The property
images_left does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 177 | $approximate_column_ratio = $total_ratio / 3; |
||
| 178 | $column_one_images = $column_two_images = $column_three_images = $sum = 0; |
||
|
0 ignored issues
–
show
$column_three_images 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 Loading history...
|
|||
| 179 | |||
| 180 | foreach ( $this->images as $image ) { |
||
|
0 ignored issues
–
show
The property
images does not seem to exist. Did you mean images_left?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 181 | if ( $sum <= $approximate_column_ratio ) { |
||
| 182 | $column_one_images++; |
||
| 183 | } |
||
| 184 | |||
| 185 | if ( $sum > $approximate_column_ratio && $sum <= 2 * $approximate_column_ratio ) { |
||
| 186 | $column_two_images++; |
||
| 187 | } |
||
| 188 | $sum += $image->ratio; |
||
| 189 | } |
||
| 190 | |||
| 191 | $column_three_images = $this->images_left - $column_two_images - $column_one_images; |
||
| 192 | |||
| 193 | if ( $column_one_images ) { |
||
| 194 | $this->shape[] = $column_one_images; |
||
| 195 | } |
||
| 196 | |||
| 197 | if ( $column_two_images ) { |
||
| 198 | $this->shape[] = $column_two_images; |
||
| 199 | } |
||
| 200 | |||
| 201 | if ( $column_three_images ) { |
||
| 202 | $this->shape[] = $column_three_images; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | public function is_possible() { |
||
| 207 | return ! empty( $this->shape ); |
||
| 208 | } |
||
| 209 | } |
||
| 210 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: