Code Duplication    Length = 30-30 lines in 2 locations

src/Tokens/TokenContainer.php 1 location

@@ 92-121 (lines=30) @@
89
    /**
90
     * Required by the Removable interface.
91
     */
92
    public function remove(LoggerInterface $logger)
93
    {
94
        $hasRemovableElements = $this->configuration->get('element-blacklist') != '';
95
        $hasRemovableTypes = $this->configuration->get('type-blacklist') != '';
96
        foreach ($this->children as $child) {
97
            // Check types.
98
            if ($hasRemovableTypes &&
99
                !$this->configuration->isAllowedType($child->getType())) {
100
                $logger->debug('Removing ' . $child);
101
                $this->removeChild($child);
102
103
                continue;
104
            }
105
106
            // Check elements.
107
            if ($hasRemovableElements &&
108
                $child->getType() == Token::ELEMENT &&
109
                !$this->configuration->isAllowedElement($child->getName())) {
110
                $logger->debug('Removing ' . $child);
111
                $this->removeChild($child);
112
113
                continue;
114
            }
115
116
            // Check children.
117
            if ($child instanceof Removable) {
118
                $child->remove($logger);
119
            }
120
        }
121
    }
122
}
123

src/Tokens/Element.php 1 location

@@ 433-462 (lines=30) @@
430
    /**
431
     * Required by the Removable interface.
432
     */
433
    public function remove(LoggerInterface $logger)
434
    {
435
        $hasRemovableElements = $this->configuration->get('element-blacklist') != '';
436
        $hasRemovableTypes = $this->configuration->get('type-blacklist') != '';
437
        foreach ($this->children as $child) {
438
            // Check types.
439
            if ($hasRemovableTypes &&
440
                !$this->configuration->isAllowedType($child->getType())) {
441
                $logger->debug('Removing ' . $child);
442
                $this->removeChild($child);
443
444
                continue;
445
            }
446
447
            // Check elements.
448
            if ($hasRemovableElements &&
449
                $child->getType() == Token::ELEMENT &&
450
                !$this->configuration->isAllowedElement($child->getName())) {
451
                $logger->debug('Removing ' . $child);
452
                $this->removeChild($child);
453
454
                continue;
455
            }
456
457
            // Check children.
458
            if ($child instanceof Removable) {
459
                $child->remove($logger);
460
            }
461
        }
462
    }
463
464
    /**
465
     * Required by the Token interface.