|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/* |
|
4
|
|
|
* citeproc-php |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/seboettg/citeproc-php for the source repository |
|
7
|
|
|
* @copyright Copyright (c) 2020 Sebastian Böttger. |
|
8
|
|
|
* @license https://opensource.org/licenses/MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Seboettg\CiteProc\Styles; |
|
12
|
|
|
|
|
13
|
|
|
use Seboettg\CiteProc\Locale\Locale; |
|
14
|
|
|
use Seboettg\CiteProc\Util\StringHelper; |
|
15
|
|
|
|
|
16
|
|
|
final class QuotesRenderer implements StylesRendererInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var bool */ |
|
19
|
|
|
private $quotes; |
|
20
|
|
|
|
|
21
|
|
|
/** @var Locale|null */ |
|
22
|
|
|
private $locale; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string|null */ |
|
25
|
|
|
private $suffix; |
|
26
|
|
|
|
|
27
|
139 |
|
public function __construct(bool $quotes, ?Locale $locale, ?string $suffix) |
|
28
|
|
|
{ |
|
29
|
139 |
|
$this->quotes = $quotes; |
|
30
|
139 |
|
$this->locale = $locale; |
|
31
|
139 |
|
$this->suffix = $suffix; |
|
32
|
139 |
|
} |
|
33
|
|
|
|
|
34
|
101 |
|
public function render(string $text): string |
|
35
|
|
|
{ |
|
36
|
101 |
|
if ($this->quotes) { |
|
37
|
12 |
|
$openQuote = $this->locale->filter("terms", "open-quote")->single; |
|
|
|
|
|
|
38
|
12 |
|
$closeQuote = $this->locale->filter("terms", "close-quote")->single; |
|
39
|
12 |
|
$punctuationInQuotes =$this->locale->filter("options", "punctuation-in-quote"); |
|
40
|
12 |
|
$text = $this->replaceOuterQuotes($text, $openQuote, $closeQuote); |
|
41
|
12 |
|
if (null !== $punctuationInQuotes || $punctuationInQuotes === false) { |
|
|
|
|
|
|
42
|
12 |
|
if (preg_match("/([^\.,;]+)([\.,;]{1,})$/", $text, $match)) { |
|
43
|
4 |
|
$punctuation = substr($match[2], -1); |
|
44
|
4 |
|
if ($this->suffix !== $punctuation) { |
|
45
|
1 |
|
$text = $match[1] . substr($match[2], 0, strlen($match[2]) - 1); |
|
46
|
1 |
|
return $openQuote . $text . $closeQuote . $punctuation; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
12 |
|
return $openQuote . $text . $closeQuote; |
|
51
|
|
|
} |
|
52
|
101 |
|
return $text; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param $text |
|
57
|
|
|
* @param $outerOpenQuote |
|
58
|
|
|
* @param $outerCloseQuote |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
12 |
|
private function replaceOuterQuotes($text, $outerOpenQuote, $outerCloseQuote) |
|
62
|
|
|
{ |
|
63
|
12 |
|
$innerOpenQuote = $this->locale->filter("terms", "open-inner-quote")->single; |
|
64
|
12 |
|
$innerCloseQuote = $this->locale->filter("terms", "close-inner-quote")->single; |
|
65
|
12 |
|
$text = StringHelper::replaceOuterQuotes( |
|
66
|
12 |
|
$text, |
|
67
|
12 |
|
"\"", |
|
68
|
12 |
|
"\"", |
|
69
|
12 |
|
$innerOpenQuote, |
|
70
|
12 |
|
$innerCloseQuote |
|
71
|
|
|
); |
|
72
|
12 |
|
$text = StringHelper::replaceOuterQuotes( |
|
73
|
12 |
|
$text, |
|
74
|
12 |
|
$outerOpenQuote, |
|
75
|
12 |
|
$outerCloseQuote, |
|
76
|
12 |
|
$innerOpenQuote, |
|
77
|
12 |
|
$innerCloseQuote |
|
78
|
|
|
); |
|
79
|
12 |
|
return $text; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.