AbstractVueJS   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 51
dl 0
loc 110
ccs 79
cts 79
cp 1
rs 10
c 3
b 1
f 0
wmc 22

20 Methods

Rating   Name   Duplication   Size   Complexity  
A onUpdatedNextTick() 0 2 1
A onCreated() 0 2 1
A onBeforeMount() 0 2 1
A onBeforeDestroy() 0 2 1
A onBeforeCreate() 0 2 1
A addHook() 0 2 1
A onMounted() 0 2 1
A onDestroyed() 0 2 1
A onBeforeUpdate() 0 2 1
A onUpdated() 0 2 1
A addData() 0 3 1
A addMixin() 0 3 1
A addComponent() 0 2 1
A addWatcher() 0 3 1
A addMethod() 0 3 1
A __construct() 0 11 1
A addFilter() 0 3 1
A addDirective() 0 5 2
A addDataRaw() 0 3 1
A addComputed() 0 4 2
1
<?php
2
3
namespace PHPMV;
4
5
use PHPMV\js\JavascriptUtils;
6
7
/**
8
 * Created by PhpStorm.
9
 * User: qgorak
10
 * Date: 19/11/2020
11
 * Time: 14:20
12
 */
13
abstract class AbstractVueJS {
14
	protected array $configuration;
15
	protected array $data;
16
	protected array $methods;
17
	protected array $computeds;
18
	protected array $watchers;
19
	protected array $components;
20
	protected array $directives;
21
	protected array $filters;
22
	protected array $hooks;
23
	protected array $mixins;
24
25 1
	protected function __construct(array $configuration) {
26 1
		$this->configuration = $configuration;
27 1
		$this->data = [];
28 1
		$this->methods = [];
29 1
		$this->computeds = [];
30 1
		$this->watchers = [];
31 1
		$this->components = [];
32 1
		$this->directives = [];
33 1
		$this->filters = [];
34 1
		$this->hooks = [];
35 1
		$this->mixins = [];
36 1
	}
37
38 1
	protected function addHook(string $name, string $body): void {
39 1
		$this->hooks[$name] = JavascriptUtils::generateFunction($body);
40 1
	}
41
42 1
	public function onBeforeCreate(string $body): void {
43 1
		$this->addHook("beforeCreate", $body);
44 1
	}
45
46 1
	public function onCreated(string $body): void {
47 1
		$this->addHook("created", $body);
48 1
	}
49
50 1
	public function onBeforeMount(string $body): void {
51 1
		$this->addHook("beforeMount", $body);
52 1
	}
53
54 1
	public function onMounted(string $body): void {
55 1
		$this->addHook("mounted", $body);
56 1
	}
57
58 1
	public function onBeforeUpdate(string $body): void {
59 1
		$this->addHook("beforeUpdate", $body);
60 1
	}
61
62 1
	public function onUpdated(string $body): void {
63 1
		$this->addHook("updated", $body);
64 1
	}
65
66 1
	public function onUpdatedNextTick(string $body): void {
67 1
		$this->addHook("updated", "this.\$nextTick(function () { $body })");
68 1
	}
69
70 1
	public function onBeforeDestroy(string $body): void {
71 1
		$this->addHook("beforeDestroy", $body);
72 1
	}
73
74 1
	public function onDestroyed(string $body): void {
75 1
		$this->addHook("destroyed", $body);
76 1
	}
77
78 1
	public function addData(string $name, $value): void {
79 1
		$name = JavascriptUtils::removeQuotes($name);
80 1
		$this->data["data"][$name] = $value;
81 1
	}
82
83 1
	public function addDataRaw(string $name, string $value): void {
84 1
		$name = JavascriptUtils::removeQuotes($name);
85 1
		$this->data["data"][$name] = JavascriptUtils::removeQuotes($value);
86 1
	}
87
88 1
	public function addMethod(string $name, string $body, array $params = []): void {
89 1
		$name = JavascriptUtils::removeQuotes($name);
90 1
		$this->methods["methods"][$name] = JavascriptUtils::generateFunction($body, $params);
91 1
	}
92
93 1
	public function addComputed(string $name, string $get, string $set = null): void {
94 1
		$name = JavascriptUtils::removeQuotes($name);
95 1
		$vc = (is_null($set)) ? JavascriptUtils::generateFunction($get) : JavascriptUtils::removeQuotes("{ get: " . JavascriptUtils::generateFunction($get, [], false) . ", set: " . JavascriptUtils::generateFunction($set, ["v"], false) . " }");
96 1
		$this->computeds["computeds"][$name] = $vc;
97 1
	}
98
99 1
	public function addComponent(VueJSComponent $component): void {
100 1
		$this->components['components'][$component->getName()] = JavascriptUtils::removeQuotes($component->getVarName());
101 1
	}
102
103 1
	public function addWatcher(string $var, string $body, array $params = []): void {
104 1
		$var = JavascriptUtils::removeQuotes($var);
105 1
		$this->watchers["watch"][$var] = JavascriptUtils::generateFunction($body, $params);
106 1
	}
107
108 1
	public function addMixin(VueJSComponent $mixin): void {
109 1
		$varName = JavascriptUtils::removeQuotes($mixin->getVarName());
110 1
		$this->mixins["mixins"][] = $varName;
111 1
	}
112
113 1
	public function addFilter(string $name, string $body, array $params = []): void {
114 1
		$name = JavascriptUtils::removeQuotes($name);
115 1
		$this->filters["filters"][$name] = JavascriptUtils::generateFunction($body, $params);
116 1
	}
117
118 1
	public function addDirective(string $name, array $hookFunction): void {
119 1
		$name = JavascriptUtils::removeQuotes($name);
120 1
		foreach ($hookFunction as $key => $value) {
121 1
			$key = JavascriptUtils::removeQuotes($key);
122 1
			$this->directives["directives"][$name][$key] = JavascriptUtils::generateFunction($value, ['el', 'binding', 'vnode', 'oldVnode']);
123
		}
124
	}
125
}