type = $type; $this->children = $children; $this->position = $position; } /** * @return string * @codeCoverageIgnore */ public function toDebugString() { return implode( "\n", $this->toDebugStringInner() ); } /** * @return array * @codeCoverageIgnore */ private function toDebugStringInner() { if ( $this->type === self::ATOM ) { return [ "ATOM({$this->children->type} {$this->children->value})" ]; } $align = function ( $line ) { return ' ' . $line; }; $lines = [ "{$this->type}" ]; // @phan-suppress-next-line PhanTypeSuspiciousNonTraversableForeach children is array here foreach ( $this->children as $subnode ) { if ( $subnode instanceof AFPTreeNode ) { $sublines = array_map( $align, $subnode->toDebugStringInner() ); } elseif ( is_string( $subnode ) ) { $sublines = [ " {$subnode}" ]; } else { throw new AFPException( "Each node parameter has to be either a node or a string" ); } $lines = array_merge( $lines, $sublines ); } return $lines; } }