@@ -13,15 +13,13 @@ abstract class AbstractElement implements GenerateableInterface
1313 /**
1414 * @var AbstractElement[]|mixed[]
1515 */
16- protected array $ children ;
16+ protected array $ children = [] ;
1717
18- protected int $ indentation ;
18+ protected int $ indentation = 0 ;
1919
2020 public function __construct (string $ name )
2121 {
2222 $ this ->setName ($ name );
23- $ this ->children = [];
24- $ this ->indentation = 0 ;
2523 }
2624
2725 public function __toString (): string
@@ -47,7 +45,7 @@ public function getName(): string
4745 public static function nameIsValid (string $ name , bool $ allowBackslash = false ): bool
4846 {
4947 $ pattern = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/ ' ;
50- if (true === $ allowBackslash ) {
48+ if ($ allowBackslash ) {
5149 $ pattern = '/[a-zA-Z_\x7f-\xff \\\][a-zA-Z0-9_\x7f-\xff \\\]*/ ' ;
5250 }
5351
@@ -61,7 +59,7 @@ public static function stringIsValid($string, bool $checkName = true, bool $allo
6159
6260 public static function objectIsValid ($ object , ?string $ checkClass = null ): bool
6361 {
64- return is_object ($ object ) && (null === $ checkClass || get_class ($ object ) === $ checkClass );
62+ return is_object ($ object ) && (is_null ( $ checkClass) || get_class ($ object ) === $ checkClass );
6563 }
6664
6765 public function toString (?int $ indentation = null ): string
@@ -78,7 +76,7 @@ public function toString(?int $indentation = null): string
7876 }
7977 $ lines [] = $ this ->getToStringAfterChildren ($ indentation );
8078
81- return implode (self ::BREAK_LINE_CHAR , self ::cleanArrayToString ($ lines ));
79+ return implode (self ::BREAK_LINE_CHAR , static ::cleanArrayToString ($ lines ));
8280 }
8381
8482 public function getPhpName (): string
@@ -152,7 +150,7 @@ public function useBracketsForChildren(): bool
152150 public function getBracketBeforeChildren (?int $ indentation = null ): string
153151 {
154152 $ line = $ this ->getIndentedString (self ::OPEN_BRACKET , $ indentation );
155- $ this ->setIndentation ((null === $ indentation ? $ this ->getIndentation () : $ indentation ) + 1 );
153+ $ this ->setIndentation ((is_null ( $ indentation) ? $ this ->getIndentation () : $ indentation ) + 1 );
156154
157155 return $ line ;
158156 }
@@ -162,7 +160,7 @@ public function getBracketBeforeChildren(?int $indentation = null): string
162160 */
163161 public function getBracketAfterChildren (?int $ indentation = null ): string
164162 {
165- $ this ->setIndentation ((null === $ indentation ? $ this ->getIndentation () : $ indentation ) - 1 );
163+ $ this ->setIndentation ((is_null ( $ indentation) ? $ this ->getIndentation () : $ indentation ) - 1 );
166164
167165 return $ this ->getIndentedString (self ::CLOSE_BRACKET , $ indentation );
168166 }
@@ -181,7 +179,7 @@ public function getIndentation(): int
181179
182180 public function getIndentationString (?int $ indentation = null ): string
183181 {
184- return str_repeat (self ::INDENTATION_CHAR , null === $ indentation ? $ this ->getIndentation () : $ indentation );
182+ return str_repeat (self ::INDENTATION_CHAR , is_null ( $ indentation) ? $ this ->getIndentation () : $ indentation );
185183 }
186184
187185 public function getIndentedString (string $ string , ?int $ indentation = null ): string
@@ -205,7 +203,7 @@ protected function getChildContent($child, int $indentation = null): string
205203 if (is_string ($ child )) {
206204 $ content = $ this ->getIndentedString ($ child , $ indentation );
207205 } elseif ($ child instanceof AbstractElement) {
208- $ content = $ child ->toString (null === $ indentation ? $ this ->getIndentation () : $ indentation );
206+ $ content = $ child ->toString (is_null ( $ indentation) ? $ this ->getIndentation () : $ indentation );
209207 }
210208
211209 return $ content ;
@@ -258,9 +256,11 @@ private static function cleanArrayToString(array $array): array
258256 {
259257 $ newArray = [];
260258 foreach ($ array as $ line ) {
261- if (null !== $ line ) {
262- $ newArray [] = $ line ;
259+ if (is_null ( $ line) ) {
260+ continue ;
263261 }
262+
263+ $ newArray [] = $ line ;
264264 }
265265
266266 return $ newArray ;
0 commit comments