Passed
Push — 5.0.0 ( dd8bc0...b0cec2 )
by Fèvre
05:00
created

Markdown   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A errorFieldName() 0 3 1
A modelName() 0 3 1
A render() 0 3 1
A __construct() 0 16 1
A setup() 0 24 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\View\Components;
6
7
use Closure;
8
use Illuminate\Contracts\View\View;
9
use Illuminate\View\Component;
10
11
class Markdown extends Component
12
{
13
    public string $uuid;
14
15
    public string $uploadUrl;
16
17
    public function __construct(
18
        public ?string $value = null,
19
        public ?string $label = null,
20
        public ?string $hint = null,
21
        public ?string $hintClass = 'fieldset-label',
22
        public ?string $disk = 'public',
23
        public ?string $folder = 'markdown',
24
        public ?array $config = [],
25
26
        // Validations
27
        public ?string $errorClass = 'text-error',
28
        public ?bool $omitError = false,
29
        public ?bool $firstErrorOnly = false,
30
    ) {
31
        $this->uuid = md5(serialize($this));
32
        $this->uploadUrl = route('upload', absolute: false);
33
    }
34
35
    public function modelName(): ?string
36
    {
37
        return $this->attributes->whereStartsWith('wire:model')->first();
38
    }
39
40
    public function errorFieldName(): ?string
41
    {
42
        return $this->modelName() ?? $this->attributes->whereStartsWith('name')->first();
43
    }
44
45
    public function setup(): string
46
    {
47
        $setup = array_merge([
48
            'spellChecker' => false,
49
            'autoSave' => false,
50
            'uploadImage' => true,
51
            'imageAccept' => 'image/png, image/jpeg',
52
            'toolbar' => [
53
                'heading', 'bold', 'italic', 'strikethrough', '|',
54
                'code', 'quote', 'unordered-list', 'ordered-list', 'horizontal-rule', '|',
55
                'link', 'upload-image', 'table', '|',
56
                'preview', 'side-by-side'
57
            ],
58
        ], $this->config);
0 ignored issues
show
Bug introduced by
It seems like $this->config can also be of type null; however, parameter $arrays of array_merge() does only seem to accept array, 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

58
        ], /** @scrutinizer ignore-type */ $this->config);
Loading history...
59
60
        // Table default CSS class `.table` breaks the layout.
61
        // Here is a workaround
62
        $table = "{ 'title' : 'Table', 'name' : 'myTable', 'action' : EasyMDE.drawTable, 'className' : 'fa fa-table' }";
63
64
        return str(json_encode($setup))
65
            ->replace("\"", "'")
66
            ->trim('{}')
67
            ->replace("'table'", $table)
68
            ->toString();
69
    }
70
71
    /**
72
     * Get the view / contents that represent the component.
73
     */
74
    public function render(): View|Closure|string
75
    {
76
        return view('components.markdown');
77
    }
78
}
79