Completed
Push — master ( da54d7...33d164 )
by Colin
25s queued 10s
created

DelimiterProcessorCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 18
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDelimiterProcessor() 0 4 1
A add() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * Additional emphasis processing code based on commonmark-java (https://github.com/atlassian/commonmark-java)
12
 *  - (c) Atlassian Pty Ltd
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace League\CommonMark\Delimiter\Processor;
19
20
final class DelimiterProcessorCollection implements DelimiterProcessorCollectionInterface
21
{
22
    private $processorsByChar = [];
23
24 2037
    public function add(DelimiterProcessorInterface $processor)
25
    {
26 2037
        if (isset($this->processorsByChar[$processor->getCharacter()])) {
27 3
            throw new \InvalidArgumentException(sprintf('Delim processor for character "%s" already exists', $processor->getCharacter()));
28
        }
29
30 2037
        $this->processorsByChar[$processor->getCharacter()] = $processor;
31 2037
    }
32
33 846
    public function getDelimiterProcessor(string $char): ?DelimiterProcessorInterface
34
    {
35 846
        return $this->processorsByChar[$char] ?? null;
36
    }
37
}
38