Completed
Push — master ( 11e974...988761 )
by Fenz
02:07
created
libs/Parser/Node/TagNode.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @var array
52 52
 	 */
53
-	private $attributes=[];
53
+	private $attributes=[ ];
54 54
 
55 55
 	/**
56 56
 	 * Real constructor.
@@ -62,14 +62,14 @@  discard block
 block discarded – undo
62 62
 	protected function construct():parent
63 63
 	{
64 64
 
65
-		$name= $this->line->pregGet('/(?<=^-)[\w-:]+/');
65
+		$name=$this->line->pregGet('/(?<=^-)[\w-:]+/');
66 66
 		$this->name=$name;
67 67
 
68
-		$this->loadConfig($name,$this->document);
68
+		$this->loadConfig($name, $this->document);
69 69
 
70
-		$this->tagName=$this->config['name']??$name;
71
-		$this->isEmpty= $this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags',$this->tagName);
72
-		isset($this->config['default_attributes']) and array_walk($this->config['default_attributes'],function( $value,$key ){ $this->setAttribute($key,$value); });
70
+		$this->tagName=$this->config[ 'name' ]??$name;
71
+		$this->isEmpty=$this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags', $this->tagName);
72
+		isset($this->config[ 'default_attributes' ]) and array_walk($this->config[ 'default_attributes' ], function( $value, $key ){ $this->setAttribute($key, $value); });
73 73
 
74 74
 		return $this;
75 75
 	}
@@ -83,16 +83,16 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	public function open():string
85 85
 	{
86
-		if( isset($this->config['opener']) )
87
-			{ return $this->config['opener']; }
86
+		if( isset($this->config[ 'opener' ]) )
87
+			{ return $this->config[ 'opener' ]; }
88 88
 
89 89
 		$this->parsePrivateAttributes();
90 90
 		$this->parseCommonAttributes();
91 91
 
92
-		if( isset($this->config['in_scope']) && isset($this->config['scope_function']) && is_callable($this->config['scope_function']) )
93
-			{ $this->config['scope_function']->call($this,$this->document->scope); }
92
+		if( isset($this->config[ 'in_scope' ]) && isset($this->config[ 'scope_function' ]) && is_callable($this->config[ 'scope_function' ]) )
93
+			{ $this->config[ 'scope_function' ]->call($this, $this->document->scope); }
94 94
 
95
-		$finisher= $this->isEmpty ? ' />' : '>';
95
+		$finisher=$this->isEmpty? ' />' : '>';
96 96
 
97 97
 		return "<{$this->tagName}{$this->attributesString}{$finisher}";
98 98
 	}
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 */
109 109
 	public function close( Line$closerLine ):string
110 110
 	{
111
-		return $this->isEmpty ? '' : $this->config['closer']??"</{$this->tagName}>";
111
+		return $this->isEmpty? '' : $this->config[ 'closer' ]??"</{$this->tagName}>";
112 112
 	}
113 113
 
114 114
 	/**
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	public function getEmbed():string
122 122
 	{
123
-		return $this->config['embedding']??'';
123
+		return $this->config[ 'embedding' ]??'';
124 124
 	}
125 125
 
126 126
 	/**
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	public function getScope()
134 134
 	{
135
-		return $this->config['scope']??null;
135
+		return $this->config[ 'scope' ]??null;
136 136
 	}
137 137
 
138 138
 	/**
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	protected function parsePrivateAttributes():self
146 146
 	{
147 147
 		foreach( self::PRIVATE_ATTRIBUTES as $attribute ){
148
-			isset($this->config[$attribute]) and $this->{'parse'.Helper\camel_case($attribute)}();
148
+			isset($this->config[ $attribute ]) and $this->{'parse'.Helper\camel_case($attribute)}();
149 149
 		}
150 150
 
151 151
 		return $this;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @todo Make this const private when php 7.1
162 162
 	 */
