Test Failed
Push — main ( d7f1b4...976a1c )
by Guillaume
02:42
created

VueJS::generateVueObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
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 12
	public function __construct(array $configuration = ['el'=>'#app'], string $varName = "app", bool $useAxios = false, bool $useVuetify = false) {
22 12
		parent::__construct();
23 12
		$this->useAxios = $useAxios;
24 12
		$this->varName = $varName;
25 12
		$configuration['el'] = "'". $configuration['el'] ."'";
26 12
		$this->configuration = $configuration;
27
        if ($useVuetify){
28 12
            $this->configuration['vuetify'] = "new Vuetify()";
29 12
        }
30
	}
31 1
32 1
    protected function generateVueObject(string $object):string {
33 1
        $vueObject = "new Vue(".$object.")";
34 1
        return JsUtils::cleanJSONFunctions($vueObject);
35
    }
36 1
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
}