SentenceCase   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ReliqArts\DirectTranslator\Translation\Formatter;
6
7
use ReliqArts\DirectTranslator\Translation\Formatter;
8
9
final class SentenceCase implements Formatter
10
{
11
    private const PATTERN = '/([.!?])\s*(\w)/';
12
13
    /**
14
     * {@inheritdoc}
15
     *
16
     * @return string
17
     */
18
    public function apply(string $inputText): string
19
    {
20
        $str = ucfirst($inputText);
21
22
        return preg_replace_callback(
23
            self::PATTERN,
24
            function ($matches) {
25
                return strtoupper($matches[0]);
26
            },
27
            $str
28
        );
29
    }
30
}
31