Find all return tags that contain 'self' or '$this' and replace those
terms for the name of the current class' type.

@param \DOMDocument $xml Structure source to apply behaviour onto.

@return \DOMDocument
11002
public function process(\DOMDocument $xml)
    {
        $licenseMap = array(
            '#^\s*(GPL|GNU General Public License)((\s?v?|version)?2)\s*$#i'
                => 'http://opensource.org/licenses/GPL-2.0',
            '#^\s*(GPL|GNU General Public License)((\s?v?|version)?3?)\s*$#i'
                => 'http://opensource.org/licenses/GPL-3.0',
            '#^\s*(LGPL|GNU (Lesser|Library) (General Public License|GPL))'
                .'((\s?v?|version)?2(\.1)?)\s*$#i'
                => 'http://opensource.org/licenses/LGPL-2.1',
            '#^\s*(LGPL|GNU (Lesser|Library) (General Public License|GPL))'
                .'((\s?v?|version)?3?)\s*$#i'
                => 'http://opensource.org/licenses/LGPL-3.0',
            '#^\s*((new |revised |modified |three-clause |3-clause )BSD'
                .'( License)?)\s*$#i'
                => 'http://opensource.org/licenses/BSD-3-Clause',
            '#^\s*((simplified |two-clause |2-clause |Free)BSD)( License)?\s*$#i'
                => 'http://opensource.org/licenses/BSD-2-Clause',
            '#^\s*MIT( License)?\s*$#i' => 'http://opensource.org/licenses/MIT',
        );

        $xpath = new \DOMXPath($xml);
        $nodes = $xpath->query('//tag[@name="license"]/@description');

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {

            $license = $node->nodeValue;

            // FIXME: migrate to '#^' . PHPDOC::LINK_REGEX . '(\s+(?P<text>.+))
            // ?$#u' once that const exists
            if (preg_match(
                '#^(?i)\b(?P<url>(?:https?://|www\d{0,3}\.|[a-z0-9.\-]+\.'
                .'[a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+'
                .'(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|'
                .'[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))(\s+(?P<text>.+))?$#u',
                $license,
                $matches
            )) {
                if (!isset($matches['text']) || !$matches['text']) {
                    // set text to URL if not present
                    $matches['text'] = $matches['url'];
                }
                $node->parentNode->setAttribute('link', $matches['url']);
                $node->nodeValue = $matches['text'];

                // bail out early
                continue;
            }

            // check map if any license matches
            foreach ($licenseMap as $regex => $url) {
                if (preg_match($regex, $license, $matches)) {
                    $node->parentNode->setAttribute('link', $url);

                    // we're done here
                    break;
                }
            }
        }

        return $xml;
    }
1272139
public function detectNamespacesFromXml( $xml )
	{
		$namespaces	= self::getNamespacesFromXml( $xml );
		$this->namespaces	= array_merge( $this->namespaces, $namespaces );
		return count( $namespaces );
	}
1172932
public static function parse($xml)
    {
        $data = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);

        if (is_object($data) && get_class($data) === 'SimpleXMLElement') {
            $data = self::arrarval($data);
        }

        return $data;
    }
172368
public static function parseElementXml(SimpleXMLElement $xml){

        $attributes = array();
        foreach($xml->attributes() as $name => $value){
            $attributes[$name] = (string) $value;
        }

        $returnValue = array(
            'qtiClass' => $xml->getName()
        );

        if(count($attributes)){
            $returnValue['attributes'] = $attributes;
        }

        return $returnValue;
    }
