Completed
Push — master ( 8fac4c...3bc63e )
by Fenz
02:33
created
libs/Parser/Node/TagNode.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @var array
51 51
 	 */
52
-	private $attributes=[];
52
+	private $attributes=[ ];
53 53
 
54 54
 	/**
55 55
 	 * Real constructor.
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
 	protected function construct():parent
62 62
 	{
63 63
 
64
-		$name= $this->line->pregGet('/(?<=^-)[\w-:]+/');
64
+		$name=$this->line->pregGet('/(?<=^-)[\w-:]+/');
65 65
 		$this->name=$name;
66 66
 
67
-		$this->loadConfig($name,$this->document);
67
+		$this->loadConfig($name, $this->document);
68 68
 
69
-		$this->tagName=$this->config['name']??$name;
70
-		$this->isEmpty= $this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags',$this->tagName);
71
-		isset($this->config['default_attributes']) and array_walk($this->config['default_attributes'],function( $value,$key ){ $this->setAttribute($key,$value); });
69
+		$this->tagName=$this->config[ 'name' ]??$name;
70
+		$this->isEmpty=$this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags', $this->tagName);
71
+		isset($this->config[ 'default_attributes' ]) and array_walk($this->config[ 'default_attributes' ], function( $value, $key ){ $this->setAttribute($key, $value); });
72 72
 
73 73
 		return $this;
74 74
 	}
@@ -82,30 +82,30 @@  discard block
 block discarded – undo
82 82
 	 */
83 83
 	public function open():string
84 84
 	{
85
-		if( isset($this->config['opener']) )
86
-			{ return $this->config['opener']; }
85
+		if( isset($this->config[ 'opener' ]) )
86
+			{ return $this->config[ 'opener' ]; }
87 87
 
88
-		if( isset($this->config['params']) )
88
+		if( isset($this->config[ 'params' ]) )
89 89
 			{ $this->parseParams(); }
90 90
 
91
-		if( isset($this->config['name_value']) )
91
+		if( isset($this->config[ 'name_value' ]) )
92 92
 			{ $this->parseNameValue(); }
93 93
 
94
-		if( isset($this->config['link']) )
94
+		if( isset($this->config[ 'link' ]) )
95 95
 			{ $this->parseLink(); }
96 96
 
97
-		if( isset($this->config['target']) )
97
+		if( isset($this->config[ 'target' ]) )
98 98
 			{ $this->parseTarget(); }
99 99
 
100
-		if( isset($this->config['alt']) )
100
+		if( isset($this->config[ 'alt' ]) )
101 101
 			{ $this->parseAlt(); }
102 102
 
103 103
 		$this->parseCommonAttributes();
104 104
 
105
-		if( isset($this->config['in_scope']) && isset($this->config['scope_function']) && is_callable($this->config['scope_function']) )
106
-			{ $this->config['scope_function']->call($this,$this->document->scope); }
105
+		if( isset($this->config[ 'in_scope' ]) && isset($this->config[ 'scope_function' ]) && is_callable($this->config[ 'scope_function' ]) )
106
+			{ $this->config[ 'scope_function' ]->call($this, $this->document->scope); }
107 107
 
108
-		$finisher= $this->isEmpty ? ' />' : '>';
108
+		$finisher=$this->isEmpty? ' />' : '>';
109 109
 
110 110
 		return "<{$this->tagName}{$this->attributesString}{$finisher}";
111 111
 	}
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function close( Line$closerLine ):string
123 123
 	{
124
-		return $this->isEmpty ? '' : $this->config['closer']??"</{$this->tagName}>";
124
+		return $this->isEmpty? '' : $this->config[ 'closer' ]??"</{$this->tagName}>";
125 125
 	}
126 126
 
127 127
 	/**
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 */
134 134
 	public function getEmbed():string
135 135
 	{
136
-		return $this->config['embedding']??'';
136
+		return $this->config[ 'embedding' ]??'';
137 137
 	}
138 138
 
139 139
 	/**
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 */
146 146
 	public function getScope()
147 147
 	{
148
-		return $this->config['scope']??null;
148
+		return $this->config[ 'scope' ]??null;
149 149
 	}
150 150
 
151 151
 	/**
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
 	 */
158 158
 	protected function parseParams():self
