Code Duplication    Length = 30-30 lines in 2 locations

src/Tokens/Element.php 1 location

@@ 424-453 (lines=30) @@
421
    /**
422
     * Required by the Removable interface.
423
     */
424
    public function remove(LoggerInterface $logger)
425
    {
426
        $hasRemovableElements = $this->configuration->get('element-blacklist') != '';
427
        $hasRemovableTypes = $this->configuration->get('type-blacklist') != '';
428
        foreach ($this->children as $child) {
429
            // Check types.
430
            if ($hasRemovableTypes &&
431
                !$this->configuration->isAllowedType($child->getType())) {
432
                $logger->debug('Removing ' . $child);
433
                $this->removeChild($child);
434
435
                continue;
436
            }
437
438
            // Check elements.
439
            if ($hasRemovableElements &&
440
                $child instanceof self &&
441
                !$this->configuration->isAllowedElement($child->getName())) {
442
                $logger->debug('Removing ' . $child);
443
                $this->removeChild($child);
444
445
                continue;
446
            }
447
448
            // Check children.
449
            if ($child instanceof Removable) {
450
                $child->remove($logger);
451
            }
452
        }
453
    }
454
455
    /**
456
     * Required by the Token interface.

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 . ' on type blacklist.');
101
                $this->removeChild($child);
102
103
                continue;
104
            }
105
106
            // Check elements.
107
            if ($hasRemovableElements &&
108
                $child instanceof Element &&
109
                !$this->configuration->isAllowedElement($child->getName())) {
110
                $logger->debug('Removing ' . $child . ' on element blacklist.');
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