Passed
Push — master ( 870e13...7b8ab0 )
by Caen
03:07 queued 13s
created

ImplementsStringHelpers::normalizeNewlines()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Foundation\Concerns;
6
7
use Hyde\Framework\Services\MarkdownService;
8
use Hyde\Markdown\Models\Markdown;
9
use Illuminate\Support\HtmlString;
10
use Illuminate\Support\Str;
11
12
/**
13
 * @internal Single-use trait for the HydeKernel class.
14
 *
15
 * @see \Hyde\Foundation\HydeKernel
16
 */
17
trait ImplementsStringHelpers
18
{
19
    public function makeTitle(string $value): string
20
    {
21
        $alwaysLowercase = ['a', 'an', 'the', 'in', 'on', 'by', 'with', 'of', 'and', 'or', 'but'];
22
23
        return ucfirst(str_ireplace(
0 ignored issues
show
Bug introduced by
It seems like str_ireplace($alwaysLowe...\Str::headline($value)) can also be of type array; however, parameter $string of ucfirst() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        return ucfirst(/** @scrutinizer ignore-type */ str_ireplace(
Loading history...
24
            $alwaysLowercase,
25
            $alwaysLowercase,
26
            Str::headline($value)
27
        ));
28
    }
29
30
    public function normalizeNewlines(string $string): string
31
    {
32
        return str_replace(["\r\n"], "\n", $string);
33
    }
34
35
    public function markdown(string $text, bool $normalizeIndentation = false): HtmlString
36
    {
37
        if ($normalizeIndentation) {
38
            $text = MarkdownService::normalizeIndentationLevel($text);
39
        }
40
41
        return new HtmlString(Markdown::render($text));
42
    }
43
}
44