1315618
public function process(\DOMDocument $xml)
    {
        $xpath = new \DOMXPath($xml);
        $nodes = $xpath->query('//tag[@name=\'covers\']');

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {
            $refers = $node->getAttribute('refers');
            $refers_array = explode('::', $refers);

            // determine the type so we know where to put the @coveredby tag on
            $type = 'class';
            if (isset($refers_array[1])) {
                // starts with $ = property, ends with () = method,
                // otherwise constant
                $type = $refers_array[1][0] == '$' ? 'property' : 'constant';
                $type = substr($refers_array[1], -2) == '()' ? 'method' : $type;
            }

            switch ($type) {
                case 'class':
                    // escape single quotes in the class name
                    $xpath_refers = 'concat(\''.str_replace(
                        array("'", '"'),
                        array('\', "\'", \'', '\', \'"\' , \''),
                        $refers
                    ) . "', '')";

                    $qry = '/project/file/class[full_name=' . $xpath_refers . ']';
                    break;
                default:
                    $class_name = $refers_array[0];

                    // escape single quotes in the class name
                    $xpath_class_name = 'concat(\''.str_replace(
                        array("'", '"'),
                        array('\', "\'", \'', '\', \'"\' , \''),
                        $class_name
                    ) . "', '')";

                    // escape single quotes in the method name
                    $xpath_method_name = 'concat(\''.str_replace(
                        array("'", '"'),
                        array('\', "\'", \'', '\', \'"\' , \''),
                        rtrim($refers_array[1], '()')
                    ) . "', '')";

                    $qry = '/project/file/class[full_name=' . $xpath_class_name
                        . ']/'.$type.'[name=' . $xpath_method_name .']';
                    break;
            }

            /** @noinspection PhpUsageOfSilenceOperatorInspection as there is no pre-validation possible */
            $referral_nodes = @$xpath->query($qry);

            // if the query is wrong; output a Critical error and continue to
            // the next @covers
            if ($referral_nodes === false) {
                // $this->log(
                //    'An XPath error occurs while processing @covers, the query used was: ' . $qry,
                //    LogLevel::CRITICAL
                // );
                continue;
            }

            // check if the result is unique; if not we error and continue
            // to the next @covers
            if ($referral_nodes->length > 1) {
                continue;
            }

            // if there is one matching element; link them together
            if ($referral_nodes->length > 0) {
                /** @var \DOMElement $referral  */
                $referral = $referral_nodes->item(0);
                $docblock = $referral->getElementsByTagName('docblock');
                if ($docblock->length < 1) {
                    $docblock = new \DOMElement('docblock');
                    $referral->appendChild($docblock);
                } else {
                    $docblock = $docblock->item(0);
                }

                $used_by = new \DOMElement('tag');
                $docblock->appendChild($used_by);
                $used_by->setAttribute('name', 'used_by');
                $used_by->setAttribute('line', '');

                // gather the name of the referring element and set that as refers
                // attribute
                if ($node->parentNode->parentNode->nodeName == 'class') {
                    // if the element where the @covers is in is a class; nothing
                    // more than the class name need to returned
                    $referral_name = $node->parentNode->parentNode
                        ->getElementsByTagName('full_name')->item(0)->nodeValue;
                } else {

                    $referral_class_name = null;
                    if ($node->parentNode->parentNode->nodeName == 'method') {
                        // gather the name of the class where the @covers is in
                        $referral_class_name = $node->parentNode->parentNode
                            ->parentNode->getElementsByTagName('full_name')->item(0)
                            ->nodeValue;
                    }

                    // gather the name of the subelement of the class where
                    // the @covers is in
                    $referral_name = $node->parentNode->parentNode
                        ->getElementsByTagName('name')->item(0)->nodeValue;

                    // if it is a method; suffix with ()
                    if ($node->parentNode->parentNode->nodeName == 'method'
                        || $node->parentNode->parentNode->nodeName == 'function'
                    ) {
                        $referral_name .= '()';
                    }

                    // only prefix class name if this is a class member
                    if ($referral_class_name) {
                        $referral_name = $referral_class_name . '::'
                            . $referral_name;
                    }
                }

                $used_by->setAttribute('description', $referral_name);
                $used_by->setAttribute('refers', $referral_name);
            }
        }

        return $xml;
    }
534330
public function loadXml($xml)
    {
        if (is_string($xml)) {
            $this->xml = $xml = simplexml_load_string($xml);
        } elseif ($xml instanceof \SimpleXMLElement) {
            $this->xml = $xml;
        }

        $this->addFields($xml);

        return $this;
    }
1280298
public function parseDom(\DOMDocument $dom)
    {
        $this->logger->info('Running parser: '.(new \ReflectionClass(__CLASS__))->getShortName());
        $items = [];

        $xpath = new \DOMXPath($dom);
        $xpath->registerNamespace('html', self::HTML_PROFILE_URI);

        // Run through all <link> elements with a `rel` attribute
        /** @var \DOMElement $linkType */
        foreach ($xpath->query('//*[local-name(.) = "link" or local-name(.) = "a"][@rel]') as $linkType) {
            $item    = [
                'type'       => $this->parseLinkType($linkType->getAttribute('rel')),
                'id'         => $linkType->getAttribute('id') ?: null,
                'properties' => $this->parseProperties($linkType),
            ];
            $items[] = (object)$item;
        }

        return new ParsingResult(self::FORMAT, $items);
    }
