Passed
Push — main ( 976a1c...cb0b4a )
by Guillaume
03:00
created

VueJS   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 27
ccs 16
cts 17
cp 0.9412
rs 10
c 8
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 5 2
A generateVueObject() 0 3 1
A __construct() 0 8 2
1
<?php
2
namespace PHPMV;
3
4
use PHPMV\js\JavascriptUtils;
5
use PHPMV\utils\JsUtils;
6
7
/**
8
 * PHPMV$VueJS
9
 * This class is part of php-vuejs
10
 *
11
 * @author jc
12
 * @version 1.0.0
13
 *
14
 */
15
class VueJS extends AbstractVueJS {
16
17
	protected array $configuration;
18
	protected bool $useAxios;
19
	protected string $varName;
20
21 10
	public function __construct(array $configuration = ['el'=>'#app'], string $varName = "app", bool $useAxios = false, bool $useVuetify = false) {
22 10
		parent::__construct();
23 10
		$this->useAxios = $useAxios;
24 10
		$this->varName = $varName;
25 10
		$configuration['el'] = "'". $configuration['el'] ."'";
26 10
		$this->configuration = $configuration;
27 10
        if ($useVuetify){
28
            $this->configuration['vuetify'] = "new Vuetify()";
29
        }
30 10
	}
31
32 1
    protected function generateVueObject(string $object):string {
33 1
        $vueObject = "new Vue(".$object.")";
34 1
        return JsUtils::cleanJSONFunctions($vueObject);
35
    }
36
37 1
	public function __toString():string {
38 1
        $script = $this->generateVueObject(JavascriptUtils::arrayToJsObject($this->configuration + $this->components + $this->directives + $this->filters + $this->data + $this->computeds + $this->watchers + $this->hooks + $this->methods));
39 1
        $script = JsUtils::declareVariable('const',$this->varName,$script);
40 1
        $script .= ($this->useAxios) ? $this->varName.".prototype.\$http = axios;\n" : "";
41 1
		return $script;
42
	}
43
}