Passed
Push — master ( d9ba4f...648548 )
by Bruno
07:53
created

Button   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 12 5
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Vue\Element;
4
5
use Formularium\Element;
6
use Formularium\Frontend\HTML\Element\Button as HTMLButton;
7
use Formularium\HTMLNode;
8
use Illuminate\Support\Str;
9
10
class Button extends HTMLButton
11
{
12
    public function render(array $parameters, HTMLNode $previous): HTMLNode
13
    {
14
        // convert to vue router
15
        $href = $previous->getAttribute('href'); // array?
16
        $href = $href[0] ?? '';
17
        if ($previous->getTag() === 'a' && $href && !Str::startsWith('http', $href) && !Str::startsWith('#', $href)) {
18
            $previous->setTag('router-link');
19
            $previous->removeAttribute('href');
20
            $previous->addAttribute(':to', "'" . $href . "'");
21
        }
22
23
        return $previous;
24
    }
25
}
26