Passed
Push — feature/6.x ( 53903f...32797a )
by Schlaefer
05:38 queued 02:15
created

BbcodeProcessorCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A process() 0 9 3
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Saito - The Threaded Web Forum
6
 *
7
 * @copyright Copyright (c) the Saito Project Developers
8
 * @link https://github.com/Schlaefer/Saito
9
 * @license http://opensource.org/licenses/MIT
10
 */
11
12
namespace BbcodeParser\Lib\Processors;
13
14
class BbcodeProcessorCollection
15
{
16
    protected $_Processors = [];
17
18
    /**
19
     * Add processor to collection.
20
     *
21
     * @param \BbcodeParser\Lib\Processors\BbcodeProcessor $Preprocessor processor
22
     * @param array $options options
23
     * @return void
24
     */
25
    public function add($Preprocessor, array $options = [])
26
    {
27
        $options += ['priority' => 1000];
28
        $this->_Processors[$options['priority']][] = $Preprocessor;
29
    }
30
31
    /**
32
     * Porcess processors in collection
33
     *
34
     * @param string $string string to process
35
     * @param array $options options
36
     *
37
     * @return string
38
     */
39
    public function process($string, array $options = [])
40
    {
41
        foreach ($this->_Processors as $priority) {
42
            foreach ($priority as $Preprocessor) {
43
                $string = $Preprocessor->process($string, $options);
44
            }
45
        }
46
47
        return $string;
48
    }
49
}
50