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:----jhdRsnZ+COfB11uTpIllrgOBKKf40H67aRKBcHMf4Iq0dPKsyJpLGakIdd/oYGh7XNLF3Pj3q3WhXlrF+/OwmJnIgTRm/q4wmme6Mt73GMSiYDNMAHlkEs3jwEPm26Kc41++Yrit+cTSeGT/kk3IRjINApjVpYO9U4wA9V3L/RlL/0LbL5TMBxwvn4Hbhbizgnp2TkTde4x/4m9OmETnkrQOPsyWEfcHsGlyNjoUjS+cWr70v8V7lB3v7agx0EYXs7ZA+XNNSv1y+w7vWaykw2YnLfBIZOlK+7kiAJ6kRu92tSmNzxywXZG8ZKrx97QZOAaFZQwSOjzmn/3OuI/1uelQHSgNC318kZEEbOHsGIdTpAB612j5lwgb9y71H+viFtrFMAEVIJfPOj8DCb2lQ5+/hoTuIuXyjGlpGwdgeq2JDDRCB1VQ8REgFMOA7I46AZSUyO1EpLJxQwn4LECEV1wDCaAXGF99wc+Yc7KQuibOKS2h3/jPjZTfbb7J6dXnd1dlUrwowE6aCxZvP4a2YGc5/pRtSinARB2L1UT7uw4GpUBE+jSDRNkhIFwMJ9wp+pI5AYH3RGmXaE/S0blQuINdidHDfzROTWF8Qj+c5Dd/qefSG0b/gHkpJ+W2665fExDyIR9NwyjGjjs3VviRDbhr/+12HMFTFOtwaDnJ+s4=----ATTACHMENT:----OTQ0OTUxODM5MzIxMTk2MCAzOTk0NzY3MzUwNjU3OTA2IDQ1MjgzMDE0ODEzNzA0Ng==