Passed
Push — main ( 92de25...9fb01f )
by Guillaume
02:18
created

VueJSComponent   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 22
ccs 0
cts 13
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProps() 0 2 1
A __construct() 0 4 1
A create() 0 7 1
1
<?php
2
namespace PHPMV;
3
4
use PHPMV\js\JavascriptUtils;
5
use PHPMV\utils\JsUtils;
6
7
class VueJSComponent extends AbstractVueJS{
8
    protected $name;
9
    protected $props=["props"=>[]];
10
    protected $template;
11
    
12
    public function __construct(string $template) {
13
        parent::__construct();
14
        $this->template["template"]="'".\str_replace(["\n","\r","\t"]," ",(\file_get_contents($template.'.html',true))."'");
15
        $this->name=$template;
16
    }
17
    
18
    public function setProps(string ...$name):void {
19
        $this->props["props"]=$name;
20
    }
21
    
22
    public function create():string {
23
        $script="Vue.component('".$this->name."',";
24
        $script.=JavascriptUtils::arrayToJsObject($this->props + $this->data + $this->methods + $this->computeds + $this->watchers + $this->hooks + $this->template);
25
        $script=JsUtils::cleanJSONFunctions($script);
26
        $script.=")";
27
        \file_put_contents($this->name.".js", $script);
28
        return $script;
29
    }
30
}