@@ -7,22 +7,22 @@ discard block |
||
| 7 | 7 | /** |
| 8 | 8 | * @return string |
| 9 | 9 | */ |
| 10 | - public function buildAttributes( array $atts = [] ) |
|
| 10 | + public function buildAttributes(array $atts = []) |
|
| 11 | 11 | { |
| 12 | 12 | $attributes = []; |
| 13 | - foreach( $atts as $key => $value ) { |
|
| 14 | - $attributes[] = sprintf( '%s="%s"', $key, $value ); |
|
| 13 | + foreach ($atts as $key => $value) { |
|
| 14 | + $attributes[] = sprintf('%s="%s"', $key, $value); |
|
| 15 | 15 | } |
| 16 | - return implode( ' ', $attributes ); |
|
| 16 | + return implode(' ', $attributes); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @return string |
| 21 | 21 | */ |
| 22 | - public function buildAttributesFor( $tag, array $atts = [] ) |
|
| 22 | + public function buildAttributesFor($tag, array $atts = []) |
|
| 23 | 23 | { |
| 24 | 24 | return $this->buildAttributes( |
| 25 | - wp_parse_args( $atts, apply_filters( "castor/render/$tag/attributes", [] )) |
|
| 25 | + wp_parse_args($atts, apply_filters("castor/render/$tag/attributes", [])) |
|
| 26 | 26 | ); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | - public function buildClassName( $name, $path = '' ) |
|
| 35 | + public function buildClassName($name, $path = '') |
|
| 36 | 36 | { |
| 37 | - $className = array_map( 'ucfirst', array_map( 'strtolower', preg_split( '/[-_]/', $name ))); |
|
| 38 | - $className = implode( '', $className ); |
|
| 37 | + $className = array_map('ucfirst', array_map('strtolower', preg_split('/[-_]/', $name))); |
|
| 38 | + $className = implode('', $className); |
|
| 39 | 39 | |
| 40 | - return !empty( $path ) |
|
| 41 | - ? str_replace( '\\\\', '\\', sprintf( '%s\%s', $path, $className )) |
|
| 40 | + return !empty($path) |
|
| 41 | + ? str_replace('\\\\', '\\', sprintf('%s\%s', $path, $className)) |
|
| 42 | 42 | : $className; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @return string |
| 50 | 50 | */ |
| 51 | - public function buildMethodName( $name, $prefix = 'get' ) |
|
| 51 | + public function buildMethodName($name, $prefix = 'get') |
|
| 52 | 52 | { |
| 53 | - return lcfirst( $this->buildClassName( $prefix . '-' . $name )); |
|
| 53 | + return lcfirst($this->buildClassName($prefix . '-' . $name)); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | - public function endWith( $suffix, $string, $unique = true ) |
|
| 63 | + public function endWith($suffix, $string, $unique = true) |
|
| 64 | 64 | { |
| 65 | - return $unique && $this->endsWith( $suffix, $string ) |
|
| 65 | + return $unique && $this->endsWith($suffix, $string) |
|
| 66 | 66 | ? $string |
| 67 | 67 | : $string . $suffix; |
| 68 | 68 | } |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | - public function endsWith( $needle, $haystack ) |
|
| 76 | + public function endsWith($needle, $haystack) |
|
| 77 | 77 | { |
| 78 | - $length = strlen( $needle ); |
|
| 78 | + $length = strlen($needle); |
|
| 79 | 79 | return $length != 0 |
| 80 | - ? substr( $haystack, -$length ) === $needle |
|
| 80 | + ? substr($haystack, -$length) === $needle |
|
| 81 | 81 | : true; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | * |
| 88 | 88 | * @return void |
| 89 | 89 | */ |
| 90 | - public function printTag( $tag, $value, array $attributes = [] ) |
|
| 90 | + public function printTag($tag, $value, array $attributes = []) |
|
| 91 | 91 | { |
| 92 | - $attributes = $this->buildAttributesFor( $tag, $attributes ); |
|
| 92 | + $attributes = $this->buildAttributesFor($tag, $attributes); |
|
| 93 | 93 | |
| 94 | - printf( '<%s>%s</%s>', |
|
| 95 | - rtrim( sprintf( '%s %s', $tag, $attributes )), |
|
| 94 | + printf('<%s>%s</%s>', |
|
| 95 | + rtrim(sprintf('%s %s', $tag, $attributes)), |
|
| 96 | 96 | $value, |
| 97 | 97 | $tag |
| 98 | 98 | ); |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | - public function startWith( $prefix, $string, $unique = true ) |
|
| 108 | + public function startWith($prefix, $string, $unique = true) |
|
| 109 | 109 | { |
| 110 | - return $unique && $this->startsWith( $prefix, $string ) |
|
| 110 | + return $unique && $this->startsWith($prefix, $string) |
|
| 111 | 111 | ? $string |
| 112 | 112 | : $prefix . $string; |
| 113 | 113 | } |
@@ -118,9 +118,9 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return string |
| 120 | 120 | */ |
| 121 | - public function startsWith( $needle, $haystack ) |
|
| 121 | + public function startsWith($needle, $haystack) |
|
| 122 | 122 | { |
| 123 | - return substr( $haystack, 0, strlen( $needle )) === $needle; |
|
| 123 | + return substr($haystack, 0, strlen($needle)) === $needle; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -128,12 +128,12 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @return array |
| 130 | 130 | */ |
| 131 | - public function toArray( $value ) |
|
| 131 | + public function toArray($value) |
|
| 132 | 132 | { |
| 133 | - if( is_string( $value )) { |
|
| 134 | - $value = trim( $value ); |
|
| 133 | + if (is_string($value)) { |
|
| 134 | + $value = trim($value); |
|
| 135 | 135 | } |
| 136 | - return array_filter((array) $value ); |
|
| 136 | + return array_filter((array) $value); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -143,11 +143,11 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | - public function trimLeft( $string, $needle, $caseSensitive = true ) |
|
| 146 | + public function trimLeft($string, $needle, $caseSensitive = true) |
|
| 147 | 147 | { |
| 148 | 148 | $strPos = $caseSensitive ? "strpos" : "stripos"; |
| 149 | - if( $strPos( $string, $needle ) === 0 ) { |
|
| 150 | - $string = substr( $string, strlen( $needle )); |
|
| 149 | + if ($strPos($string, $needle) === 0) { |
|
| 150 | + $string = substr($string, strlen($needle)); |
|
| 151 | 151 | } |
| 152 | 152 | return $string; |
| 153 | 153 | } |
@@ -159,11 +159,11 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return string |
| 161 | 161 | */ |
| 162 | - public function trimRight( $string, $needle, $caseSensitive = true ) |
|
| 162 | + public function trimRight($string, $needle, $caseSensitive = true) |
|
| 163 | 163 | { |
| 164 | 164 | $strPos = $caseSensitive ? "strpos" : "stripos"; |
| 165 | - if( $strPos( $string, $needle, strlen( $string ) - strlen( $needle )) !== false ) { |
|
| 166 | - $string = substr( $string, 0, -strlen( $needle )); |
|
| 165 | + if ($strPos($string, $needle, strlen($string) - strlen($needle)) !== false) { |
|
| 166 | + $string = substr($string, 0, -strlen($needle)); |
|
| 167 | 167 | } |
| 168 | 168 | return $string; |
| 169 | 169 | } |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return array|string |
| 66 | 66 | */ |
| 67 | - public function form( array $args = [], $implode = false ) |
|
| 67 | + public function form(array $args = [], $implode = false) |
|
| 68 | 68 | { |
| 69 | - $attributes = $this->parseAttributes( self::FORM_ATTRIBUTES, $args ); |
|
| 69 | + $attributes = $this->parseAttributes(self::FORM_ATTRIBUTES, $args); |
|
| 70 | 70 | |
| 71 | - return $this->maybeImplode( $attributes, $implode ); |
|
| 71 | + return $this->maybeImplode($attributes, $implode); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return array|string |
| 78 | 78 | */ |
| 79 | - public function input( array $args = [], $implode = false ) |
|
| 79 | + public function input(array $args = [], $implode = false) |
|
| 80 | 80 | { |
| 81 | 81 | $this->filterInputType(); |
| 82 | 82 | |
| 83 | - $attributes = $this->parseAttributes( self::INPUT_ATTRIBUTES, $args ); |
|
| 83 | + $attributes = $this->parseAttributes(self::INPUT_ATTRIBUTES, $args); |
|
| 84 | 84 | |
| 85 | - return $this->maybeImplode( $attributes, $implode ); |
|
| 85 | + return $this->maybeImplode($attributes, $implode); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -92,24 +92,24 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return array|string |
| 94 | 94 | */ |
| 95 | - public function maybeImplode( array $attributes, $implode = true ) |
|
| 95 | + public function maybeImplode(array $attributes, $implode = true) |
|
| 96 | 96 | { |
| 97 | - if( !$implode || $implode !== 'implode' ) { |
|
| 97 | + if (!$implode || $implode !== 'implode') { |
|
| 98 | 98 | return $attributes; |
| 99 | 99 | } |
| 100 | 100 | $results = []; |
| 101 | - foreach( $attributes as $key => $value ) { |
|
| 101 | + foreach ($attributes as $key => $value) { |
|
| 102 | 102 | // if data attributes, use single quotes in case of json encoded values |
| 103 | - $quotes = false !== stripos( $key, 'data-' ) ? "'" : '"'; |
|
| 104 | - if( is_array( $value )) { |
|
| 105 | - $value = json_encode( $value ); |
|
| 103 | + $quotes = false !== stripos($key, 'data-') ? "'" : '"'; |
|
| 104 | + if (is_array($value)) { |
|
| 105 | + $value = json_encode($value); |
|
| 106 | 106 | $quotes = "'"; |
| 107 | 107 | } |
| 108 | - $results[] = is_string( $key ) |
|
| 109 | - ? sprintf( '%1$s=%3$s%2$s%3$s', $key, $value, $quotes ) |
|
| 108 | + $results[] = is_string($key) |
|
| 109 | + ? sprintf('%1$s=%3$s%2$s%3$s', $key, $value, $quotes) |
|
| 110 | 110 | : $value; |
| 111 | 111 | } |
| 112 | - return implode( ' ', $results ); |
|
| 112 | + return implode(' ', $results); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -117,11 +117,11 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @return array|string |
| 119 | 119 | */ |
| 120 | - public function select( array $args = [], $implode = false ) |
|
| 120 | + public function select(array $args = [], $implode = false) |
|
| 121 | 121 | { |
| 122 | - $attributes = $this->parseAttributes( self::SELECT_ATTRIBUTES, $args ); |
|
| 122 | + $attributes = $this->parseAttributes(self::SELECT_ATTRIBUTES, $args); |
|
| 123 | 123 | |
| 124 | - return $this->maybeImplode( $attributes, $implode ); |
|
| 124 | + return $this->maybeImplode($attributes, $implode); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return array|string |
| 131 | 131 | */ |
| 132 | - public function textarea( array $args = [], $implode = false ) |
|
| 132 | + public function textarea(array $args = [], $implode = false) |
|
| 133 | 133 | { |
| 134 | - $attributes = $this->parseAttributes( self::TEXTAREA_ATTRIBUTES, $args ); |
|
| 134 | + $attributes = $this->parseAttributes(self::TEXTAREA_ATTRIBUTES, $args); |
|
| 135 | 135 | |
| 136 | - return $this->maybeImplode( $attributes, $implode ); |
|
| 136 | + return $this->maybeImplode($attributes, $implode); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -142,31 +142,31 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * @return array |
| 144 | 144 | */ |
| 145 | - protected function filterAttributes( array $attributeKeys ) |
|
| 145 | + protected function filterAttributes(array $attributeKeys) |
|
| 146 | 146 | { |
| 147 | - $filtered = array_intersect_key( $this->args, array_flip( $attributeKeys )); |
|
| 147 | + $filtered = array_intersect_key($this->args, array_flip($attributeKeys)); |
|
| 148 | 148 | |
| 149 | 149 | // normalize truthy boolean attributes |
| 150 | - foreach( $filtered as $key => $value ) { |
|
| 151 | - if( !in_array( $key, self::BOOLEAN_ATTRIBUTES ))continue; |
|
| 150 | + foreach ($filtered as $key => $value) { |
|
| 151 | + if (!in_array($key, self::BOOLEAN_ATTRIBUTES))continue; |
|
| 152 | 152 | |
| 153 | - if( $value !== false ) { |
|
| 154 | - $filtered[ $key ] = ''; |
|
| 153 | + if ($value !== false) { |
|
| 154 | + $filtered[$key] = ''; |
|
| 155 | 155 | continue; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - unset( $filtered[ $key ] ); |
|
| 158 | + unset($filtered[$key]); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $filteredKeys = array_filter( array_keys( $filtered ), function( $key ) use ( $filtered ) { |
|
| 161 | + $filteredKeys = array_filter(array_keys($filtered), function($key) use ($filtered) { |
|
| 162 | 162 | return !( |
| 163 | - empty( $filtered[ $key ] ) |
|
| 164 | - && !is_numeric( $filtered[ $key ] ) |
|
| 165 | - && !in_array( $key, self::BOOLEAN_ATTRIBUTES ) |
|
| 163 | + empty($filtered[$key]) |
|
| 164 | + && !is_numeric($filtered[$key]) |
|
| 165 | + && !in_array($key, self::BOOLEAN_ATTRIBUTES) |
|
| 166 | 166 | ); |
| 167 | 167 | }); |
| 168 | 168 | |
| 169 | - return array_intersect_key( $filtered, array_flip( $filteredKeys )); |
|
| 169 | + return array_intersect_key($filtered, array_flip($filteredKeys)); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -174,34 +174,34 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | protected function filterGlobalAttributes() |
| 176 | 176 | { |
| 177 | - $global = $this->filterAttributes( self::GLOBAL_ATTRIBUTES ); |
|
| 177 | + $global = $this->filterAttributes(self::GLOBAL_ATTRIBUTES); |
|
| 178 | 178 | |
| 179 | 179 | $wildcards = []; |
| 180 | 180 | |
| 181 | - foreach( self::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard ) { |
|
| 181 | + foreach (self::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
| 182 | 182 | |
| 183 | - foreach( $this->args as $key => $value ) { |
|
| 183 | + foreach ($this->args as $key => $value) { |
|
| 184 | 184 | |
| 185 | - $length = strlen( $wildcard ); |
|
| 186 | - $result = substr( $key, 0, $length) === $wildcard; |
|
| 185 | + $length = strlen($wildcard); |
|
| 186 | + $result = substr($key, 0, $length) === $wildcard; |
|
| 187 | 187 | |
| 188 | - if( $result ) { |
|
| 188 | + if ($result) { |
|
| 189 | 189 | // only allow data attributes to have an empty value |
| 190 | - if( $wildcard != 'data-' && empty( $value ))continue; |
|
| 190 | + if ($wildcard != 'data-' && empty($value))continue; |
|
| 191 | 191 | |
| 192 | - if( is_array( $value )) { |
|
| 192 | + if (is_array($value)) { |
|
| 193 | 193 | |
| 194 | - if( $wildcard != 'data-' )continue; |
|
| 194 | + if ($wildcard != 'data-')continue; |
|
| 195 | 195 | |
| 196 | - $value = json_encode( $value ); |
|
| 196 | + $value = json_encode($value); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - $wildcards[ $key ] = $value; |
|
| 199 | + $wildcards[$key] = $value; |
|
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - return array_merge( $global, $wildcards ); |
|
| 204 | + return array_merge($global, $wildcards); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | protected function filterInputType() |
| 211 | 211 | { |
| 212 | - if( !isset( $this->args['type'] ) || !in_array( $this->args['type'], self::INPUT_TYPES )) { |
|
| 212 | + if (!isset($this->args['type']) || !in_array($this->args['type'], self::INPUT_TYPES)) { |
|
| 213 | 213 | $this->args['type'] = 'text'; |
| 214 | 214 | } |
| 215 | 215 | } |
@@ -217,15 +217,15 @@ discard block |
||
| 217 | 217 | /** |
| 218 | 218 | * @return array |
| 219 | 219 | */ |
| 220 | - protected function parseAttributes( array $attributes, array $args = [] ) |
|
| 220 | + protected function parseAttributes(array $attributes, array $args = []) |
|
| 221 | 221 | { |
| 222 | - if( !empty( $args )) { |
|
| 223 | - $this->args = array_change_key_case( $args ); |
|
| 222 | + if (!empty($args)) { |
|
| 223 | + $this->args = array_change_key_case($args); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | $global = $this->filterGlobalAttributes(); |
| 227 | - $local = $this->filterAttributes( $attributes ); |
|
| 227 | + $local = $this->filterAttributes($attributes); |
|
| 228 | 228 | |
| 229 | - return array_merge( $global, $local ); |
|
| 229 | + return array_merge($global, $local); |
|
| 230 | 230 | } |
| 231 | 231 | } |