QuoteProcessor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 54.55%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 77
ccs 18
cts 33
cp 0.5455
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getOpeningCharacter() 0 4 1
A getClosingCharacter() 0 4 1
A getMinLength() 0 4 1
A getDelimiterUse() 0 4 1
A process() 0 4 1
A createDoubleQuoteProcessor() 0 4 1
A createSingleQuoteProcessor() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark-ext-smartpunct package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * Original code based on the CommonMark JS reference parser (http://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace League\CommonMark\Ext\SmartPunct;
16
17
use League\CommonMark\Delimiter\DelimiterInterface;
18
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
19
use League\CommonMark\Extension\SmartPunct\Quote;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, League\CommonMark\Ext\SmartPunct\Quote.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
20
use League\CommonMark\Extension\SmartPunct\QuoteProcessor as CoreProcessor;
21
use League\CommonMark\Inline\Element\AbstractStringContainer;
22
23
/**
24
 * @deprecated The league/commonmark-ext-smartpunct extension is now deprecated. All functionality has been moved into league/commonmark 1.3+, so use that instead.
25
 */
26
final class QuoteProcessor implements DelimiterProcessorInterface
27
{
28
    /** @var CoreProcessor */
29
    private $coreProcessor;
30
31 4
    private function __construct(CoreProcessor $coreProcessor)
32
    {
33 4
        @trigger_error(sprintf('league/commonmark-ext-external-link is deprecated; use %s from league/commonmark 1.3+ instead', CoreProcessor::class), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
34 4
        $this->coreProcessor = $coreProcessor;
35 4
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 4
    public function getOpeningCharacter(): string
41
    {
42 4
        return $this->coreProcessor->getOpeningCharacter();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 4
    public function getClosingCharacter(): string
49
    {
50 4
        return $this->coreProcessor->getClosingCharacter();
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 4
    public function getMinLength(): int
57
    {
58 4
        return $this->coreProcessor->getMinLength();
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 4
    public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int
65
    {
66 4
        return $this->coreProcessor->getDelimiterUse($opener, $closer);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 4
    public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse)
73
    {
74 4
        return $this->coreProcessor->process($opener, $closer, $delimiterUse);
75
    }
76
77
    /**
78
     * Create a double-quote processor
79
     *
80
     * @param string $opener
81
     * @param string $closer
82
     *
83
     * @return QuoteProcessor
84
     */
85 2
    public static function createDoubleQuoteProcessor(string $opener = Quote::DOUBLE_QUOTE_OPENER, string $closer = Quote::DOUBLE_QUOTE_CLOSER): self
86
    {
87 2
        return new self(CoreProcessor::createDoubleQuoteProcessor($opener, $closer));
0 ignored issues
show
Deprecated Code introduced by
The class League\CommonMark\Ext\SmartPunct\QuoteProcessor has been deprecated with message: The league/commonmark-ext-smartpunct extension is now deprecated. All functionality has been moved into league/commonmark 1.3+, so use that instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
88
    }
89
90
    /**
91
     * Create a single-quote processor
92
     *
93
     * @param string $opener
94
     * @param string $closer
95
     *
96
     * @return QuoteProcessor
97
     */
98 2
    public static function createSingleQuoteProcessor(string $opener = Quote::SINGLE_QUOTE_OPENER, string $closer = Quote::SINGLE_QUOTE_CLOSER): self
99
    {
100 2
        return new self(CoreProcessor::createSingleQuoteProcessor($opener, $closer));
0 ignored issues
show
Deprecated Code introduced by
The class League\CommonMark\Ext\SmartPunct\QuoteProcessor has been deprecated with message: The league/commonmark-ext-smartpunct extension is now deprecated. All functionality has been moved into league/commonmark 1.3+, so use that instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
101
    }
102
}
103