@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | $yamlFile = $this->getYamlFile(); |
| 43 | 43 | $yaml = $this->normalizeYamlValues( $this->normalize( |
| 44 | 44 | $this->parseYaml( file_get_contents( $yamlFile ), $yamlFile ) |
| 45 | - )); |
|
| 46 | - if( !$yaml['disable_config'] ) { |
|
| 47 | - $config = array_filter( (array) get_option( Config::id(), [] )); |
|
| 45 | + ) ); |
|
| 46 | + if( !$yaml[ 'disable_config' ] ) { |
|
| 47 | + $config = array_filter( (array) get_option( Config::id(), [ ] ) ); |
|
| 48 | 48 | } |
| 49 | 49 | return empty( $config ) |
| 50 | - ? $this->setTimestamp( $yaml, filemtime( $yamlFile )) |
|
| 51 | - : $this->normalizeYamlValues( $this->normalize( $config )); |
|
| 50 | + ? $this->setTimestamp( $yaml, filemtime( $yamlFile ) ) |
|
| 51 | + : $this->normalizeYamlValues( $this->normalize( $config ) ); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -57,15 +57,15 @@ discard block |
||
| 57 | 57 | public function compile() |
| 58 | 58 | { |
| 59 | 59 | $configFile = $this->getCompileDestination(); |
| 60 | - if( $this->shouldCompile( $configFile )) { |
|
| 60 | + if( $this->shouldCompile( $configFile ) ) { |
|
| 61 | 61 | $config = $this->normalizeArray( $this->options ); |
| 62 | 62 | if( $this->parseError ) { |
| 63 | 63 | return (object) $config; |
| 64 | 64 | } |
| 65 | 65 | file_put_contents( $configFile, sprintf( '<?php // DO NOT MODIFY THIS FILE DIRECTLY!%sreturn (object) %s;', |
| 66 | 66 | PHP_EOL, |
| 67 | - $this->parseRawStrings( var_export( $this->setTimestamp( $config ), true )) |
|
| 68 | - )); |
|
| 67 | + $this->parseRawStrings( var_export( $this->setTimestamp( $config ), true ) ) |
|
| 68 | + ) ); |
|
| 69 | 69 | } |
| 70 | 70 | return include $configFile; |
| 71 | 71 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | public function convertArrayToYaml( array $array ) |
| 77 | 77 | { |
| 78 | 78 | return !empty( $array ) |
| 79 | - ? trim( $this->parseRawStrings( $this->dumpYaml( $array ))) |
|
| 79 | + ? trim( $this->parseRawStrings( $this->dumpYaml( $array ) ) ) |
|
| 80 | 80 | : ''; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | trailingslashit( trailingslashit( $theme->theme_root ) . $theme->template ), |
| 104 | 104 | trailingslashit( WP_CONTENT_DIR ), |
| 105 | 105 | trailingslashit( ABSPATH ), |
| 106 | - trailingslashit( dirname( ABSPATH )), |
|
| 107 | - trailingslashit( dirname( dirname( ABSPATH ))), |
|
| 108 | - ]); |
|
| 106 | + trailingslashit( dirname( ABSPATH ) ), |
|
| 107 | + trailingslashit( dirname( dirname( ABSPATH ) ) ), |
|
| 108 | + ] ); |
|
| 109 | 109 | foreach( (array) $configLocations as $location ) { |
| 110 | - if( !file_exists( $location . $configYaml ))continue; |
|
| 110 | + if( !file_exists( $location . $configYaml ) )continue; |
|
| 111 | 111 | return $location . $configYaml; |
| 112 | 112 | } |
| 113 | 113 | return $this->app->path( 'defaults.yml' ); |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | public function normalizeArray( array $array ) |
| 120 | 120 | { |
| 121 | 121 | array_walk( $array, function( &$value, $key ) { |
| 122 | - if( !is_numeric( $value ) && is_string( $value )) { |
|
| 122 | + if( !is_numeric( $value ) && is_string( $value ) ) { |
|
| 123 | 123 | $value = $this->parseYaml( $value, $key ); |
| 124 | 124 | if( $this->parseError == $key ) { |
| 125 | - $value = []; |
|
| 125 | + $value = [ ]; |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | }); |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | public function setTimestamp( array $config, $timestamp = null ) |
| 148 | 148 | { |
| 149 | 149 | $timestamp || $timestamp = time(); |
| 150 | - $config['updated'] = $timestamp; |
|
| 150 | + $config[ 'updated' ] = $timestamp; |
|
| 151 | 151 | return $config; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | return wp_parse_args( |
| 173 | 173 | $config, |
| 174 | 174 | $this->parseYaml( |
| 175 | - file_get_contents( $this->app->path( 'defaults.yml' )), |
|
| 175 | + file_get_contents( $this->app->path( 'defaults.yml' ) ), |
|
| 176 | 176 | $this->app->path( 'defaults.yml' ) |
| 177 | 177 | ) |
| 178 | 178 | ); |
@@ -186,13 +186,13 @@ discard block |
||
| 186 | 186 | protected function parseRawStrings( $configString ) |
| 187 | 187 | { |
| 188 | 188 | $strings = apply_filters( 'pollux/config/raw_strings', static::RAW_STRINGS ); |
| 189 | - if( empty( $strings )) { |
|
| 189 | + if( empty( $strings ) ) { |
|
| 190 | 190 | return $configString; |
| 191 | 191 | } |
| 192 | 192 | $pattern = '/(\')((' . implode( '|', $strings ) . ')\(?.+\))(\')/'; |
| 193 | 193 | return stripslashes( |
| 194 | 194 | preg_replace_callback( $pattern, function( $matches ) { |
| 195 | - return str_replace( "''", "'", $matches[2] ); |
|
| 195 | + return str_replace( "''", "'", $matches[ 2 ] ); |
|
| 196 | 196 | }, $configString ) |
| 197 | 197 | ); |
| 198 | 198 | } |
@@ -211,13 +211,13 @@ discard block |
||
| 211 | 211 | if( $file ) { |
| 212 | 212 | $file = sprintf( '<code>%s</code>', $file ); |
| 213 | 213 | } |
| 214 | - $this->app->make( 'Notice' )->addError([ |
|
| 214 | + $this->app->make( 'Notice' )->addError( [ |
|
| 215 | 215 | sprintf( '<strong>Pollux Error:</strong> Unable to parse config at line %s (near "%s").', |
| 216 | 216 | $e->getParsedLine(), |
| 217 | 217 | $e->getSnippet() |
| 218 | 218 | ), |
| 219 | 219 | $file |
| 220 | - ]); |
|
| 220 | + ] ); |
|
| 221 | 221 | return $value; |
| 222 | 222 | } |
| 223 | 223 | } |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | protected function shouldCompile( $configFile ) |
| 230 | 230 | { |
| 231 | - if( !file_exists( $configFile )) { |
|
| 231 | + if( !file_exists( $configFile ) ) { |
|
| 232 | 232 | return true; |
| 233 | 233 | } |
| 234 | 234 | $config = include $configFile; |
@@ -107,7 +107,9 @@ discard block |
||
| 107 | 107 | trailingslashit( dirname( dirname( ABSPATH ))), |
| 108 | 108 | ]); |
| 109 | 109 | foreach( (array) $configLocations as $location ) { |
| 110 | - if( !file_exists( $location . $configYaml ))continue; |
|
| 110 | + if( !file_exists( $location . $configYaml )) { |
|
| 111 | + continue; |
|
| 112 | + } |
|
| 111 | 113 | return $location . $configYaml; |
| 112 | 114 | } |
| 113 | 115 | return $this->app->path( 'defaults.yml' ); |
@@ -118,7 +120,8 @@ discard block |
||
| 118 | 120 | */ |
| 119 | 121 | public function normalizeArray( array $array ) |
| 120 | 122 | { |
| 121 | - array_walk( $array, function( &$value, $key ) { |
|
| 123 | + array_walk( $array, function( &$value, $key ) |
|
| 124 | + { |
|
| 122 | 125 | if( !is_numeric( $value ) && is_string( $value )) { |
| 123 | 126 | $value = $this->parseYaml( $value, $key ); |
| 124 | 127 | if( $this->parseError == $key ) { |
@@ -134,7 +137,8 @@ discard block |
||
| 134 | 137 | */ |
| 135 | 138 | public function normalizeYamlValues( array $array ) |
| 136 | 139 | { |
| 137 | - return array_map( function( $value ) { |
|
| 140 | + return array_map( function( $value ) |
|
| 141 | + { |
|
| 138 | 142 | return is_array( $value ) |
| 139 | 143 | ? $this->convertArrayToYaml( $value ) |
| 140 | 144 | : $value; |
@@ -191,7 +195,8 @@ discard block |
||
| 191 | 195 | } |
| 192 | 196 | $pattern = '/(\')((' . implode( '|', $strings ) . ')\(?.+\))(\')/'; |
| 193 | 197 | return stripslashes( |
| 194 | - preg_replace_callback( $pattern, function( $matches ) { |
|
| 198 | + preg_replace_callback( $pattern, function( $matches ) |
|
| 199 | + { |
|
| 195 | 200 | return str_replace( "''", "'", $matches[2] ); |
| 196 | 201 | }, $configString ) |
| 197 | 202 | ); |