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

VueJS::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 4
dl 0
loc 8
ccs 7
cts 8
cp 0.875
crap 2.0078
rs 10
c 1
b 0
f 0
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
}