@@ -10,15 +10,15 @@ |
||
| 10 | 10 | /** |
| 11 | 11 | * @return void |
| 12 | 12 | */ |
| 13 | - public function handle(Command $command) |
|
| 13 | + public function handle( Command $command ) |
|
| 14 | 14 | { |
| 15 | - foreach ($command->shortcodes as $shortcode) { |
|
| 16 | - $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes'); |
|
| 17 | - if (!class_exists($shortcodeClass)) { |
|
| 18 | - glsr_log()->error(sprintf('Class missing (%s)', $shortcodeClass)); |
|
| 15 | + foreach( $command->shortcodes as $shortcode ) { |
|
| 16 | + $shortcodeClass = Helper::buildClassName( $shortcode.'-shortcode', 'Shortcodes' ); |
|
| 17 | + if( !class_exists( $shortcodeClass ) ) { |
|
| 18 | + glsr_log()->error( sprintf( 'Class missing (%s)', $shortcodeClass ) ); |
|
| 19 | 19 | continue; |
| 20 | 20 | } |
| 21 | - add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']); |
|
| 21 | + add_shortcode( $shortcode, [glsr( $shortcodeClass ), 'buildShortcode'] ); |
|
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | } |
@@ -10,18 +10,18 @@ |
||
| 10 | 10 | /** |
| 11 | 11 | * @return void |
| 12 | 12 | */ |
| 13 | - public function handle(Command $command) |
|
| 13 | + public function handle( Command $command ) |
|
| 14 | 14 | { |
| 15 | - foreach ($command->popups as $slug => $label) { |
|
| 16 | - $buttonClass = Helper::buildClassName($slug.'-popup', 'Shortcodes'); |
|
| 17 | - if (!class_exists($buttonClass)) { |
|
| 18 | - glsr_log()->error(sprintf('Class missing (%s)', $buttonClass)); |
|
| 15 | + foreach( $command->popups as $slug => $label ) { |
|
| 16 | + $buttonClass = Helper::buildClassName( $slug.'-popup', 'Shortcodes' ); |
|
| 17 | + if( !class_exists( $buttonClass ) ) { |
|
| 18 | + glsr_log()->error( sprintf( 'Class missing (%s)', $buttonClass ) ); |
|
| 19 | 19 | continue; |
| 20 | 20 | } |
| 21 | - $shortcode = glsr($buttonClass)->register($slug, [ |
|
| 21 | + $shortcode = glsr( $buttonClass )->register( $slug, [ |
|
| 22 | 22 | 'label' => $label, |
| 23 | 23 | 'title' => $label, |
| 24 | - ]); |
|
| 24 | + ] ); |
|
| 25 | 25 | glsr()->mceShortcodes[$slug] = $shortcode->properties; |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | public function defaults() |
| 13 | 13 | { |
| 14 | 14 | $settings = $this->settings(); |
| 15 | - $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
| 16 | - return wp_parse_args($defaults, [ |
|
| 15 | + $defaults = (array)array_combine( array_keys( $settings ), glsr_array_column( $settings, 'default' ) ); |
|
| 16 | + return wp_parse_args( $defaults, [ |
|
| 17 | 17 | 'version' => '', |
| 18 | 18 | 'version_upgraded_from' => '', |
| 19 | - ]); |
|
| 19 | + ] ); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function get() |
| 26 | 26 | { |
| 27 | - return Arr::convertDotNotationArray($this->defaults()); |
|
| 27 | + return Arr::convertDotNotationArray( $this->defaults() ); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function set() |
| 34 | 34 | { |
| 35 | - $settings = glsr(OptionManager::class)->all(); |
|
| 36 | - $currentSettings = Arr::removeEmptyArrayValues($settings); |
|
| 37 | - $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
| 38 | - $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
| 39 | - update_option(OptionManager::databaseKey(), $updatedSettings); |
|
| 35 | + $settings = glsr( OptionManager::class )->all(); |
|
| 36 | + $currentSettings = Arr::removeEmptyArrayValues( $settings ); |
|
| 37 | + $defaultSettings = array_replace_recursive( $this->get(), $currentSettings ); |
|
| 38 | + $updatedSettings = array_replace_recursive( $settings, $defaultSettings ); |
|
| 39 | + update_option( OptionManager::databaseKey(), $updatedSettings ); |
|
| 40 | 40 | return $defaultSettings; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -45,17 +45,17 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function settings() |
| 47 | 47 | { |
| 48 | - $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
| 49 | - return $this->normalize($settings); |
|
| 48 | + $settings = apply_filters( 'site-reviews/addon/settings', glsr()->config( 'settings' ) ); |
|
| 49 | + return $this->normalize( $settings ); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | - protected function normalize(array $settings) |
|
| 55 | + protected function normalize( array $settings ) |
|
| 56 | 56 | { |
| 57 | - array_walk($settings, function (&$setting) { |
|
| 58 | - if (isset($setting['default'])) { |
|
| 57 | + array_walk( $settings, function( &$setting ) { |
|
| 58 | + if( isset($setting['default']) ) { |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | 61 | $setting['default'] = ''; |
@@ -20,31 +20,31 @@ discard block |
||
| 20 | 20 | * @param string $id |
| 21 | 21 | * @return string |
| 22 | 22 | */ |
| 23 | - public function buildFields($id) |
|
| 23 | + public function buildFields( $id ) |
|
| 24 | 24 | { |
| 25 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
| 26 | - $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
| 27 | - $data = !method_exists($this, $method) |
|
| 28 | - ? $this->getTemplateData($id) |
|
| 29 | - : $this->$method($id); |
|
| 30 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
| 25 | + $this->settings = glsr( DefaultsManager::class )->settings(); |
|
| 26 | + $method = Helper::buildMethodName( $id, 'getTemplateDataFor' ); |
|
| 27 | + $data = !method_exists( $this, $method ) |
|
| 28 | + ? $this->getTemplateData( $id ) |
|
| 29 | + : $this->$method( $id ); |
|
| 30 | + return glsr( Template::class )->build( 'pages/settings/'.$id, $data ); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @return string |
| 35 | 35 | */ |
| 36 | - protected function getFieldDefault(array $field) |
|
| 36 | + protected function getFieldDefault( array $field ) |
|
| 37 | 37 | { |
| 38 | - return Arr::get($field, 'default'); |
|
| 38 | + return Arr::get( $field, 'default' ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @return string |
| 43 | 43 | */ |
| 44 | - protected function getFieldNameForDependsOn($path) |
|
| 44 | + protected function getFieldNameForDependsOn( $path ) |
|
| 45 | 45 | { |
| 46 | - $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
| 47 | - return $this->isMultiDependency($path) |
|
| 46 | + $fieldName = Str::convertPathToName( $path, OptionManager::databaseKey() ); |
|
| 47 | + return $this->isMultiDependency( $path ) |
|
| 48 | 48 | ? $fieldName.'[]' |
| 49 | 49 | : $fieldName; |
| 50 | 50 | } |
@@ -52,25 +52,25 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | - protected function getSettingFields($path) |
|
| 55 | + protected function getSettingFields( $path ) |
|
| 56 | 56 | { |
| 57 | - return array_filter($this->settings, function ($key) use ($path) { |
|
| 58 | - return Str::startsWith($path, $key); |
|
| 59 | - }, ARRAY_FILTER_USE_KEY); |
|
| 57 | + return array_filter( $this->settings, function( $key ) use ($path) { |
|
| 58 | + return Str::startsWith( $path, $key ); |
|
| 59 | + }, ARRAY_FILTER_USE_KEY ); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * @return string |
| 64 | 64 | */ |
| 65 | - protected function getSettingRows(array $fields) |
|
| 65 | + protected function getSettingRows( array $fields ) |
|
| 66 | 66 | { |
| 67 | 67 | $rows = ''; |
| 68 | - foreach ($fields as $name => $field) { |
|
| 69 | - $field = wp_parse_args($field, [ |
|
| 68 | + foreach( $fields as $name => $field ) { |
|
| 69 | + $field = wp_parse_args( $field, [ |
|
| 70 | 70 | 'is_setting' => true, |
| 71 | 71 | 'name' => $name, |
| 72 | - ]); |
|
| 73 | - $rows.= new Field($this->normalize($field)); |
|
| 72 | + ] ); |
|
| 73 | + $rows .= new Field( $this->normalize( $field ) ); |
|
| 74 | 74 | } |
| 75 | 75 | return $rows; |
| 76 | 76 | } |
@@ -79,12 +79,12 @@ discard block |
||
| 79 | 79 | * @param string $id |
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | - protected function getTemplateData($id) |
|
| 82 | + protected function getTemplateData( $id ) |
|
| 83 | 83 | { |
| 84 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 84 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
| 85 | 85 | return [ |
| 86 | 86 | 'context' => [ |
| 87 | - 'rows' => $this->getSettingRows($fields), |
|
| 87 | + 'rows' => $this->getSettingRows( $fields ), |
|
| 88 | 88 | ], |
| 89 | 89 | ]; |
| 90 | 90 | } |
@@ -93,19 +93,19 @@ discard block |
||
| 93 | 93 | * @param string $id |
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | - protected function getTemplateDataForAddons($id) |
|
| 96 | + protected function getTemplateDataForAddons( $id ) |
|
| 97 | 97 | { |
| 98 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 99 | - $settings = Arr::convertDotNotationArray($fields); |
|
| 100 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
| 98 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
| 99 | + $settings = Arr::convertDotNotationArray( $fields ); |
|
| 100 | + $settingKeys = array_keys( $settings['settings']['addons'] ); |
|
| 101 | 101 | $results = []; |
| 102 | - foreach ($settingKeys as $key) { |
|
| 103 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
| 104 | - return Str::startsWith('settings.addons.'.$key, $path); |
|
| 105 | - }, ARRAY_FILTER_USE_KEY); |
|
| 106 | - $results[$key] = $this->getSettingRows($addonFields); |
|
| 102 | + foreach( $settingKeys as $key ) { |
|
| 103 | + $addonFields = array_filter( $fields, function( $path ) use ($key) { |
|
| 104 | + return Str::startsWith( 'settings.addons.'.$key, $path ); |
|
| 105 | + }, ARRAY_FILTER_USE_KEY ); |
|
| 106 | + $results[$key] = $this->getSettingRows( $addonFields ); |
|
| 107 | 107 | } |
| 108 | - ksort($results); |
|
| 108 | + ksort( $results ); |
|
| 109 | 109 | return [ |
| 110 | 110 | 'settings' => $results, |
| 111 | 111 | ]; |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | * @param string $id |
| 116 | 116 | * @return array |
| 117 | 117 | */ |
| 118 | - protected function getTemplateDataForLicenses($id) |
|
| 118 | + protected function getTemplateDataForLicenses( $id ) |
|
| 119 | 119 | { |
| 120 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 121 | - ksort($fields); |
|
| 120 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
| 121 | + ksort( $fields ); |
|
| 122 | 122 | return [ |
| 123 | 123 | 'context' => [ |
| 124 | - 'rows' => $this->getSettingRows($fields), |
|
| 124 | + 'rows' => $this->getSettingRows( $fields ), |
|
| 125 | 125 | ], |
| 126 | 126 | ]; |
| 127 | 127 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | protected function getTemplateDataForTranslations() |
| 133 | 133 | { |
| 134 | - $translations = glsr(Translation::class)->renderAll(); |
|
| 134 | + $translations = glsr( Translation::class )->renderAll(); |
|
| 135 | 135 | $class = empty($translations) |
| 136 | 136 | ? 'glsr-hidden' |
| 137 | 137 | : ''; |
@@ -149,16 +149,16 @@ discard block |
||
| 149 | 149 | * @param string|array $expectedValue |
| 150 | 150 | * @return bool |
| 151 | 151 | */ |
| 152 | - protected function isFieldHidden($path, $expectedValue) |
|
| 152 | + protected function isFieldHidden( $path, $expectedValue ) |
|
| 153 | 153 | { |
| 154 | - $optionValue = glsr(OptionManager::class)->get( |
|
| 154 | + $optionValue = glsr( OptionManager::class )->get( |
|
| 155 | 155 | $path, |
| 156 | - Arr::get(glsr()->defaults, $path) |
|
| 156 | + Arr::get( glsr()->defaults, $path ) |
|
| 157 | 157 | ); |
| 158 | - if (is_array($expectedValue)) { |
|
| 159 | - return is_array($optionValue) |
|
| 160 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
| 161 | - : !in_array($optionValue, $expectedValue); |
|
| 158 | + if( is_array( $expectedValue ) ) { |
|
| 159 | + return is_array( $optionValue ) |
|
| 160 | + ? 0 === count( array_intersect( $optionValue, $expectedValue ) ) |
|
| 161 | + : !in_array( $optionValue, $expectedValue ); |
|
| 162 | 162 | } |
| 163 | 163 | return $optionValue != $expectedValue; |
| 164 | 164 | } |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | /** |
| 167 | 167 | * @return bool |
| 168 | 168 | */ |
| 169 | - protected function isMultiDependency($path) |
|
| 169 | + protected function isMultiDependency( $path ) |
|
| 170 | 170 | { |
| 171 | - if (isset($this->settings[$path])) { |
|
| 171 | + if( isset($this->settings[$path]) ) { |
|
| 172 | 172 | $field = $this->settings[$path]; |
| 173 | 173 | return ('checkbox' == $field['type'] && !empty($field['options'])) |
| 174 | 174 | || !empty($field['multiple']); |
@@ -179,32 +179,32 @@ discard block |
||
| 179 | 179 | /** |
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | - protected function normalize(array $field) |
|
| 182 | + protected function normalize( array $field ) |
|
| 183 | 183 | { |
| 184 | - $field = $this->normalizeDependsOn($field); |
|
| 185 | - $field = $this->normalizeLabelAndLegend($field); |
|
| 186 | - $field = $this->normalizeValue($field); |
|
| 184 | + $field = $this->normalizeDependsOn( $field ); |
|
| 185 | + $field = $this->normalizeLabelAndLegend( $field ); |
|
| 186 | + $field = $this->normalizeValue( $field ); |
|
| 187 | 187 | return $field; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * @return array |
| 192 | 192 | */ |
| 193 | - protected function normalizeDependsOn(array $field) |
|
| 193 | + protected function normalizeDependsOn( array $field ) |
|
| 194 | 194 | { |
| 195 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
| 195 | + if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) { |
|
| 196 | 196 | $isFieldHidden = false; |
| 197 | 197 | $conditions = []; |
| 198 | - foreach ($field['depends_on'] as $path => $value) { |
|
| 198 | + foreach( $field['depends_on'] as $path => $value ) { |
|
| 199 | 199 | $conditions[] = [ |
| 200 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
| 200 | + 'name' => $this->getFieldNameForDependsOn( $path ), |
|
| 201 | 201 | 'value' => $value, |
| 202 | 202 | ]; |
| 203 | - if ($this->isFieldHidden($path, $value)) { |
|
| 203 | + if( $this->isFieldHidden( $path, $value ) ) { |
|
| 204 | 204 | $isFieldHidden = true; |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
| 207 | + $field['data-depends'] = json_encode( $conditions, JSON_HEX_APOS | JSON_HEX_QUOT ); |
|
| 208 | 208 | $field['is_hidden'] = $isFieldHidden; |
| 209 | 209 | } |
| 210 | 210 | return $field; |
@@ -213,14 +213,14 @@ discard block |
||
| 213 | 213 | /** |
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | - protected function normalizeLabelAndLegend(array $field) |
|
| 216 | + protected function normalizeLabelAndLegend( array $field ) |
|
| 217 | 217 | { |
| 218 | - if (!empty($field['label'])) { |
|
| 218 | + if( !empty($field['label']) ) { |
|
| 219 | 219 | $field['legend'] = $field['label']; |
| 220 | 220 | unset($field['label']); |
| 221 | 221 | } else { |
| 222 | 222 | $field['is_valid'] = false; |
| 223 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
| 223 | + glsr_log()->warning( 'Setting field is missing a label' )->debug( $field ); |
|
| 224 | 224 | } |
| 225 | 225 | return $field; |
| 226 | 226 | } |
@@ -228,12 +228,12 @@ discard block |
||
| 228 | 228 | /** |
| 229 | 229 | * @return array |
| 230 | 230 | */ |
| 231 | - protected function normalizeValue(array $field) |
|
| 231 | + protected function normalizeValue( array $field ) |
|
| 232 | 232 | { |
| 233 | - if (!isset($field['value'])) { |
|
| 234 | - $field['value'] = glsr(OptionManager::class)->get( |
|
| 233 | + if( !isset($field['value']) ) { |
|
| 234 | + $field['value'] = glsr( OptionManager::class )->get( |
|
| 235 | 235 | $field['name'], |
| 236 | - $this->getFieldDefault($field) |
|
| 236 | + $this->getFieldDefault( $field ) |
|
| 237 | 237 | ); |
| 238 | 238 | } |
| 239 | 239 | return $field; |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | /** |
| 243 | 243 | * @return string |
| 244 | 244 | */ |
| 245 | - protected function normalizeSettingPath($path) |
|
| 245 | + protected function normalizeSettingPath( $path ) |
|
| 246 | 246 | { |
| 247 | - return Str::prefix('settings.', rtrim($path, '.')); |
|
| 247 | + return Str::prefix( 'settings.', rtrim( $path, '.' ) ); |
|
| 248 | 248 | } |
| 249 | 249 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function __construct() |
| 36 | 36 | { |
| 37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
| 37 | + $this->style = glsr( OptionManager::class )->get( 'settings.general.style', 'default' ); |
|
| 38 | 38 | $this->setConfig(); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param string $view |
| 43 | 43 | * @return string |
| 44 | 44 | */ |
| 45 | - public function filterView($view) |
|
| 45 | + public function filterView( $view ) |
|
| 46 | 46 | { |
| 47 | 47 | $styledViews = [ |
| 48 | 48 | 'templates/form/field', |
@@ -50,15 +50,15 @@ discard block |
||
| 50 | 50 | 'templates/form/submit-button', |
| 51 | 51 | 'templates/reviews-form', |
| 52 | 52 | ]; |
| 53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
| 53 | + if( !preg_match( '('.implode( '|', $styledViews ).')', $view ) ) { |
|
| 54 | 54 | return $view; |
| 55 | 55 | } |
| 56 | - $views = $this->generatePossibleViews($view); |
|
| 57 | - foreach ($views as $possibleView) { |
|
| 58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
| 56 | + $views = $this->generatePossibleViews( $view ); |
|
| 57 | + foreach( $views as $possibleView ) { |
|
| 58 | + if( !file_exists( glsr()->file( $possibleView ) ) ) { |
|
| 59 | 59 | continue; |
| 60 | 60 | } |
| 61 | - return Str::removePrefix('views/', $possibleView); |
|
| 61 | + return Str::removePrefix( 'views/', $possibleView ); |
|
| 62 | 62 | } |
| 63 | 63 | return $view; |
| 64 | 64 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function get() |
| 70 | 70 | { |
| 71 | - return apply_filters('site-reviews/style', $this->style); |
|
| 71 | + return apply_filters( 'site-reviews/style', $this->style ); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -77,77 +77,77 @@ discard block |
||
| 77 | 77 | public function setConfig() |
| 78 | 78 | { |
| 79 | 79 | $config = shortcode_atts( |
| 80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
| 81 | - glsr()->config('styles/'.$this->style) |
|
| 80 | + array_fill_keys( ['fields', 'pagination', 'validation'], [] ), |
|
| 81 | + glsr()->config( 'styles/'.$this->style ) |
|
| 82 | 82 | ); |
| 83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
| 84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
| 85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
| 83 | + $this->fields = glsr( StyleFieldsDefaults::class )->restrict( $config['fields'] ); |
|
| 84 | + $this->pagination = glsr( PaginationDefaults::class )->restrict( $config['pagination'] ); |
|
| 85 | + $this->validation = glsr( StyleValidationDefaults::class )->restrict( $config['validation'] ); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * @return void |
| 90 | 90 | */ |
| 91 | - public function modifyField(Builder $instance) |
|
| 91 | + public function modifyField( Builder $instance ) |
|
| 92 | 92 | { |
| 93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
| 93 | + if( !$this->isPublicInstance( $instance ) || empty(array_filter( $this->fields )) ) { |
|
| 94 | 94 | return; |
| 95 | 95 | } |
| 96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
| 96 | + call_user_func_array( [$this, 'customize'], [$instance] ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | - public function paginationArgs(array $args) |
|
| 102 | + public function paginationArgs( array $args ) |
|
| 103 | 103 | { |
| 104 | - return wp_parse_args($args, $this->pagination); |
|
| 104 | + return wp_parse_args( $args, $this->pagination ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - protected function customize(Builder $instance) |
|
| 110 | + protected function customize( Builder $instance ) |
|
| 111 | 111 | { |
| 112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
| 112 | + if( !array_key_exists( $instance->tag, $this->fields ) ) { |
|
| 113 | 113 | return; |
| 114 | 114 | } |
| 115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
| 115 | + $args = wp_parse_args( $instance->args, array_fill_keys( ['class', 'type'], '' ) ); |
|
| 116 | 116 | $key = $instance->tag.'_'.$args['type']; |
| 117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
| 118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
| 119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
| 117 | + $classes = Arr::get( $this->fields, $key, Arr::get( $this->fields, $instance->tag ) ); |
|
| 118 | + $instance->args['class'] = trim( $args['class'].' '.$classes ); |
|
| 119 | + do_action_ref_array( 'site-reviews/customize/'.$this->style, [$instance] ); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * @param string $view |
| 124 | 124 | * @return array |
| 125 | 125 | */ |
| 126 | - protected function generatePossibleViews($view) |
|
| 126 | + protected function generatePossibleViews( $view ) |
|
| 127 | 127 | { |
| 128 | - $basename = basename($view); |
|
| 129 | - $basepath = rtrim($view, $basename); |
|
| 128 | + $basename = basename( $view ); |
|
| 129 | + $basepath = rtrim( $view, $basename ); |
|
| 130 | 130 | $customPath = 'views/partials/styles/'.$this->style.'/'; |
| 131 | - $parts = explode('_', $basename); |
|
| 131 | + $parts = explode( '_', $basename ); |
|
| 132 | 132 | $views = [ |
| 133 | 133 | $customPath.$basename, |
| 134 | 134 | $customPath.$parts[0], |
| 135 | 135 | $view, |
| 136 | 136 | $basepath.$parts[0], |
| 137 | 137 | ]; |
| 138 | - return array_filter($views); |
|
| 138 | + return array_filter( $views ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * @return bool |
| 143 | 143 | */ |
| 144 | - protected function isPublicInstance(Builder $instance) |
|
| 144 | + protected function isPublicInstance( Builder $instance ) |
|
| 145 | 145 | { |
| 146 | - $args = wp_parse_args($instance->args, [ |
|
| 146 | + $args = wp_parse_args( $instance->args, [ |
|
| 147 | 147 | 'is_public' => false, |
| 148 | 148 | 'is_raw' => false, |
| 149 | - ]); |
|
| 150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
| 149 | + ] ); |
|
| 150 | + if( is_admin() || !$args['is_public'] || $args['is_raw'] ) { |
|
| 151 | 151 | return false; |
| 152 | 152 | } |
| 153 | 153 | return true; |
@@ -33,27 +33,27 @@ discard block |
||
| 33 | 33 | public $url; |
| 34 | 34 | public $user_id; |
| 35 | 35 | |
| 36 | - public function __construct(WP_Post $post) |
|
| 36 | + public function __construct( WP_Post $post ) |
|
| 37 | 37 | { |
| 38 | - if (Application::POST_TYPE != $post->post_type) { |
|
| 38 | + if( Application::POST_TYPE != $post->post_type ) { |
|
| 39 | 39 | return; |
| 40 | 40 | } |
| 41 | 41 | $this->content = $post->post_content; |
| 42 | 42 | $this->date = $post->post_date; |
| 43 | - $this->ID = intval($post->ID); |
|
| 43 | + $this->ID = intval( $post->ID ); |
|
| 44 | 44 | $this->status = $post->post_status; |
| 45 | 45 | $this->title = $post->post_title; |
| 46 | - $this->user_id = intval($post->post_author); |
|
| 47 | - $this->setProperties($post); |
|
| 48 | - $this->setTermIds($post); |
|
| 46 | + $this->user_id = intval( $post->post_author ); |
|
| 47 | + $this->setProperties( $post ); |
|
| 48 | + $this->setTermIds( $post ); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * @return mixed |
| 53 | 53 | */ |
| 54 | - public function __get($key) |
|
| 54 | + public function __get( $key ) |
|
| 55 | 55 | { |
| 56 | - return $this->offsetGet($key); |
|
| 56 | + return $this->offsetGet( $key ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -61,41 +61,41 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function __toString() |
| 63 | 63 | { |
| 64 | - return (string) $this->build(); |
|
| 64 | + return (string)$this->build(); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @return ReviewHtml |
| 69 | 69 | */ |
| 70 | - public function build(array $args = []) |
|
| 70 | + public function build( array $args = [] ) |
|
| 71 | 71 | { |
| 72 | - if (empty($this->ID)) { |
|
| 73 | - return new ReviewHtml($this); |
|
| 72 | + if( empty($this->ID) ) { |
|
| 73 | + return new ReviewHtml( $this ); |
|
| 74 | 74 | } |
| 75 | - $partial = glsr(SiteReviewsPartial::class); |
|
| 76 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
| 77 | - $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
| 78 | - return $partial->buildReview($this); |
|
| 75 | + $partial = glsr( SiteReviewsPartial::class ); |
|
| 76 | + $partial->args = glsr( SiteReviewsDefaults::class )->merge( $args ); |
|
| 77 | + $partial->options = Arr::flattenArray( glsr( OptionManager::class )->all() ); |
|
| 78 | + return $partial->buildReview( $this ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * @param mixed $key |
| 83 | 83 | * @return bool |
| 84 | 84 | */ |
| 85 | - public function offsetExists($key) |
|
| 85 | + public function offsetExists( $key ) |
|
| 86 | 86 | { |
| 87 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
| 87 | + return property_exists( $this, $key ) || array_key_exists( $key, (array)$this->custom ); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * @param mixed $key |
| 92 | 92 | * @return mixed |
| 93 | 93 | */ |
| 94 | - public function offsetGet($key) |
|
| 94 | + public function offsetGet( $key ) |
|
| 95 | 95 | { |
| 96 | - return property_exists($this, $key) |
|
| 96 | + return property_exists( $this, $key ) |
|
| 97 | 97 | ? $this->$key |
| 98 | - : Arr::get($this->custom, $key, null); |
|
| 98 | + : Arr::get( $this->custom, $key, null ); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | * @param mixed $value |
| 104 | 104 | * @return void |
| 105 | 105 | */ |
| 106 | - public function offsetSet($key, $value) |
|
| 106 | + public function offsetSet( $key, $value ) |
|
| 107 | 107 | { |
| 108 | - if (property_exists($this, $key)) { |
|
| 108 | + if( property_exists( $this, $key ) ) { |
|
| 109 | 109 | $this->$key = $value; |
| 110 | 110 | return; |
| 111 | 111 | } |
| 112 | - if (!is_array($this->custom)) { |
|
| 113 | - $this->custom = array_filter((array) $this->custom); |
|
| 112 | + if( !is_array( $this->custom ) ) { |
|
| 113 | + $this->custom = array_filter( (array)$this->custom ); |
|
| 114 | 114 | } |
| 115 | 115 | $this->custom[$key] = $value; |
| 116 | 116 | } |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | * @param mixed $key |
| 120 | 120 | * @return void |
| 121 | 121 | */ |
| 122 | - public function offsetUnset($key) |
|
| 122 | + public function offsetUnset( $key ) |
|
| 123 | 123 | { |
| 124 | - $this->offsetSet($key, null); |
|
| 124 | + $this->offsetSet( $key, null ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | /** |
| 136 | 136 | * @return bool |
| 137 | 137 | */ |
| 138 | - protected function isModified(array $properties) |
|
| 138 | + protected function isModified( array $properties ) |
|
| 139 | 139 | { |
| 140 | 140 | return $this->date != $properties['date'] |
| 141 | 141 | || $this->content != $properties['content'] |
@@ -145,39 +145,39 @@ discard block |
||
| 145 | 145 | /** |
| 146 | 146 | * @return void |
| 147 | 147 | */ |
| 148 | - protected function setProperties(WP_Post $post) |
|
| 148 | + protected function setProperties( WP_Post $post ) |
|
| 149 | 149 | { |
| 150 | 150 | $defaults = [ |
| 151 | - 'author' => __('Anonymous', 'site-reviews'), |
|
| 151 | + 'author' => __( 'Anonymous', 'site-reviews' ), |
|
| 152 | 152 | 'date' => '', |
| 153 | 153 | 'review_id' => '', |
| 154 | 154 | 'review_type' => 'local', |
| 155 | 155 | ]; |
| 156 | 156 | $meta = array_filter( |
| 157 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
| 157 | + array_map( 'array_shift', array_filter( (array)get_post_meta( $post->ID ) ) ), |
|
| 158 | 158 | 'strlen' |
| 159 | 159 | ); |
| 160 | - $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
| 161 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
| 162 | - $this->modified = $this->isModified($properties); |
|
| 163 | - array_walk($properties, function ($value, $key) { |
|
| 164 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
| 160 | + $meta = array_merge( $defaults, Arr::unprefixArrayKeys( $meta ) ); |
|
| 161 | + $properties = glsr( CreateReviewDefaults::class )->restrict( array_merge( $defaults, $meta ) ); |
|
| 162 | + $this->modified = $this->isModified( $properties ); |
|
| 163 | + array_walk( $properties, function( $value, $key ) { |
|
| 164 | + if( !property_exists( $this, $key ) || isset($this->$key) ) { |
|
| 165 | 165 | return; |
| 166 | 166 | } |
| 167 | - $this->$key = maybe_unserialize($value); |
|
| 167 | + $this->$key = maybe_unserialize( $value ); |
|
| 168 | 168 | }); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | - protected function setTermIds(WP_Post $post) |
|
| 174 | + protected function setTermIds( WP_Post $post ) |
|
| 175 | 175 | { |
| 176 | 176 | $this->term_ids = []; |
| 177 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
| 177 | + if( !is_array( $terms = get_the_terms( $post, Application::TAXONOMY ) ) ) { |
|
| 178 | 178 | return; |
| 179 | 179 | } |
| 180 | - foreach ($terms as $term) { |
|
| 180 | + foreach( $terms as $term ) { |
|
| 181 | 181 | $this->term_ids[] = $term->term_id; |
| 182 | 182 | } |
| 183 | 183 | } |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | * @param string $name |
| 30 | 30 | * @return void|array |
| 31 | 31 | */ |
| 32 | - public function __call($name, array $args = []) |
|
| 32 | + public function __call( $name, array $args = [] ) |
|
| 33 | 33 | { |
| 34 | - if (!method_exists($this, $name) || !in_array($name, $this->callable)) { |
|
| 34 | + if( !method_exists( $this, $name ) || !in_array( $name, $this->callable ) ) { |
|
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | - $args[0] = $this->mapKeys(Arr::get($args, 0, [])); |
|
| 38 | - $defaults = call_user_func_array([$this, $name], $args); |
|
| 39 | - $hookName = (new ReflectionClass($this))->getShortName(); |
|
| 40 | - $hookName = str_replace('Defaults', '', $hookName); |
|
| 41 | - $hookName = Str::dashCase($hookName); |
|
| 42 | - return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name); |
|
| 37 | + $args[0] = $this->mapKeys( Arr::get( $args, 0, [] ) ); |
|
| 38 | + $defaults = call_user_func_array( [$this, $name], $args ); |
|
| 39 | + $hookName = (new ReflectionClass( $this ))->getShortName(); |
|
| 40 | + $hookName = str_replace( 'Defaults', '', $hookName ); |
|
| 41 | + $hookName = Str::dashCase( $hookName ); |
|
| 42 | + return apply_filters( 'site-reviews/defaults/'.$hookName, $defaults, $name ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -50,38 +50,38 @@ discard block |
||
| 50 | 50 | /** |
| 51 | 51 | * @return array |
| 52 | 52 | */ |
| 53 | - protected function filter(array $values = []) |
|
| 53 | + protected function filter( array $values = [] ) |
|
| 54 | 54 | { |
| 55 | - return $this->normalize($this->merge(array_filter($values)), $values); |
|
| 55 | + return $this->normalize( $this->merge( array_filter( $values ) ), $values ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | - protected function filteredJson(array $values = []) |
|
| 61 | + protected function filteredJson( array $values = [] ) |
|
| 62 | 62 | { |
| 63 | 63 | $defaults = $this->flattenArray( |
| 64 | - array_diff_key($this->defaults(), array_flip($this->guarded)) |
|
| 64 | + array_diff_key( $this->defaults(), array_flip( $this->guarded ) ) |
|
| 65 | 65 | ); |
| 66 | 66 | $values = $this->flattenArray( |
| 67 | - shortcode_atts($defaults, $values) |
|
| 67 | + shortcode_atts( $defaults, $values ) |
|
| 68 | 68 | ); |
| 69 | - $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) { |
|
| 70 | - return !$this->isEmpty($value); |
|
| 69 | + $filtered = array_filter( array_diff_assoc( $values, $defaults ), function( $value ) { |
|
| 70 | + return !$this->isEmpty( $value ); |
|
| 71 | 71 | }); |
| 72 | - return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 72 | + return json_encode( $filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * @return array |
| 77 | 77 | */ |
| 78 | - protected function flattenArray(array $values) |
|
| 78 | + protected function flattenArray( array $values ) |
|
| 79 | 79 | { |
| 80 | - array_walk($values, function (&$value) { |
|
| 81 | - if (!is_array($value)) { |
|
| 80 | + array_walk( $values, function( &$value ) { |
|
| 81 | + if( !is_array( $value ) ) { |
|
| 82 | 82 | return; |
| 83 | 83 | } |
| 84 | - $value = implode(',', $value); |
|
| 84 | + $value = implode( ',', $value ); |
|
| 85 | 85 | }); |
| 86 | 86 | return $values; |
| 87 | 87 | } |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | * @param mixed $var |
| 91 | 91 | * @return bool |
| 92 | 92 | */ |
| 93 | - protected function isEmpty($var) |
|
| 93 | + protected function isEmpty( $var ) |
|
| 94 | 94 | { |
| 95 | - return !is_numeric($var) && !is_bool($var) && empty($var); |
|
| 95 | + return !is_numeric( $var ) && !is_bool( $var ) && empty($var); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * @return array |
| 100 | 100 | */ |
| 101 | - protected function mapKeys(array $args) |
|
| 101 | + protected function mapKeys( array $args ) |
|
| 102 | 102 | { |
| 103 | - foreach ($this->mapped as $old => $new) { |
|
| 104 | - if (array_key_exists($old, $args)) { |
|
| 103 | + foreach( $this->mapped as $old => $new ) { |
|
| 104 | + if( array_key_exists( $old, $args ) ) { |
|
| 105 | 105 | $args[$new] = $args[$old]; |
| 106 | 106 | unset($args[$old]); |
| 107 | 107 | } |
@@ -112,26 +112,26 @@ discard block |
||
| 112 | 112 | /** |
| 113 | 113 | * @return array |
| 114 | 114 | */ |
| 115 | - protected function merge(array $values = []) |
|
| 115 | + protected function merge( array $values = [] ) |
|
| 116 | 116 | { |
| 117 | - return $this->normalize(wp_parse_args($values, $this->defaults()), $values); |
|
| 117 | + return $this->normalize( wp_parse_args( $values, $this->defaults() ), $values ); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | - protected function normalize(array $values, array $originalValues) |
|
| 123 | + protected function normalize( array $values, array $originalValues ) |
|
| 124 | 124 | { |
| 125 | - $values['json'] = $this->filteredJson($originalValues); |
|
| 125 | + $values['json'] = $this->filteredJson( $originalValues ); |
|
| 126 | 126 | return $values; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * @return array |
| 131 | 131 | */ |
| 132 | - protected function restrict(array $values = []) |
|
| 132 | + protected function restrict( array $values = [] ) |
|
| 133 | 133 | { |
| 134 | - return $this->normalize(shortcode_atts($this->defaults(), $values), $values); |
|
| 134 | + return $this->normalize( shortcode_atts( $this->defaults(), $values ), $values ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -139,6 +139,6 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | protected function unguarded() |
| 141 | 141 | { |
| 142 | - return array_diff_key($this->defaults(), array_flip($this->guarded)); |
|
| 142 | + return array_diff_key( $this->defaults(), array_flip( $this->guarded ) ); |
|
| 143 | 143 | } |
| 144 | 144 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public $translator; |
| 17 | 17 | |
| 18 | - public function __construct(Translator $translator) |
|
| 18 | + public function __construct( Translator $translator ) |
|
| 19 | 19 | { |
| 20 | 20 | $this->translator = $translator; |
| 21 | 21 | } |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | * @return array |
| 26 | 26 | * @filter bulk_post_updated_messages |
| 27 | 27 | */ |
| 28 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
| 28 | + public function filterBulkUpdateMessages( $messages, array $counts ) |
|
| 29 | 29 | { |
| 30 | - $messages = Arr::consolidateArray($messages); |
|
| 30 | + $messages = Arr::consolidateArray( $messages ); |
|
| 31 | 31 | $messages[Application::POST_TYPE] = [ |
| 32 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
| 33 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
| 34 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
| 35 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
| 36 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
| 32 | + 'updated' => _n( '%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews' ), |
|
| 33 | + 'locked' => _n( '%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews' ), |
|
| 34 | + 'deleted' => _n( '%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews' ), |
|
| 35 | + 'trashed' => _n( '%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews' ), |
|
| 36 | + 'untrashed' => _n( '%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews' ), |
|
| 37 | 37 | ]; |
| 38 | 38 | return $messages; |
| 39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * @return string |
| 46 | 46 | * @filter gettext |
| 47 | 47 | */ |
| 48 | - public function filterGettext($translation, $text, $domain) |
|
| 48 | + public function filterGettext( $translation, $text, $domain ) |
|
| 49 | 49 | { |
| 50 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
| 50 | + return apply_filters( 'site-reviews/gettext/'.$domain, $translation, $text ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | * @filter site-reviews/gettext/site-reviews |
| 58 | 58 | */ |
| 59 | - public function filterGettextSiteReviews($translation, $text) |
|
| 59 | + public function filterGettextSiteReviews( $translation, $text ) |
|
| 60 | 60 | { |
| 61 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 61 | + return $this->translator->translate( $translation, Application::ID, [ |
|
| 62 | 62 | 'single' => $text, |
| 63 | - ]); |
|
| 63 | + ] ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | * @return string |
| 72 | 72 | * @filter gettext_with_context |
| 73 | 73 | */ |
| 74 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 74 | + public function filterGettextWithContext( $translation, $text, $context, $domain ) |
|
| 75 | 75 | { |
| 76 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
| 76 | + return apply_filters( 'site-reviews/gettext_with_context/'.$domain, $translation, $text, $context ); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | * @return string |
| 84 | 84 | * @filter site-reviews/gettext_with_context/site-reviews |
| 85 | 85 | */ |
| 86 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
| 86 | + public function filterGettextWithContextSiteReviews( $translation, $text, $context ) |
|
| 87 | 87 | { |
| 88 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 88 | + return $this->translator->translate( $translation, Application::ID, [ |
|
| 89 | 89 | 'context' => $context, |
| 90 | 90 | 'single' => $text, |
| 91 | - ]); |
|
| 91 | + ] ); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | * @return string |
| 101 | 101 | * @filter ngettext |
| 102 | 102 | */ |
| 103 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 103 | + public function filterNgettext( $translation, $single, $plural, $number, $domain ) |
|
| 104 | 104 | { |
| 105 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
| 105 | + return apply_filters( 'site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | * @return string |
| 114 | 114 | * @filter site-reviews/ngettext/site-reviews |
| 115 | 115 | */ |
| 116 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
| 116 | + public function filterNgettextSiteReviews( $translation, $single, $plural, $number ) |
|
| 117 | 117 | { |
| 118 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 118 | + return $this->translator->translate( $translation, Application::ID, [ |
|
| 119 | 119 | 'number' => $number, |
| 120 | 120 | 'plural' => $plural, |
| 121 | 121 | 'single' => $single, |
| 122 | - ]); |
|
| 122 | + ] ); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | * @return string |
| 133 | 133 | * @filter ngettext_with_context |
| 134 | 134 | */ |
| 135 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 135 | + public function filterNgettextWithContext( $translation, $single, $plural, $number, $context, $domain ) |
|
| 136 | 136 | { |
| 137 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
| 137 | + return apply_filters( 'site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context ); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | * @return string |
| 147 | 147 | * @filter site-reviews/ngettext_with_context/site-reviews |
| 148 | 148 | */ |
| 149 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
| 149 | + public function filterNgettextWithContextSiteReviews( $translation, $single, $plural, $number, $context ) |
|
| 150 | 150 | { |
| 151 | - return $this->translator->translate($translation, Application::ID, [ |
|
| 151 | + return $this->translator->translate( $translation, Application::ID, [ |
|
| 152 | 152 | 'context' => $context, |
| 153 | 153 | 'number' => $number, |
| 154 | 154 | 'plural' => $plural, |
| 155 | 155 | 'single' => $single, |
| 156 | - ]); |
|
| 156 | + ] ); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | * @return array |
| 163 | 163 | * @filter display_post_states |
| 164 | 164 | */ |
| 165 | - public function filterPostStates($postStates, $post) |
|
| 165 | + public function filterPostStates( $postStates, $post ) |
|
| 166 | 166 | { |
| 167 | - $postStates = Arr::consolidateArray($postStates); |
|
| 168 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
| 169 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
| 167 | + $postStates = Arr::consolidateArray( $postStates ); |
|
| 168 | + if( Application::POST_TYPE == Arr::get( $post, 'post_type' ) && array_key_exists( 'pending', $postStates ) ) { |
|
| 169 | + $postStates['pending'] = __( 'Unapproved', 'site-reviews' ); |
|
| 170 | 170 | } |
| 171 | 171 | return $postStates; |
| 172 | 172 | } |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | * @filter site-reviews/gettext/default |
| 179 | 179 | * @filter site-reviews/gettext_with_context/default |
| 180 | 180 | */ |
| 181 | - public function filterPostStatusLabels($translation, $text) |
|
| 181 | + public function filterPostStatusLabels( $translation, $text ) |
|
| 182 | 182 | { |
| 183 | 183 | return $this->canModifyTranslation() |
| 184 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
| 184 | + ? glsr( Labels::class )->filterPostStatusLabels( $translation, $text ) |
|
| 185 | 185 | : $translation; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -193,22 +193,22 @@ discard block |
||
| 193 | 193 | * @return string |
| 194 | 194 | * @filter site-reviews/ngettext/default |
| 195 | 195 | */ |
| 196 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
| 196 | + public function filterPostStatusText( $translation, $single, $plural, $number ) |
|
| 197 | 197 | { |
| 198 | - if ($this->canModifyTranslation()) { |
|
| 198 | + if( $this->canModifyTranslation() ) { |
|
| 199 | 199 | $strings = [ |
| 200 | - 'Published' => __('Approved', 'site-reviews'), |
|
| 201 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 200 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
| 201 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
| 202 | 202 | ]; |
| 203 | - foreach ($strings as $search => $replace) { |
|
| 204 | - if (!Str::contains($single, $search)) { |
|
| 203 | + foreach( $strings as $search => $replace ) { |
|
| 204 | + if( !Str::contains( $single, $search ) ) { |
|
| 205 | 205 | continue; |
| 206 | 206 | } |
| 207 | - return $this->translator->getTranslation([ |
|
| 207 | + return $this->translator->getTranslation( [ |
|
| 208 | 208 | 'number' => $number, |
| 209 | - 'plural' => str_replace($search, $replace, $plural), |
|
| 210 | - 'single' => str_replace($search, $replace, $single), |
|
| 211 | - ]); |
|
| 209 | + 'plural' => str_replace( $search, $replace, $plural ), |
|
| 210 | + 'single' => str_replace( $search, $replace, $single ), |
|
| 211 | + ] ); |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | return $translation; |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | public function translatePostStatusLabels() |
| 222 | 222 | { |
| 223 | - if ($this->canModifyTranslation()) { |
|
| 224 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
| 223 | + if( $this->canModifyTranslation() ) { |
|
| 224 | + glsr( Labels::class )->translatePostStatusLabels(); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
@@ -232,6 +232,6 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | $screen = glsr_current_screen(); |
| 234 | 234 | return Application::POST_TYPE == $screen->post_type |
| 235 | - && in_array($screen->base, ['edit', 'post']); |
|
| 235 | + && in_array( $screen->base, ['edit', 'post'] ); |
|
| 236 | 236 | } |
| 237 | 237 | } |
@@ -10,13 +10,13 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | class Console |
| 12 | 12 | { |
| 13 | - const DEBUG = 0; // Detailed debug information |
|
| 14 | - const INFO = 1; // Interesting events |
|
| 15 | - const NOTICE = 2; // Normal but significant events |
|
| 16 | - const WARNING = 4; // Exceptional occurrences that are not errors |
|
| 17 | - const ERROR = 8; // Runtime errors that do not require immediate action |
|
| 18 | - const CRITICAL = 16; // Critical conditions |
|
| 19 | - const ALERT = 32; // Action must be taken immediately |
|
| 13 | + const DEBUG = 0; // Detailed debug information |
|
| 14 | + const INFO = 1; // Interesting events |
|
| 15 | + const NOTICE = 2; // Normal but significant events |
|
| 16 | + const WARNING = 4; // Exceptional occurrences that are not errors |
|
| 17 | + const ERROR = 8; // Runtime errors that do not require immediate action |
|
| 18 | + const CRITICAL = 16; // Critical conditions |
|
| 19 | + const ALERT = 32; // Action must be taken immediately |
|
| 20 | 20 | const EMERGENCY = 64; // System is unusable |
| 21 | 21 | |
| 22 | 22 | protected $file; |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function __construct() |
| 27 | 27 | { |
| 28 | - $this->file = glsr()->path('console.log'); |
|
| 29 | - $this->log = file_exists($this->file) |
|
| 30 | - ? file_get_contents($this->file) |
|
| 28 | + $this->file = glsr()->path( 'console.log' ); |
|
| 29 | + $this->log = file_exists( $this->file ) |
|
| 30 | + ? file_get_contents( $this->file ) |
|
| 31 | 31 | : ''; |
| 32 | 32 | $this->reset(); |
| 33 | 33 | } |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | * @param array $context |
| 48 | 48 | * @return static |
| 49 | 49 | */ |
| 50 | - public function alert($message, array $context = []) |
|
| 50 | + public function alert( $message, array $context = [] ) |
|
| 51 | 51 | { |
| 52 | - return $this->log(static::ALERT, $message, $context); |
|
| 52 | + return $this->log( static::ALERT, $message, $context ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | public function clear() |
| 59 | 59 | { |
| 60 | 60 | $this->log = ''; |
| 61 | - file_put_contents($this->file, $this->log); |
|
| 61 | + file_put_contents( $this->file, $this->log ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | * @param array $context |
| 69 | 69 | * @return static |
| 70 | 70 | */ |
| 71 | - public function critical($message, array $context = []) |
|
| 71 | + public function critical( $message, array $context = [] ) |
|
| 72 | 72 | { |
| 73 | - return $this->log(static::CRITICAL, $message, $context); |
|
| 73 | + return $this->log( static::CRITICAL, $message, $context ); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | * @param array $context |
| 80 | 80 | * @return static |
| 81 | 81 | */ |
| 82 | - public function debug($message, array $context = []) |
|
| 82 | + public function debug( $message, array $context = [] ) |
|
| 83 | 83 | { |
| 84 | - return $this->log(static::DEBUG, $message, $context); |
|
| 84 | + return $this->log( static::DEBUG, $message, $context ); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | * @param array $context |
| 91 | 91 | * @return static |
| 92 | 92 | */ |
| 93 | - public function emergency($message, array $context = []) |
|
| 93 | + public function emergency( $message, array $context = [] ) |
|
| 94 | 94 | { |
| 95 | - return $this->log(static::EMERGENCY, $message, $context); |
|
| 95 | + return $this->log( static::EMERGENCY, $message, $context ); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | * @param array $context |
| 102 | 102 | * @return static |
| 103 | 103 | */ |
| 104 | - public function error($message, array $context = []) |
|
| 104 | + public function error( $message, array $context = [] ) |
|
| 105 | 105 | { |
| 106 | - return $this->log(static::ERROR, $message, $context); |
|
| 106 | + return $this->log( static::ERROR, $message, $context ); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | public function get() |
| 113 | 113 | { |
| 114 | 114 | return empty($this->log) |
| 115 | - ? __('Console is empty', 'site-reviews') |
|
| 115 | + ? __( 'Console is empty', 'site-reviews' ) |
|
| 116 | 116 | : $this->log; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function getLevel() |
| 123 | 123 | { |
| 124 | - return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
| 124 | + return intval( apply_filters( 'site-reviews/console/level', static::INFO ) ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function getLevels() |
| 131 | 131 | { |
| 132 | - $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
| 133 | - return array_map('strtolower', array_flip($constants)); |
|
| 132 | + $constants = (new ReflectionClass( __CLASS__ ))->getConstants(); |
|
| 133 | + return array_map( 'strtolower', array_flip( $constants ) ); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -139,21 +139,21 @@ discard block |
||
| 139 | 139 | public function humanLevel() |
| 140 | 140 | { |
| 141 | 141 | $level = $this->getLevel(); |
| 142 | - return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
| 142 | + return sprintf( '%s (%d)', strtoupper( Arr::get( $this->getLevels(), $level, 'unknown' ) ), $level ); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * @param string|null $valueIfEmpty |
| 147 | 147 | * @return string |
| 148 | 148 | */ |
| 149 | - public function humanSize($valueIfEmpty = null) |
|
| 149 | + public function humanSize( $valueIfEmpty = null ) |
|
| 150 | 150 | { |
| 151 | 151 | $bytes = $this->size(); |
| 152 | - if (empty($bytes) && is_string($valueIfEmpty)) { |
|
| 152 | + if( empty($bytes) && is_string( $valueIfEmpty ) ) { |
|
| 153 | 153 | return $valueIfEmpty; |
| 154 | 154 | } |
| 155 | - $exponent = floor(log(max($bytes, 1), 1024)); |
|
| 156 | - return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
| 155 | + $exponent = floor( log( max( $bytes, 1 ), 1024 ) ); |
|
| 156 | + return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | * @param array $context |
| 164 | 164 | * @return static |
| 165 | 165 | */ |
| 166 | - public function info($message, array $context = []) |
|
| 166 | + public function info( $message, array $context = [] ) |
|
| 167 | 167 | { |
| 168 | - return $this->log(static::INFO, $message, $context); |
|
| 168 | + return $this->log( static::INFO, $message, $context ); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -175,19 +175,19 @@ discard block |
||
| 175 | 175 | * @param string $backtraceLine |
| 176 | 176 | * @return static |
| 177 | 177 | */ |
| 178 | - public function log($level, $message, $context = [], $backtraceLine = '') |
|
| 178 | + public function log( $level, $message, $context = [], $backtraceLine = '' ) |
|
| 179 | 179 | { |
| 180 | - if (empty($backtraceLine)) { |
|
| 180 | + if( empty($backtraceLine) ) { |
|
| 181 | 181 | $backtraceLine = $this->getBacktraceLine(); |
| 182 | 182 | } |
| 183 | - if ($this->canLogEntry($level, $backtraceLine)) { |
|
| 184 | - $levelName = Arr::get($this->getLevels(), $level); |
|
| 185 | - $context = Arr::consolidateArray($context); |
|
| 186 | - $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
| 187 | - $message = $this->interpolate($message, $context); |
|
| 188 | - $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
| 189 | - file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
| 190 | - apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
| 183 | + if( $this->canLogEntry( $level, $backtraceLine ) ) { |
|
| 184 | + $levelName = Arr::get( $this->getLevels(), $level ); |
|
| 185 | + $context = Arr::consolidateArray( $context ); |
|
| 186 | + $backtraceLine = $this->normalizeBacktraceLine( $backtraceLine ); |
|
| 187 | + $message = $this->interpolate( $message, $context ); |
|
| 188 | + $entry = $this->buildLogEntry( $levelName, $message, $backtraceLine ); |
|
| 189 | + file_put_contents( $this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX ); |
|
| 190 | + apply_filters( 'console', $message, $levelName, $backtraceLine ); // Show in Blackbar plugin if installed |
|
| 191 | 191 | $this->reset(); |
| 192 | 192 | } |
| 193 | 193 | return $this; |
@@ -198,17 +198,17 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | public function logOnce() |
| 200 | 200 | { |
| 201 | - $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
| 201 | + $once = Arr::consolidateArray( glsr()->{$this->logOnceKey}); |
|
| 202 | 202 | $levels = $this->getLevels(); |
| 203 | - foreach ($once as $entry) { |
|
| 204 | - $levelName = Arr::get($entry, 'level'); |
|
| 205 | - if (!in_array($levelName, $levels)) { |
|
| 203 | + foreach( $once as $entry ) { |
|
| 204 | + $levelName = Arr::get( $entry, 'level' ); |
|
| 205 | + if( !in_array( $levelName, $levels ) ) { |
|
| 206 | 206 | continue; |
| 207 | 207 | } |
| 208 | - $level = Arr::get(array_flip($levels), $levelName); |
|
| 209 | - $message = Arr::get($entry, 'message'); |
|
| 210 | - $backtraceLine = Arr::get($entry, 'backtrace'); |
|
| 211 | - $this->log($level, $message, [], $backtraceLine); |
|
| 208 | + $level = Arr::get( array_flip( $levels ), $levelName ); |
|
| 209 | + $message = Arr::get( $entry, 'message' ); |
|
| 210 | + $backtraceLine = Arr::get( $entry, 'backtrace' ); |
|
| 211 | + $this->log( $level, $message, [], $backtraceLine ); |
|
| 212 | 212 | } |
| 213 | 213 | glsr()->{$this->logOnceKey} = []; |
| 214 | 214 | } |
@@ -219,9 +219,9 @@ discard block |
||
| 219 | 219 | * @param array $context |
| 220 | 220 | * @return static |
| 221 | 221 | */ |
| 222 | - public function notice($message, array $context = []) |
|
| 222 | + public function notice( $message, array $context = [] ) |
|
| 223 | 223 | { |
| 224 | - return $this->log(static::NOTICE, $message, $context); |
|
| 224 | + return $this->log( static::NOTICE, $message, $context ); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -230,21 +230,21 @@ discard block |
||
| 230 | 230 | * @param mixed $data |
| 231 | 231 | * @return void |
| 232 | 232 | */ |
| 233 | - public function once($levelName, $handle, $data) |
|
| 233 | + public function once( $levelName, $handle, $data ) |
|
| 234 | 234 | { |
| 235 | - $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
| 236 | - $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
| 237 | - return Arr::get($entry, 'level') == $levelName |
|
| 238 | - && Arr::get($entry, 'handle') == $handle; |
|
| 235 | + $once = Arr::consolidateArray( glsr()->{$this->logOnceKey}); |
|
| 236 | + $filtered = array_filter( $once, function( $entry ) use ($levelName, $handle) { |
|
| 237 | + return Arr::get( $entry, 'level' ) == $levelName |
|
| 238 | + && Arr::get( $entry, 'handle' ) == $handle; |
|
| 239 | 239 | }); |
| 240 | - if (!empty($filtered)) { |
|
| 240 | + if( !empty($filtered) ) { |
|
| 241 | 241 | return; |
| 242 | 242 | } |
| 243 | 243 | $once[] = [ |
| 244 | - 'backtrace' => $this->getBacktraceLineFromData($data), |
|
| 244 | + 'backtrace' => $this->getBacktraceLineFromData( $data ), |
|
| 245 | 245 | 'handle' => $handle, |
| 246 | 246 | 'level' => $levelName, |
| 247 | - 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
| 247 | + 'message' => '[RECURRING] '.$this->getMessageFromData( $data ), |
|
| 248 | 248 | ]; |
| 249 | 249 | glsr()->{$this->logOnceKey} = $once; |
| 250 | 250 | } |
@@ -254,8 +254,8 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | public function size() |
| 256 | 256 | { |
| 257 | - return file_exists($this->file) |
|
| 258 | - ? filesize($this->file) |
|
| 257 | + return file_exists( $this->file ) |
|
| 258 | + ? filesize( $this->file ) |
|
| 259 | 259 | : 0; |
| 260 | 260 | } |
| 261 | 261 | |
@@ -266,9 +266,9 @@ discard block |
||
| 266 | 266 | * @param array $context |
| 267 | 267 | * @return static |
| 268 | 268 | */ |
| 269 | - public function warning($message, array $context = []) |
|
| 269 | + public function warning( $message, array $context = [] ) |
|
| 270 | 270 | { |
| 271 | - return $this->log(static::WARNING, $message, $context); |
|
| 271 | + return $this->log( static::WARNING, $message, $context ); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | * @param int $index |
| 277 | 277 | * @return string |
| 278 | 278 | */ |
| 279 | - protected function buildBacktraceLine($backtrace, $index) |
|
| 279 | + protected function buildBacktraceLine( $backtrace, $index ) |
|
| 280 | 280 | { |
| 281 | - return sprintf('%s:%s', |
|
| 282 | - Arr::get($backtrace, $index.'.file'), // realpath |
|
| 283 | - Arr::get($backtrace, $index.'.line') |
|
| 281 | + return sprintf( '%s:%s', |
|
| 282 | + Arr::get( $backtrace, $index.'.file' ), // realpath |
|
| 283 | + Arr::get( $backtrace, $index.'.line' ) |
|
| 284 | 284 | ); |
| 285 | 285 | } |
| 286 | 286 | |
@@ -290,11 +290,11 @@ discard block |
||
| 290 | 290 | * @param string $backtraceLine |
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | - protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
| 293 | + protected function buildLogEntry( $levelName, $message, $backtraceLine = '' ) |
|
| 294 | 294 | { |
| 295 | - return sprintf('[%s] %s [%s] %s', |
|
| 296 | - current_time('mysql'), |
|
| 297 | - strtoupper($levelName), |
|
| 295 | + return sprintf( '[%s] %s [%s] %s', |
|
| 296 | + current_time( 'mysql' ), |
|
| 297 | + strtoupper( $levelName ), |
|
| 298 | 298 | $backtraceLine, |
| 299 | 299 | $message |
| 300 | 300 | ); |
@@ -304,10 +304,10 @@ discard block |
||
| 304 | 304 | * @param int $level |
| 305 | 305 | * @return bool |
| 306 | 306 | */ |
| 307 | - protected function canLogEntry($level, $backtraceLine) |
|
| 307 | + protected function canLogEntry( $level, $backtraceLine ) |
|
| 308 | 308 | { |
| 309 | - $levelExists = array_key_exists($level, $this->getLevels()); |
|
| 310 | - if (!Str::contains($backtraceLine, glsr()->path())) { |
|
| 309 | + $levelExists = array_key_exists( $level, $this->getLevels() ); |
|
| 310 | + if( !Str::contains( $backtraceLine, glsr()->path() ) ) { |
|
| 311 | 311 | return $levelExists; // ignore level restriction if triggered outside of the plugin |
| 312 | 312 | } |
| 313 | 313 | return $levelExists && $level >= $this->getLevel(); |
@@ -318,17 +318,17 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | protected function getBacktraceLine() |
| 320 | 320 | { |
| 321 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
| 322 | - $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
| 323 | - if (false !== $search) { |
|
| 324 | - return $this->buildBacktraceLine($backtrace, (int) $search); |
|
| 321 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 6 ); |
|
| 322 | + $search = array_search( 'glsr_log', glsr_array_column( $backtrace, 'function' ) ); |
|
| 323 | + if( false !== $search ) { |
|
| 324 | + return $this->buildBacktraceLine( $backtrace, (int)$search ); |
|
| 325 | 325 | } |
| 326 | - $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
| 327 | - if (false !== $search) { |
|
| 328 | - $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
| 326 | + $search = array_search( 'log', glsr_array_column( $backtrace, 'function' ) ); |
|
| 327 | + if( false !== $search ) { |
|
| 328 | + $index = '{closure}' == Arr::get( $backtrace, ($search + 2).'.function' ) |
|
| 329 | 329 | ? $search + 4 |
| 330 | 330 | : $search + 1; |
| 331 | - return $this->buildBacktraceLine($backtrace, $index); |
|
| 331 | + return $this->buildBacktraceLine( $backtrace, $index ); |
|
| 332 | 332 | } |
| 333 | 333 | return 'Unknown'; |
| 334 | 334 | } |
@@ -337,23 +337,23 @@ discard block |
||
| 337 | 337 | * @param mixed $data |
| 338 | 338 | * @return string |
| 339 | 339 | */ |
| 340 | - protected function getBacktraceLineFromData($data) |
|
| 340 | + protected function getBacktraceLineFromData( $data ) |
|
| 341 | 341 | { |
| 342 | 342 | $backtrace = $data instanceof Throwable |
| 343 | 343 | ? $data->getTrace() |
| 344 | - : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
| 345 | - return $this->buildBacktraceLine($backtrace, 0); |
|
| 344 | + : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 ); |
|
| 345 | + return $this->buildBacktraceLine( $backtrace, 0 ); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
| 349 | 349 | * @param mixed $data |
| 350 | 350 | * @return string |
| 351 | 351 | */ |
| 352 | - protected function getMessageFromData($data) |
|
| 352 | + protected function getMessageFromData( $data ) |
|
| 353 | 353 | { |
| 354 | 354 | return $data instanceof Throwable |
| 355 | - ? $this->normalizeThrowableMessage($data->getMessage()) |
|
| 356 | - : print_r($data, 1); |
|
| 355 | + ? $this->normalizeThrowableMessage( $data->getMessage() ) |
|
| 356 | + : print_r( $data, 1 ); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -362,53 +362,53 @@ discard block |
||
| 362 | 362 | * @param array $context |
| 363 | 363 | * @return string |
| 364 | 364 | */ |
| 365 | - protected function interpolate($message, $context = []) |
|
| 365 | + protected function interpolate( $message, $context = [] ) |
|
| 366 | 366 | { |
| 367 | - if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
| 368 | - return print_r($message, true); |
|
| 367 | + if( $this->isObjectOrArray( $message ) || !is_array( $context ) ) { |
|
| 368 | + return print_r( $message, true ); |
|
| 369 | 369 | } |
| 370 | 370 | $replace = []; |
| 371 | - foreach ($context as $key => $value) { |
|
| 372 | - $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
| 371 | + foreach( $context as $key => $value ) { |
|
| 372 | + $replace['{'.$key.'}'] = $this->normalizeValue( $value ); |
|
| 373 | 373 | } |
| 374 | - return strtr($message, $replace); |
|
| 374 | + return strtr( $message, $replace ); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
| 378 | 378 | * @param mixed $value |
| 379 | 379 | * @return bool |
| 380 | 380 | */ |
| 381 | - protected function isObjectOrArray($value) |
|
| 381 | + protected function isObjectOrArray( $value ) |
|
| 382 | 382 | { |
| 383 | - return is_object($value) || is_array($value); |
|
| 383 | + return is_object( $value ) || is_array( $value ); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
| 387 | 387 | * @param string $backtraceLine |
| 388 | 388 | * @return string |
| 389 | 389 | */ |
| 390 | - protected function normalizeBacktraceLine($backtraceLine) |
|
| 390 | + protected function normalizeBacktraceLine( $backtraceLine ) |
|
| 391 | 391 | { |
| 392 | 392 | $search = [ |
| 393 | - glsr()->path('plugin/'), |
|
| 394 | - glsr()->path('plugin/', false), |
|
| 395 | - trailingslashit(glsr()->path()), |
|
| 396 | - trailingslashit(glsr()->path('', false)), |
|
| 393 | + glsr()->path( 'plugin/' ), |
|
| 394 | + glsr()->path( 'plugin/', false ), |
|
| 395 | + trailingslashit( glsr()->path() ), |
|
| 396 | + trailingslashit( glsr()->path( '', false ) ), |
|
| 397 | 397 | WP_CONTENT_DIR, |
| 398 | 398 | ABSPATH, |
| 399 | 399 | ]; |
| 400 | - return str_replace(array_unique($search), '', $backtraceLine); |
|
| 400 | + return str_replace( array_unique( $search ), '', $backtraceLine ); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
| 404 | 404 | * @param string $message |
| 405 | 405 | * @return string |
| 406 | 406 | */ |
| 407 | - protected function normalizeThrowableMessage($message) |
|
| 407 | + protected function normalizeThrowableMessage( $message ) |
|
| 408 | 408 | { |
| 409 | - $calledIn = strpos($message, ', called in'); |
|
| 409 | + $calledIn = strpos( $message, ', called in' ); |
|
| 410 | 410 | return false !== $calledIn |
| 411 | - ? substr($message, 0, $calledIn) |
|
| 411 | + ? substr( $message, 0, $calledIn ) |
|
| 412 | 412 | : $message; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -416,14 +416,14 @@ discard block |
||
| 416 | 416 | * @param mixed $value |
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | - protected function normalizeValue($value) |
|
| 419 | + protected function normalizeValue( $value ) |
|
| 420 | 420 | { |
| 421 | - if ($value instanceof DateTime) { |
|
| 422 | - $value = $value->format('Y-m-d H:i:s'); |
|
| 423 | - } elseif ($this->isObjectOrArray($value)) { |
|
| 424 | - $value = json_encode($value); |
|
| 421 | + if( $value instanceof DateTime ) { |
|
| 422 | + $value = $value->format( 'Y-m-d H:i:s' ); |
|
| 423 | + } elseif( $this->isObjectOrArray( $value ) ) { |
|
| 424 | + $value = json_encode( $value ); |
|
| 425 | 425 | } |
| 426 | - return (string) $value; |
|
| 426 | + return (string)$value; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | protected function reset() |
| 433 | 433 | { |
| 434 | - if ($this->size() <= pow(1024, 2) / 8) { |
|
| 434 | + if( $this->size() <= pow( 1024, 2 ) / 8 ) { |
|
| 435 | 435 | return; |
| 436 | 436 | } |
| 437 | 437 | $this->clear(); |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | $this->file, |
| 440 | 440 | $this->buildLogEntry( |
| 441 | 441 | static::NOTICE, |
| 442 | - __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
| 442 | + __( 'Console was automatically cleared (128 KB maximum size)', 'site-reviews' ) |
|
| 443 | 443 | ) |
| 444 | 444 | ); |
| 445 | 445 | } |