| @@ -4,11 +4,8 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFieldGridHelper { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * @var bool | |
| 10 | - */ | |
| 11 | 8 | private $parent_li; |
| 12 | 9 | |
| 13 | 10 | /** |
| 14 | 11 | * @var int |
| @@ -30,9 +27,9 @@ | ||
| 30 | 27 | */ |
| 31 | 28 | private $active_field_size; |
| 32 | 29 | |
| 33 | 30 | /** |
| 34 | - * @var bool flagged while calling get_field_layout_class, true if classes contain frm_first class. | |
| 31 | + * @var bool $is_frm_first flagged while calling get_field_layout_class, true if classes contain frm_first class. | |
| 35 | 32 | */ |
| 36 | 33 | private $is_frm_first; |
| 37 | 34 | |
| 38 | 35 | /** |
| @@ -40,30 +37,24 @@ | ||
| 40 | 37 | */ |
| 41 | 38 | private $field; |
| 42 | 39 | |
| 43 | 40 | /** |
| 44 | - * @var FrmFieldGridHelper | |
| 41 | + * @var FrmFieldGridHelper $section_helper | |
| 45 | 42 | */ |
| 46 | 43 | private $section_helper; |
| 47 | 44 | |
| 48 | 45 | /** |
| 49 | - * @var bool | |
| 46 | + * @var bool $nested | |
| 50 | 47 | */ |
| 51 | 48 | private $nested; |
| 52 | 49 | |
| 53 | 50 | /** |
| 54 | - * @var int | |
| 51 | + * @var int $section_size | |
| 55 | 52 | */ |
| 56 | 53 | private $section_size; |
| 57 | 54 | |
| 58 | - /** | |
| 59 | - * @var bool | |
| 60 | - */ | |
| 61 | 55 | private $section_is_open = false; |
| 62 | 56 | |
| 63 | - /** | |
| 64 | - * @param bool $nested | |
| 65 | - */ | |
| 66 | 57 | public function __construct( $nested = false ) { |
| 67 | 58 | $this->parent_li = false; |
| 68 | 59 | $this->current_list_size = 0; |
| 69 | 60 | $this->current_field_count = 0; |
| @@ -89,9 +80,9 @@ | ||
| 89 | 80 | $this->section_is_open = false; |
| 90 | 81 | $this->maybe_close_section_helper(); |
| 91 | 82 | } else { |
| 92 | 83 | $this->field_layout_class = $this->get_field_layout_class(); |
| 93 | - $this->active_field_size = self::get_size_of_class( $this->field_layout_class ); | |
| 84 | + $this->active_field_size = $this->get_size_of_class( $this->field_layout_class ); | |
| 94 | 85 | } |
| 95 | 86 | |
| 96 | 87 | if ( 'divider' === $field->type && empty( $this->nested ) ) { |
| 97 | 88 | $this->section_size = $this->active_field_size; |
| @@ -157,13 +148,11 @@ | ||
| 157 | 148 | private function should_first_close_the_active_field_wrapper() { |
| 158 | 149 | if ( false === $this->parent_li || ! empty( $this->section_helper ) ) { |
| 159 | 150 | return false; |
| 160 | 151 | } |
| 161 | - | |
| 162 | 152 | if ( 'end_divider' === $this->field->type ) { |
| 163 | 153 | return false; |
| 164 | 154 | } |
| 165 | - | |
| 166 | 155 | return ! $this->can_support_current_layout() || $this->is_frm_first; |
| 167 | 156 | } |
| 168 | 157 | |
| 169 | 158 | /** |
| @@ -177,9 +166,8 @@ | ||
| 177 | 166 | } |
| 178 | 167 | |
| 179 | 168 | /** |
| 180 | 169 | * @param string $class |
| 181 | - * | |
| 182 | 170 | * @return int |
| 183 | 171 | */ |
| 184 | 172 | private static function get_size_of_class( $class ) { |
| 185 | 173 | switch ( $class ) { |
| @@ -196,11 +184,10 @@ | ||
| 196 | 184 | case 'frm_sixth': |
| 197 | 185 | return 2; |
| 198 | 186 | } |
| 199 | 187 | |
| 200 | - if ( str_starts_with( $class, 'frm' ) ) { | |
| 188 | + if ( 0 === strpos( $class, 'frm' ) ) { | |
| 201 | 189 | $substr = substr( $class, 3 ); |
| 202 | - | |
| 203 | 190 | if ( is_numeric( $substr ) ) { |
| 204 | 191 | return (int) $substr; |
| 205 | 192 | } |
| 206 | 193 | } |
| @@ -212,9 +199,9 @@ | ||
| 212 | 199 | /** |
| 213 | 200 | * @return void |
| 214 | 201 | */ |
| 215 | 202 | public function sync_list_size() { |
| 216 | - if ( empty( $this->field ) ) { | |
| 203 | + if ( ! isset( $this->field ) ) { | |
| 217 | 204 | return; |
| 218 | 205 | } |
| 219 | 206 | |
| 220 | 207 | if ( 'divider' === $this->field->type ) { |
| @@ -222,20 +209,17 @@ | ||
| 222 | 209 | } |
| 223 | 210 | |
| 224 | 211 | if ( ! empty( $this->section_helper ) ) { |
| 225 | 212 | $this->section_helper->sync_list_size(); |
| 226 | - | |
| 227 | 213 | if ( 'end_divider' === $this->field->type ) { |
| 228 | 214 | $this->maybe_close_section_helper(); |
| 229 | 215 | } |
| 230 | - | |
| 231 | 216 | return; |
| 232 | 217 | } |
| 233 | 218 | |
| 234 | 219 | if ( false !== $this->parent_li ) { |
| 235 | - ++$this->current_field_count; | |
| 220 | + $this->current_field_count ++; | |
| 236 | 221 | $this->current_list_size += $this->active_field_size; |
| 237 | - | |
| 238 | 222 | if ( 12 === $this->current_list_size ) { |
| 239 | 223 | $this->close_field_wrapper(); |
| 240 | 224 | } |
| 241 | 225 | } |
| @@ -275,13 +259,12 @@ | ||
| 275 | 259 | } |
| 276 | 260 | |
| 277 | 261 | /** |
| 278 | 262 | * @param string $class |
| 279 | - * | |
| 280 | 263 | * @return bool |
| 281 | 264 | */ |
| 282 | 265 | private function can_support_an_additional_layout( $class ) { |
| 283 | - $size = self::get_size_of_class( $class ); | |
| 266 | + $size = $this->get_size_of_class( $class ); | |
| 284 | 267 | return $this->current_list_size + $size <= 12; |
| 285 | 268 | } |
| 286 | 269 | |
| 287 | 270 | /** |