159 159
 	{
160
-		$params= preg_split('/(?<!\\\\)\\|/',$this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/',1));
160
+		$params=preg_split('/(?<!\\\\)\\|/', $this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/', 1));
161 161
 
162
-		if( ($m= count($params)) != ($n= count($this->config['params'])) ){$this->document->throw("Tag $this->name has $n parameters $m given.");}
162
+		if( ($m=count($params))!=($n=count($this->config[ 'params' ])) ){$this->document->throw("Tag $this->name has $n parameters $m given."); }
163 163
 
164
-		array_map(function( $key, $value ){return $this->setAttribute($key,str_replace('\\|','|',$value));},$this->config['params'],$params);
164
+		array_map(function( $key, $value ){return $this->setAttribute($key, str_replace('\\|', '|', $value)); },$this->config[ 'params' ], $params);
165 165
 
166 166
 		return $this;
167 167
 	}
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
 	 */
176 176
 	protected function parseNameValue():self
177 177
 	{
178
-		$params= $this->line->pregGet('/ <(.*?)>(?= |$)/',1)
179
-		 and $params= preg_split('/(?<!\\\\)\\|/',$params)
180
-		  and array_map(function( $key, $value ){return isset($key)&&isset($value) ? $this->setAttribute($key,$this->checkExpression(str_replace('\\|','|',$value))) : '';},$this->config['name_value'],$params);
178
+		$params=$this->line->pregGet('/ <(.*?)>(?= |$)/', 1)
179
+		 and $params=preg_split('/(?<!\\\\)\\|/', $params)
180
+		  and array_map(function( $key, $value ){return isset($key) && isset($value)? $this->setAttribute($key, $this->checkExpression(str_replace('\\|', '|', $value))) : ''; },$this->config[ 'name_value' ], $params);
181 181
 
182 182
 		return $this;
183 183
 	}
@@ -219,13 +219,13 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	protected function parseLink():self
221 221
 	{
222
-		return $this->setMultinameAttribute('link',$this->sectionLedBy('@',true),function( string$link ){
223
-			if( isset($this->config['target']) && ':'===$link{0} ){
222
+		return $this->setMultinameAttribute('link', $this->sectionLedBy('@', true), function( string$link ){
223
+			if( isset($this->config[ 'target' ]) && ':'===$link{0} ){
224 224
 				return 'javascript'.$link;
225
-			}elseif( '//'===($firstTwoLetters=substr($link,0,2)) ){
225
+			}elseif( '//'===($firstTwoLetters=substr($link, 0, 2)) ){
226 226
 				return 'http:'.$link;
227 227
 			}elseif( '\\\\'===$firstTwoLetters ){
228
-				return 'https://'.substr($link,2);
228
+				return 'https://'.substr($link, 2);
229 229
 			}else{
230 230
 				return $this->checkExpression($link);
231 231
 			}
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 */
242 242
 	protected function parseTarget():self
243 243
 	{
244
-		return $this->setMultinameAttribute('target',$this->sectionLedBy('>',true));
244
+		return $this->setMultinameAttribute('target', $this->sectionLedBy('>', true));
245 245
 	}
246 246
 
247 247
 	/**
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 */
254 254
 	protected function parseAlt():self
255 255
 	{
256
-		return $this->setMultinameAttribute('alt',$this->sectionLedBy('_',true));
256
+		return $this->setMultinameAttribute('alt', $this->sectionLedBy('_', true));
257 257
 	}
258 258
 
259 259
 	/**
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 	 */
270 270
 	private function setMultinameAttribute( string$name, string$value, callable$processer=null ):self
271 271
 	{
272
-		if( strlen($value) && !empty($this->config[$name]) ){
273
-			return $this->setAttribute($this->config[$name],call_user_func($processer??[$this,'checkExpression',],$value));
272
+		if( strlen($value) && !empty($this->config[ $name ]) ){
273
+			return $this->setAttribute($this->config[ $name ], call_user_func($processer??[ $this, 'checkExpression', ], $value));
274 274
 		}
275 275
 
276 276
 		return $this;
@@ -285,33 +285,33 @@  discard block
 block discarded – undo
285 285
 	 */
286 286
 	protected function parseCommonAttributes():string
287 287
 	{
288
-		$attributes= '';
288
+		$attributes='';
289 289
 
290
-		$id= $this->sectionLedBy('#')
291
-		 and $this->setAttribute('id',$id);
290
+		$id=$this->sectionLedBy('#')
291
+		 and $this->setAttribute('id', $id);
292 292
 
293
-		$classes= $this->line->pregGet('/ \.[^ ]+(?= |$)/')
294
-		 and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/',$classes,$matches)
295
-		  and $classes= implode(' ',array_filter(array_map(function( $className ){return $this->checkExpression($className);},$matches[1])))
296
-		   and $this->setAttribute('class',$classes);
293
+		$classes=$this->line->pregGet('/ \.[^ ]+(?= |$)/')
294
+		 and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/', $classes, $matches)
295
+		  and $classes=implode(' ', array_filter(array_map(function( $className ){return $this->checkExpression($className); },$matches[ 1 ])))
296
+		   and $this->setAttribute('class', $classes);
297 297
 
298
-		$title= $this->sectionLedBy('^',true)
299
-		 and $this->setAttribute('title',$title);
298
+		$title=$this->sectionLedBy('^', true)
299
+		 and $this->setAttribute('title', $title);
300 300
 
301
-		$style= $this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/',1)
302
-		 and $this->setAttribute('style',$style);
301
+		$style=$this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/', 1)
302
+		 and $this->setAttribute('style', $style);
303 303
 
304
-		$eventListeners= $this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/',function( $string, $name, $code ){
305
-			$this->setAttribute('on'.$name,str_replace('"','&quot;',$code));
304
+		$eventListeners=$this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/', function( $string, $name, $code ){
305
+			$this->setAttribute('on'.$name, str_replace('"', '&quot;', $code));
306 306
 		})
307
-		 and implode('',$eventListeners);
307
+		 and implode('', $eventListeners);
308 308
 
309
-		$other= $this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/')
309
+		$other=$this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/')
310 310
 		 and array_map(function( $keyValue ){
311
-			preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/',function($matches){
312
-				$this->setAttribute($matches[1],($matches[3]??$matches[1])?:$matches[1],$matches[2]??null);
311
+			preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/', function( $matches ){
312
+				$this->setAttribute($matches[ 1 ], ($matches[ 3 ]??$matches[ 1 ])?: $matches[ 1 ], $matches[ 2 ]??null);
313 313
 			},$keyValue);
314
-		},explode(';',$other));
314
+		},explode(';', $other));
315 315
 
316 316
 		return $attributes;
317 317
 	}
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	 */
328 328
 	protected function checkExpression( string$value ):string
329 329
 	{
330
-		return preg_match('/^\(.*\)$/',$value) ? '<?=str_replace(\'"\',\'&quot;\','.substr($value,1,-1).')?>' : str_replace('"','&quot;',$value);
330
+		return preg_match('/^\(.*\)$/', $value)? '<?=str_replace(\'"\',\'&quot;\','.substr($value, 1, -1).')?>' : str_replace('"', '&quot;', $value);
331 331
 	}
332 332
 
333 333
 	/**
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
 	protected function getAttributesString():string
341 341
 	{
342 342
 		ksort($this->attributes);
343
-		return implode('',array_map(static function( string$key, array$data ){
344
-			return (isset($data['condition'])&&strlen($data['condition'])?
345
-				"<?php if( {$data['condition']} ){?> $key=\"{$data['value']}\"<?php }?>"
343
+		return implode('', array_map(static function( string$key, array$data ){
344
+			return (isset($data[ 'condition' ]) && strlen($data[ 'condition' ])?
345
+				"<?php if( {$data[ 'condition' ]} ){?> $key=\"{$data[ 'value' ]}\"<?php }?>"
346 346
 				:
347
-				" $key=\"{$data['value']}\""
347
+				" $key=\"{$data[ 'value' ]}\""
348 348
 			);
349
-		},array_keys($this->attributes),$this->attributes));
349
+		},array_keys($this->attributes), $this->attributes));
350 350
 	}
351 351
 
352 352
 	/**
@@ -360,10 +360,10 @@  discard block
 block discarded – undo
360 360
 	 */
361 361
 	protected function setAttribute( string$key, string$value, string$condition=null ):self
362 362
 	{
363
-		if( isset($this->attributes[$key]) )
363
+		if( isset($this->attributes[ $key ]) )
364 364
 			{ $this->document->throw("Attribute $key of $this->name cannot redeclare."); }
365 365
 
366
-		$this->attributes[$key]=[
366
+		$this->attributes[ $key ]=[
367 367
 			'value'=> $value,
368 368
 			'condition'=> $condition,
369 369
 		];
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 	 */
388 388
 	public function offsetExists( $offset ):bool
389 389
 	{
390
-		return isset($this->attributes[$offset]);
390
+		return isset($this->attributes[ $offset ]);
391 391
 	}
392 392
 
393 393
 	/**
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 	 */
402 402
 	public function offsetGet( $offset )
403 403
 	{
404
-		return $this->attributes[$offset]??null;
404
+		return $this->attributes[ $offset ]??null;
405 405
 	}
406 406
 
407 407
 	/**
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 	 */
415 415
 	public function offsetSet( $offset, $value )
416 416
 	{
417
-		$this->setAttribute($offset,$value);
417
+		$this->setAttribute($offset, $value);
418 418
 	}
419 419
 
420 420
 	/**
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 	 */
427 427
 	public function offsetUnset( $offset )
428 428
 	{
429
-		if( isset($this->attributes[$offset]) )
430
-			{ unset($this->attributes[$offset]); }
429
+		if( isset($this->attributes[ $offset ]) )
430
+			{ unset($this->attributes[ $offset ]); }
431 431
 	}
432 432
 }
Please login to merge, or discard this patch.