Passed
Push — main ( f5d3c8...cedc07 )
by Guillaume
02:48
created

VueJS::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 5
b 0
f 0
nc 2
nop 0
dl 0
loc 11
ccs 10
cts 10
cp 1
crap 2
rs 9.9666
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 bool $useAxios;
18
19
	protected array $configuration;
20
21 12
	public function __construct(string $app = "#app", bool $vuetify = false, bool $useAxios = false) {
22 12
		parent::__construct();
23 12
		$this->configuration['el'] = '"' . $app . '"';
24 12
		if ($vuetify) {
25 12
			$this->configuration['vuetify'] = "new Vuetify()";
26
		}
27 12
		$this->useAxios = $useAxios;
28 12
	}
29
30 1
	public function __toString(): string {
31 1
        $script = "";
32 1
		if ($this->useAxios) {
33 1
			$script .= "Vue.prototype.\$http = axios;\n";
34
		}
35 1
		$script .= "const app=new Vue(";
36 1
		$script .= JavascriptUtils::arrayToJsObject($this->configuration + $this->data + $this->methods + $this->directives + $this->watchers + $this->filters + $this->computeds + $this->hooks);
37 1
		$script = JsUtils::cleanJSONFunctions($script);
38 1
		$script .= ")";
39 1
		$script = JavascriptUtils::wrapScript($script);
40 1
		return $script;
41
	}
42
43 1
	public function getUseAxios(): bool {
44 1
		return $this->useAxios;
45
	}
46
47 2
	public function setUseAxios(bool $useAxios): void {
48 2
		$this->useAxios = $useAxios;
49 2
	}
50
51 1
	public function getConfiguration(): array {
52 1
		return $this->configuration;
53
	}
54
55 1
	public function setConfiguration(array $configuration): void {
56 1
		$this->configuration = $configuration;
57
	}
58
}