Passed
Push — main ( f61cf1...0f2cdb )
by Guillaume
02:44
created

VueJS   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
eloc 14
c 8
b 0
f 0
dl 0
loc 24
ccs 14
cts 15
cp 0.9333
rs 10
wmc 4

3 Methods

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