@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | 'is_setting' => false, |
| 27 | 27 | 'is_valid' => true, |
| 28 | 28 | 'path' => '', |
| 29 | - ]); |
|
| 29 | + ] ); |
|
| 30 | 30 | $this->normalize(); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | return glsr( Template::class )->build( 'partials/form/field', [ |
| 73 | 73 | 'context' => [ |
| 74 | 74 | 'class' => $this->getFieldClass(), |
| 75 | - 'field' => glsr( Builder::class )->{$this->field['type']}( $this->field ), |
|
| 75 | + 'field' => glsr( Builder::class )->{$this->field['type']}($this->field), |
|
| 76 | 76 | ], |
| 77 | - ]); |
|
| 77 | + ] ); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -85,10 +85,10 @@ discard block |
||
| 85 | 85 | return glsr( Template::class )->build( 'partials/form/table-row', [ |
| 86 | 86 | 'context' => [ |
| 87 | 87 | 'class' => $this->getFieldClass(), |
| 88 | - 'field' => glsr( Builder::class )->{$this->field['type']}( $this->field ), |
|
| 88 | + 'field' => glsr( Builder::class )->{$this->field['type']}($this->field), |
|
| 89 | 89 | 'label' => glsr( Builder::class )->label( $this->field['legend'], ['for' => $this->field['id']] ), |
| 90 | 90 | ], |
| 91 | - ]); |
|
| 91 | + ] ); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -97,16 +97,16 @@ discard block |
||
| 97 | 97 | protected function buildSettingMultiField() |
| 98 | 98 | { |
| 99 | 99 | $dependsOn = $this->getFieldDependsOn(); |
| 100 | - unset( $this->field['data-depends'] ); |
|
| 100 | + unset($this->field['data-depends']); |
|
| 101 | 101 | return glsr( Template::class )->build( 'partials/form/table-row-multiple', [ |
| 102 | 102 | 'context' => [ |
| 103 | 103 | 'class' => $this->getFieldClass(), |
| 104 | 104 | 'depends_on' => $dependsOn, |
| 105 | - 'field' => glsr( Builder::class )->{$this->field['type']}( $this->field ), |
|
| 105 | + 'field' => glsr( Builder::class )->{$this->field['type']}($this->field), |
|
| 106 | 106 | 'label' => glsr( Builder::class )->label( $this->field['legend'], ['for' => $this->field['id']] ), |
| 107 | 107 | 'legend' => $this->field['legend'], |
| 108 | 108 | ], |
| 109 | - ]); |
|
| 109 | + ] ); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | if( $this->field['is_hidden'] ) { |
| 119 | 119 | $classes[] = 'hidden'; |
| 120 | 120 | } |
| 121 | - if( !empty( $this->field['required'] )) { |
|
| 121 | + if( !empty($this->field['required']) ) { |
|
| 122 | 122 | $classes[] = 'glsr-required'; |
| 123 | 123 | } |
| 124 | 124 | return implode( ' ', $classes ); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | protected function getFieldDependsOn() |
| 131 | 131 | { |
| 132 | - return !empty( $this->field['data-depends'] ) |
|
| 132 | + return !empty($this->field['data-depends']) |
|
| 133 | 133 | ? $this->field['data-depends'] |
| 134 | 134 | : ''; |
| 135 | 135 | } |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | 'name', 'type', |
| 155 | 155 | ]; |
| 156 | 156 | foreach( $requiredValues as $value ) { |
| 157 | - if( isset( $this->field[$value] ))continue; |
|
| 157 | + if( isset($this->field[$value]) )continue; |
|
| 158 | 158 | $missingValues[] = $value; |
| 159 | 159 | $this->field['is_valid'] = false; |
| 160 | 160 | } |
| 161 | - if( !empty( $missingValues )) { |
|
| 161 | + if( !empty($missingValues) ) { |
|
| 162 | 162 | glsr_log() |
| 163 | - ->warning( 'Field is missing: '.implode( ', ', $missingValues )) |
|
| 163 | + ->warning( 'Field is missing: '.implode( ', ', $missingValues ) ) |
|
| 164 | 164 | ->info( $this->field ); |
| 165 | 165 | } |
| 166 | 166 | return $this->field['is_valid']; |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | if( !$this->isFieldValid() )return; |
| 175 | 175 | $this->field['path'] = $this->field['name']; |
| 176 | 176 | $className = glsr( Helper::class )->buildClassName( $this->field['type'], __NAMESPACE__.'\Fields' ); |
| 177 | - if( class_exists( $className )) { |
|
| 177 | + if( class_exists( $className ) ) { |
|
| 178 | 178 | $this->field = array_merge( |
| 179 | 179 | wp_parse_args( $this->field, $className::defaults() ), |
| 180 | 180 | $className::required() |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | protected function normalizeId() |
| 192 | 192 | { |
| 193 | - if( isset( $this->field['id'] ) || $this->field['is_raw'] )return; |
|
| 193 | + if( isset($this->field['id']) || $this->field['is_raw'] )return; |
|
| 194 | 194 | $this->field['id'] = glsr( Helper::class )->convertPathToId( |
| 195 | 195 | $this->field['path'], |
| 196 | 196 | $this->getFieldPrefix() |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | protected function determineIfMulti() |
| 216 | 216 | { |
| 217 | - if( !in_array( $this->field['type'], static::MULTI_FIELD_TYPES ))return; |
|
| 217 | + if( !in_array( $this->field['type'], static::MULTI_FIELD_TYPES ) )return; |
|
| 218 | 218 | $this->field['is_multi'] = true; |
| 219 | 219 | } |
| 220 | 220 | } |
@@ -43,7 +43,9 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function build() |
| 45 | 45 | { |
| 46 | - if( !$this->field['is_valid'] )return; |
|
| 46 | + if( !$this->field['is_valid'] ) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 47 | 49 | if( $this->field['is_raw'] ) { |
| 48 | 50 | return glsr( Builder::class )->hidden( $this->field ); |
| 49 | 51 | } |
@@ -154,7 +156,9 @@ discard block |
||
| 154 | 156 | 'name', 'type', |
| 155 | 157 | ]; |
| 156 | 158 | foreach( $requiredValues as $value ) { |
| 157 | - if( isset( $this->field[$value] ))continue; |
|
| 159 | + if( isset( $this->field[$value] )) { |
|
| 160 | + continue; |
|
| 161 | + } |
|
| 158 | 162 | $missingValues[] = $value; |
| 159 | 163 | $this->field['is_valid'] = false; |
| 160 | 164 | } |
@@ -171,7 +175,9 @@ discard block |
||
| 171 | 175 | */ |
| 172 | 176 | protected function normalize() |
| 173 | 177 | { |
| 174 | - if( !$this->isFieldValid() )return; |
|
| 178 | + if( !$this->isFieldValid() ) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 175 | 181 | $this->field['path'] = $this->field['name']; |
| 176 | 182 | $className = glsr( Helper::class )->buildClassName( $this->field['type'], __NAMESPACE__.'\Fields' ); |
| 177 | 183 | if( class_exists( $className )) { |
@@ -190,7 +196,9 @@ discard block |
||
| 190 | 196 | */ |
| 191 | 197 | protected function normalizeId() |
| 192 | 198 | { |
| 193 | - if( isset( $this->field['id'] ) || $this->field['is_raw'] )return; |
|
| 199 | + if( isset( $this->field['id'] ) || $this->field['is_raw'] ) { |
|
| 200 | + return; |
|
| 201 | + } |
|
| 194 | 202 | $this->field['id'] = glsr( Helper::class )->convertPathToId( |
| 195 | 203 | $this->field['path'], |
| 196 | 204 | $this->getFieldPrefix() |
@@ -214,7 +222,9 @@ discard block |
||
| 214 | 222 | */ |
| 215 | 223 | protected function determineIfMulti() |
| 216 | 224 | { |
| 217 | - if( !in_array( $this->field['type'], static::MULTI_FIELD_TYPES ))return; |
|
| 225 | + if( !in_array( $this->field['type'], static::MULTI_FIELD_TYPES )) { |
|
| 226 | + return; |
|
| 227 | + } |
|
| 218 | 228 | $this->field['is_multi'] = true; |
| 219 | 229 | } |
| 220 | 230 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | : $this->$method( $id ); |
| 24 | 24 | return glsr( Template::class )->build( 'pages/settings/'.$id, [ |
| 25 | 25 | 'context' => $context, |
| 26 | - ]); |
|
| 26 | + ] ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | protected function getFieldDefault( array $field ) |
| 33 | 33 | { |
| 34 | - return isset( $field['default'] ) |
|
| 34 | + return isset($field['default']) |
|
| 35 | 35 | ? $field['default'] |
| 36 | 36 | : ''; |
| 37 | 37 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | protected function getSettingFields( $path ) |
| 43 | 43 | { |
| 44 | 44 | $settings = glsr( DefaultsManager::class )->settings(); |
| 45 | - return array_filter( $settings, function( $key ) use( $path ) { |
|
| 45 | + return array_filter( $settings, function( $key ) use($path) { |
|
| 46 | 46 | return glsr( Helper::class )->startsWith( $path, $key ); |
| 47 | 47 | }, ARRAY_FILTER_USE_KEY ); |
| 48 | 48 | } |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | protected function getTemplateContext( $id ) |
| 55 | 55 | { |
| 56 | - $fields = $this->getSettingFields( $this->normalizeSettingPath( $id )); |
|
| 56 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
| 57 | 57 | $rows = ''; |
| 58 | 58 | foreach( $fields as $name => $field ) { |
| 59 | 59 | $field = wp_parse_args( $field, [ |
| 60 | 60 | 'is_setting' => true, |
| 61 | 61 | 'name' => $name, |
| 62 | - ]); |
|
| 63 | - $rows.= new Field( $this->normalize( $field )); |
|
| 62 | + ] ); |
|
| 63 | + $rows .= new Field( $this->normalize( $field ) ); |
|
| 64 | 64 | } |
| 65 | 65 | return [ |
| 66 | 66 | 'rows' => $rows, |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | protected function getTemplateContextForTranslations() |
| 74 | 74 | { |
| 75 | 75 | $translations = glsr( Translator::class )->renderAll(); |
| 76 | - $class = empty( $translations ) |
|
| 76 | + $class = empty($translations) |
|
| 77 | 77 | ? 'glsr-hidden' |
| 78 | 78 | : ''; |
| 79 | 79 | return [ |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $path, |
| 95 | 95 | glsr( Helper::class )->getPathValue( $path, glsr()->defaults ) |
| 96 | 96 | ); |
| 97 | - if( is_array( $expectedValue )) { |
|
| 97 | + if( is_array( $expectedValue ) ) { |
|
| 98 | 98 | return !in_array( $optionValue, $expectedValue ); |
| 99 | 99 | } |
| 100 | 100 | return $optionValue != $expectedValue; |
@@ -116,13 +116,13 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | protected function normalizeDependsOn( array $field ) |
| 118 | 118 | { |
| 119 | - if( !empty( $field['depends_on'] ) && is_array( $field['depends_on'] )) { |
|
| 119 | + if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) { |
|
| 120 | 120 | $path = key( $field['depends_on'] ); |
| 121 | 121 | $expectedValue = $field['depends_on'][$path]; |
| 122 | - $field['data-depends'] = json_encode([ |
|
| 122 | + $field['data-depends'] = json_encode( [ |
|
| 123 | 123 | 'name' => glsr( Helper::class )->convertPathToName( $path, OptionManager::databaseKey() ), |
| 124 | 124 | 'value' => $expectedValue, |
| 125 | - ], JSON_HEX_APOS|JSON_HEX_QUOT ); |
|
| 125 | + ], JSON_HEX_APOS | JSON_HEX_QUOT ); |
|
| 126 | 126 | $field['is_hidden'] = $this->isFieldHidden( $path, $expectedValue ); |
| 127 | 127 | } |
| 128 | 128 | return $field; |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | protected function normalizeLabelAndLegend( array $field ) |
| 135 | 135 | { |
| 136 | - if( isset( $field['label'] )) { |
|
| 136 | + if( isset($field['label']) ) { |
|
| 137 | 137 | $field['legend'] = $field['label']; |
| 138 | - unset( $field['label'] ); |
|
| 138 | + unset($field['label']); |
|
| 139 | 139 | } |
| 140 | 140 | else { |
| 141 | 141 | $field['is_valid'] = false; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | protected function normalizeValue( array $field ) |
| 151 | 151 | { |
| 152 | - if( !isset( $field['value'] )) { |
|
| 152 | + if( !isset($field['value']) ) { |
|
| 153 | 153 | $field['value'] = glsr( OptionManager::class )->get( |
| 154 | 154 | $field['name'], |
| 155 | 155 | $this->getFieldDefault( $field ) |
@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | public function buildClassName( $name, $path = '' ) |
| 16 | 16 | { |
| 17 | - $className = array_map( 'strtolower', (array)preg_split( '/[-_]/', $name )); |
|
| 17 | + $className = array_map( 'strtolower', (array)preg_split( '/[-_]/', $name ) ); |
|
| 18 | 18 | $className = array_map( 'ucfirst', $className ); |
| 19 | 19 | $className = implode( '', $className ); |
| 20 | 20 | $path = ltrim( str_replace( __NAMESPACE__, '', $path ), '\\' ); |
| 21 | - return !empty( $path ) |
|
| 21 | + return !empty($path) |
|
| 22 | 22 | ? __NAMESPACE__.'\\'.$path.'\\'.$className |
| 23 | 23 | : $className; |
| 24 | 24 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function buildMethodName( $name, $prefix = '' ) |
| 32 | 32 | { |
| 33 | - return lcfirst( $prefix.$this->buildClassName( $name )); |
|
| 33 | + return lcfirst( $prefix.$this->buildClassName( $name ) ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function buildPropertyName( $name ) |
| 41 | 41 | { |
| 42 | - return lcfirst( $this->buildClassName( $name )); |
|
| 42 | + return lcfirst( $this->buildClassName( $name ) ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function convertPathToId( $path, $prefix = '' ) |
| 72 | 72 | { |
| 73 | - return str_replace( ['[', ']'], ['-', ''], $this->convertPathToName( $path, $prefix )); |
|
| 73 | + return str_replace( ['[', ']'], ['-', ''], $this->convertPathToName( $path, $prefix ) ); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | $levels = explode( '.', $path ); |
| 83 | 83 | return array_reduce( $levels, function( $result, $value ) { |
| 84 | - return $result.= '['.$value.']'; |
|
| 84 | + return $result .= '['.$value.']'; |
|
| 85 | 85 | }, $prefix ); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function dashCase( $string ) |
| 93 | 93 | { |
| 94 | - return str_replace( '_', '-', $this->snakeCase( $string )); |
|
| 94 | + return str_replace( '_', '-', $this->snakeCase( $string ) ); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -117,13 +117,13 @@ discard block |
||
| 117 | 117 | $result = []; |
| 118 | 118 | foreach( $array as $key => $value ) { |
| 119 | 119 | $newKey = ltrim( $prefix.'.'.$key, '.' ); |
| 120 | - if( $this->isIndexedFlatArray( $value )) { |
|
| 120 | + if( $this->isIndexedFlatArray( $value ) ) { |
|
| 121 | 121 | if( $flattenValue ) { |
| 122 | 122 | $value = '['.implode( ', ', $value ).']'; |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | - else if( is_array( $value )) { |
|
| 126 | - $result = array_merge( $result, $this->flattenArray( $value, $flattenValue, $newKey )); |
|
| 125 | + else if( is_array( $value ) ) { |
|
| 126 | + $result = array_merge( $result, $this->flattenArray( $value, $flattenValue, $newKey ) ); |
|
| 127 | 127 | continue; |
| 128 | 128 | } |
| 129 | 129 | $result[$newKey] = $value; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | Whip::IPV4 => $cloudflareIps['v4'], |
| 143 | 143 | Whip::IPV6 => $cloudflareIps['v6'], |
| 144 | 144 | ], |
| 145 | - ]))->getValidIpAddress(); |
|
| 145 | + ] ))->getValidIpAddress(); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | { |
| 156 | 156 | $keys = explode( '.', $path ); |
| 157 | 157 | foreach( $keys as $key ) { |
| 158 | - if( !isset( $values[$key] )) { |
|
| 158 | + if( !isset($values[$key]) ) { |
|
| 159 | 159 | return $fallback; |
| 160 | 160 | } |
| 161 | 161 | $values = $values[$key]; |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | public function isIndexedArray( $array ) |
| 171 | 171 | { |
| 172 | - if( !is_array( $array )) { |
|
| 172 | + if( !is_array( $array ) ) { |
|
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | $current = 0; |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | public function isIndexedFlatArray( $array ) |
| 190 | 190 | { |
| 191 | - if( !is_array( $array ) || array_filter( $array, 'is_array' )) { |
|
| 191 | + if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) { |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | return $this->isIndexedArray( $array ); |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | public function prefixString( $string, $prefix = '' ) |
| 203 | 203 | { |
| 204 | - return $prefix.str_replace( $prefix, '', trim( $string )); |
|
| 204 | + return $prefix.str_replace( $prefix, '', trim( $string ) ); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | public function snakeCase( $string ) |
| 249 | 249 | { |
| 250 | - if( !ctype_lower( $string )) { |
|
| 250 | + if( !ctype_lower( $string ) ) { |
|
| 251 | 251 | $string = preg_replace( '/\s+/u', '', $string ); |
| 252 | 252 | $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
| 253 | 253 | $string = mb_strtolower( $string, 'UTF-8' ); |
@@ -262,6 +262,6 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | public function startsWith( $needle, $haystack ) |
| 264 | 264 | { |
| 265 | - return substr( $haystack, 0, strlen( $needle )) === $needle; |
|
| 265 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
| 266 | 266 | } |
| 267 | 267 | } |