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

ImplementsStringHelpers   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 5
Bugs 2 Features 0
Metric Value
eloc 10
c 5
b 2
f 0
dl 0
loc 25
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A markdown() 0 7 2
A normalizeNewlines() 0 3 1
A makeTitle() 0 8 1
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