163
-	const PRIVATE_ATTRIBUTES= [
163
+	const PRIVATE_ATTRIBUTES=[
164 164
 		'params',
165 165
 		'name_value',
166 166
 		'link',
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 	 */
178 178
 	protected function parseParams():self
179 179
 	{
180
-		$params= preg_split('/(?<!\\\\)\\|/',$this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/',1));
180
+		$params=preg_split('/(?<!\\\\)\\|/', $this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/', 1));
181 181
 
182
-		if( ($m= count($params)) != ($n= count($this->config['params'])) ){$this->document->throw("Tag $this->name has $n parameters $m given.");}
182
+		if( ($m=count($params))!=($n=count($this->config[ 'params' ])) ){$this->document->throw("Tag $this->name has $n parameters $m given."); }
183 183
 
184
-		array_map(function( $key, $value ){return $this->setAttribute($key,str_replace('\\|','|',$value));},$this->config['params'],$params);
184
+		array_map(function( $key, $value ){return $this->setAttribute($key, str_replace('\\|', '|', $value)); },$this->config[ 'params' ], $params);
185 185
 
186 186
 		return $this;
187 187
 	}
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 	 */
196 196
 	protected function parseNameValue():self
197 197
 	{
198
-		$params= $this->line->pregGet('/ <(.*?)>(?= |$)/',1)
199
-		 and $params= preg_split('/(?<!\\\\)\\|/',$params)
200
-		  and array_map(function( $key, $value ){return isset($key)&&isset($value) ? $this->setAttribute($key,$this->checkExpression(str_replace('\\|','|',$value))) : '';},$this->config['name_value'],$params);
198
+		$params=$this->line->pregGet('/ <(.*?)>(?= |$)/', 1)
199
+		 and $params=preg_split('/(?<!\\\\)\\|/', $params)
200
+		  and array_map(function( $key, $value ){return isset($key) && isset($value)? $this->setAttribute($key, $this->checkExpression(str_replace('\\|', '|', $value))) : ''; },$this->config[ 'name_value' ], $params);
201 201
 
202 202
 		return $this;
203 203
 	}
@@ -239,13 +239,13 @@  discard block
 block discarded – undo
239 239
 	 */
240 240
 	protected function parseLink():self
241 241
 	{
242
-		return $this->setMultinameAttribute('link',$this->sectionLedBy('@',true),function( string$link ){
243
-			if( isset($this->config['target']) && ':'===$link{0} ){
242
+		return $this->setMultinameAttribute('link', $this->sectionLedBy('@', true), function( string$link ){
243
+			if( isset($this->config[ 'target' ]) && ':'===$link{0} ){
244 244
 				return 'javascript'.$link;
245
-			}elseif( '//'===($firstTwoLetters=substr($link,0,2)) ){
245
+			}elseif( '//'===($firstTwoLetters=substr($link, 0, 2)) ){
246 246
 				return 'http:'.$link;
247 247
 			}elseif( '\\\\'===$firstTwoLetters ){
248
-				return 'https://'.substr($link,2);
248
+				return 'https://'.substr($link, 2);
249 249
 			}else{
250 250
 				return $this->checkExpression($link);
251 251
 			}
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	 */
262 262
 	protected function parseTarget():self
263 263
 	{
264
-		return $this->setMultinameAttribute('target',$this->sectionLedBy('>',true));
264
+		return $this->setMultinameAttribute('target', $this->sectionLedBy('>', true));
265 265
 	}
266 266
 
267 267
 	/**
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	 */
274 274
 	protected function parseAlt():self
275 275
 	{
276
-		return $this->setMultinameAttribute('alt',$this->sectionLedBy('_',true));
276
+		return $this->setMultinameAttribute('alt', $this->sectionLedBy('_', true));
277 277
 	}
278 278
 
279 279
 	/**
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 	 */
290 290
 	private function setMultinameAttribute( string$name, string$value, callable$processer=null ):self
291 291
 	{
292
-		if( strlen($value) && !empty($this->config[$name]) ){
293
-			return $this->setAttribute($this->config[$name],call_user_func($processer??[$this,'checkExpression',],$value));
292
+		if( strlen($value) && !empty($this->config[ $name ]) ){
293
+			return $this->setAttribute($this->config[ $name ], call_user_func($processer??[ $this, 'checkExpression', ], $value));
294 294
 		}
295 295
 
296 296
 		return $this;
@@ -305,33 +305,33 @@  discard block
 block discarded – undo
305 305
 	 */
306 306
 	protected function parseCommonAttributes():string
307 307
 	{
308
-		$attributes= '';
308
+		$attributes='';
309 309
 
310
-		$id= $this->sectionLedBy('#')
311
-		 and $this->setAttribute('id',$id);
310
+		$id=$this->sectionLedBy('#')
311
+		 and $this->setAttribute('id', $id);
312 312
 
313
-		$classes= $this->line->pregGet('/ \.[^ ]+(?= |$)/')
314
-		 and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/',$classes,$matches)
315
-		  and $classes= implode(' ',array_filter(array_map(function( $className ){return $this->checkExpression($className);},$matches[1])))
316
-		   and $this->setAttribute('class',$classes);
313
+		$classes=$this->line->pregGet('/ \.[^ ]+(?= |$)/')
314
+		 and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/', $classes, $matches)
315
+		  and $classes=implode(' ', array_filter(array_map(function( $className ){return $this->checkExpression($className); },$matches[ 1 ])))
316
+		   and $this->setAttribute('class', $classes);
317 317
 
318
-		$title= $this->sectionLedBy('^',true)
319
-		 and $this->setAttribute('title',$this->checkExpression($title));
318
+		$title=$this->sectionLedBy('^', true)
319
+		 and $this->setAttribute('title', $this->checkExpression($title));
320 320
 
321
-		$style= $this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/',1)
322
-		 and $this->setAttribute('style',$style);
321
+		$style=$this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/', 1)
322
+		 and $this->setAttribute('style', $style);
323 323
 
324
-		$eventListeners= $this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/',function( $string, $name, $code ){
325
-			$this->setAttribute('on'.$name,str_replace('"','&quot;',$code));
324
+		$eventListeners=$this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/', function( $string, $name, $code ){
325
+			$this->setAttribute('on'.$name, str_replace('"', '&quot;', $code));
326 326
 		})
327
-		 and implode('',$eventListeners);
327
+		 and implode('', $eventListeners);
328 328
 
329
-		$other= $this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/')
329
+		$other=$this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/')
330 330
 		 and array_map(function( $keyValue ){
331
-			preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/',function($matches){
332
-				$this->setAttribute($matches[1],(isset($matches[3])? $this->checkExpression($matches[3]) : $matches[1]),$matches[2]??null);
331
+			preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/', function( $matches ){
332
+				$this->setAttribute($matches[ 1 ], (isset($matches[ 3 ])? $this->checkExpression($matches[ 3 ]) : $matches[ 1 ]), $matches[ 2 ]??null);
333 333
 			},$keyValue);
334
-		},explode(';',$other));
334
+		},explode(';', $other));
335 335
 
336 336
 		return $attributes;
337 337
 	}
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 	 */
348 348
 	protected function checkExpression( string$value ):string
349 349
 	{
350
-		return preg_match('/^\(.*\)$/',$value) ? '<?=str_replace(\'"\',\'&quot;\','.substr($value,1,-1).')?>' : str_replace('"','&quot;',$value);
350
+		return preg_match('/^\(.*\)$/', $value)? '<?=str_replace(\'"\',\'&quot;\','.substr($value, 1, -1).')?>' : str_replace('"', '&quot;', $value);
351 351
 	}
352 352
 
353 353
 	/**
@@ -360,13 +360,13 @@  discard block
 block discarded – undo
360 360
 	protected function getAttributesString():string
361 361
 	{
362 362
 		ksort($this->attributes);
363
-		return implode('',array_map(static function( string$key, array$data ){
364
-			return (isset($data['condition'])&&strlen($data['condition'])?
365
-				"<?php if( {$data['condition']} ){?> $key=\"{$data['value']}\"<?php }?>"
363
+		return implode('', array_map(static function( string$key, array$data ){
364
+			return (isset($data[ 'condition' ]) && strlen($data[ 'condition' ])?
365
+				"<?php if( {$data[ 'condition' ]} ){?> $key=\"{$data[ 'value' ]}\"<?php }?>"
366 366
 				:
367
-				" $key=\"{$data['value']}\""
367
+				" $key=\"{$data[ 'value' ]}\""
368 368
 			);
369
-		},array_keys($this->attributes),$this->attributes));
369
+		},array_keys($this->attributes), $this->attributes));
370 370
 	}
371 371
 
372 372
 	/**
@@ -380,10 +380,10 @@  discard block
 block discarded – undo
380 380
 	 */
381 381
 	protected function setAttribute( string$key, string$value, string$condition=null ):self
382 382
 	{
383
-		if( isset($this->attributes[$key]) )
383
+		if( isset($this->attributes[ $key ]) )
384 384
 			{ $this->document->throw("Attribute $key of $this->name cannot redeclare."); }
385 385
 
386
-		$this->attributes[$key]=[
386
+		$this->attributes[ $key ]=[
387 387
 			'value'=> $value,
388 388
 			'condition'=> $condition,
389 389
 		];
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	 */
408 408
 	public function offsetExists( $offset ):bool
409 409
 	{
410
-		return isset($this->attributes[$offset]);
410
+		return isset($this->attributes[ $offset ]);
411 411
 	}
412 412
 
413 413
 	/**
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 	 */
422 422
 	public function offsetGet( $offset )
423 423
 	{
424
-		return $this->attributes[$offset]??null;
424
+		return $this->attributes[ $offset ]??null;
425 425
 	}
426 426
 
427 427
 	/**
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 	 */
435 435
 	public function offsetSet( $offset, $value )
436 436
 	{
437
-		$this->setAttribute($offset,$value);
437
+		$this->setAttribute($offset, $value);
438 438
 	}
439 439
 
440 440
 	/**
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	 */
447 447
 	public function offsetUnset( $offset )
448 448
 	{
449
-		if( isset($this->attributes[$offset]) )
450
-			{ unset($this->attributes[$offset]); }
449
+		if( isset($this->attributes[ $offset ]) )
450
+			{ unset($this->attributes[ $offset ]); }
451 451
 	}
452 452
 }
Please login to merge, or discard this patch.