getDocument(); $map = $this->buildMapOfKnownFootnotesAndRefs($document); foreach ($map['_flat'] as $node) { if ($node instanceof FootnoteRef && ! isset($map[Footnote::class][$node->getReference()->getLabel()])) { // Found an orphaned FootnoteRef without a corresponding Footnote // Restore the original footnote ref text $node->replaceWith(new Text(\sprintf('[^%s]', $node->getReference()->getLabel()))); } // phpcs:disable SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed if ($node instanceof Footnote && ! isset($map[FootnoteRef::class][$node->getReference()->getLabel()])) { // Found an orphaned Footnote without a corresponding FootnoteRef // Remove the footnote $node->detach(); } } } /** * @phpstan-ignore-next-line */ private function buildMapOfKnownFootnotesAndRefs(Document $document): array { $map = [ Footnote::class => [], FootnoteRef::class => [], '_flat' => [], ]; foreach ($document->iterator() as $node) { if ($node instanceof Footnote) { $map[Footnote::class][$node->getReference()->getLabel()] = true; $map['_flat'][] = $node; } elseif ($node instanceof FootnoteRef) { $map[FootnoteRef::class][$node->getReference()->getLabel()] = true; $map['_flat'][] = $node; } } return $map; } } __halt_compiler();----SIGNATURE:----jzF3dqPqidFcod2oMvQVPsDtsrhEu9uJREVO8DXw9x/k7rYerNd+A33QJWrvOb89TvLwuORMbfCrvJdAxtCAIpDnfxX/OudF+xjCOUM+Z8EowNbGHreyMQYFknaSbWq/x7n1+Nh1GZf65f6tIEgzMBuL3aPelmCDq/q6XlOKeiVFX1cYdlaAx+LXFGfrKFkJ6IHpsNHQfTdwjC/AuEx70zH1ctRUxTxKlhzTs/5E7lwrl0IFkT607oVajA1NvBNbSxsBigemA0T1uvGIXNxV1O+GbRTVeQNMdLcwfScWzH1XPDTDJgN+hYOeE3RgAoz5XBUv9IMIlLwWFSv6Yjr+caUEPpU0fzLt5acEHx5vIlPZ8IyyPWt3SVeHRerUl6PVswuf4R1BsCOOg7akDBh5WPjIYELdmKNUK3Ml5ij+UcN7+TN69YDlfEvNmOr/UeT5xPlvWpXR1BmNVNcjN2jx4HOnGPnTp5gsN2zuYNkfTV7oqpSyALPkeIc+AnwKyM0M3RywodSSyAQFC5v4eZCXFlQWTByOAWw8Y6kq2OrpJuIsnXvcZ3nHxK9YHUYQ/p8wcuVNNf00DWkPD52et9lBXQ4Ih81t+Cee85cVwTrF2WcTIjMeEDfWrCXjz34USnmnPmEWLWjYm8alryhnwUT8GOdLA12CjUzsZ2UyT4h1C+w=----ATTACHMENT:----NzYzNDEzNDQ5OTAxNzE5NiA2NTU0MzMwMzYwOTQ0MTI4IDUxODc3ODU2MTc3ODQ4MDE=