1307838
public static function cleanXML($xml)
    {
        if($xml != '') {
            $doc = new \DOMDocument();
            $doc->loadXML($xml);
            $doc->formatOutput = true;
            return $doc->saveXML();
        } else {
            return '';
        }
    }
359742
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();

        $locationId = $xml->getElementsByTagName('pickupLocation');
        $static->locationId = StringLiteral::fromXml($locationId);

        $text = $xml->getElementsByTagName('pickupLocationText');
        $static->text = StringLiteral::fromXml($text);

        return $static;
    }
667631
public function parseXML(\SimpleXMLElement $xml)
    {
        $name = $xml->getName();
        if ($name !== 'svg') {
            return null;
        }

        $width = isset($xml['width']) ? $xml['width'] : null;
        $height = isset($xml['height']) ? $xml['height'] : null;
        $namespaces = $xml->getNamespaces(true);

        $img = new SVG($width, $height, $namespaces);

        $nsKeys = array_keys($namespaces);

        $doc = $img->getDocument();
        $this->applyAttributes($doc, $xml, $nsKeys);
        $this->applyStyles($doc, $xml);
        $this->addChildren($doc, $xml, $nsKeys);

        return $img;
    }
1064173
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();
        $static->libraryItemMetadata = LibraryItemMetadata::fromXml($xml);

        $expenseId = $xml->getElementsByTagName('id');
        $static->expenseId = StringLiteral::fromXml($expenseId);

        $date = $xml->getElementsByTagName('date');
        $static->date = DateTime::fromXml($date);

        $amount = $xml->getElementsByTagName('amount');
        $static->amount = FloatLiteral::fromXml($amount);

        $stringLiterals = array(
            'title' => $xml->getElementsByTagName('title'),
            'description' => $xml->getElementsByTagName('description'),
            'type' => $xml->getElementsByTagName('type'),
        );
        foreach ($stringLiterals as $propertyName => $xmlTag) {
            $static->$propertyName = StringLiteral::fromXml($xmlTag);
        }

        return $static;
    }
605218
public static function format($xml) {
        $domtree = new DOMDocument('1.0', 'UTF-8');
        $domtree->loadXML($xml);
        $domtree->preserveWhiteSpace = false;
        $domtree->formatOutput = true;
        $domtree->setIndent = (1);
        return $domtree->saveXML();
    }
554559
protected function process($xml)
    {
        if ($this->basedir) {
            $cwd = getcwd();
            chdir($this->basedir);
        }

        // Create and setup document.
        $xmlDom = new DomDocument();
        $xmlDom->resolveExternals = $this->resolveExternals;

        $xmlDom->loadXML($xml);

        $xmlDom->xinclude();

        if ($this->basedir) {
            chdir($cwd);
        }

        return $xmlDom->saveXML();
    }
370027
public function generateDigest(DOMDocument $xml)
    {
        $xml = $xml->cloneNode(true);

        // strip Signature
        foreach ($this->getXPath($xml)->query('ds:Signature') as $node) {
            $node->parentNode->removeChild($node);
        }

        $message = $this->c14n($xml);

        return base64_encode(hash('sha256', $message, true));
    }
744343
private function parseLinkInput (SimpleXMLElement $xml)
    {
        return (new ReflectionClass(Input\Link::class))->newInstanceArgs(
            array_merge(
                $this->getCommonMessageProperties($xml),
                [
                    (string)$xml->Url,
                    (string)$xml->Title,
                    (string)$xml->Description,
                ]
            )
        );
    }
1161586
public function getXML(\DOMDocument $document)
    {
        $xml = $document->createElement(sprintf('%s:TransactionDetails', $this->namespace));

        $comments = $document->createElement('ns1:Comments');
        $comments->textContent = $this->comments;

        $xml->appendChild($comments);

        if (!empty($this->invoiceNumber)) {
            $invoiceNumber = $document->createElement('ns1:InvoiceNumber');
            $invoiceNumber->textContent = $this->invoiceNumber;

            $xml->appendChild($invoiceNumber);
        }

        return $xml;
    }
820
public function xml2array(\SimpleXMLElement $xml)
    {
        $arr = array();
        foreach ($xml as $element) {
            $tag = $element->getName();
            $e = get_object_vars($element);
            if (!empty($e)) {
                $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e;
            } else {
                $arr[$tag] = trim($element);
            }
        }

        return $arr;
    }