Passed
Push — main ( 8a2c2c...f2e444 )
by Guillaume
02:30
created

AbstractVueJS   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Test Coverage

Coverage 93.18%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 46
dl 0
loc 132
ccs 82
cts 88
cp 0.9318
rs 10
c 1
b 0
f 0
wmc 30

29 Methods

Rating   Name   Duplication   Size   Complexity  
A setWatchers() 0 2 1
A onUpdatedNextTick() 0 2 1
A setData() 0 2 1
A addData() 0 2 1
A getWatchers() 0 2 1
A onCreated() 0 2 1
A onBeforeMount() 0 2 1
A setMethods() 0 2 1
A addGlobalFilter() 0 2 1
A generateFunction() 0 2 1
A addWatcher() 0 2 1
A onBeforeDestroy() 0 2 1
A getMethods() 0 2 1
A setComputeds() 0 2 1
A onBeforeCreate() 0 2 1
A addMethod() 0 2 1
A __construct() 0 8 1
A getHooks() 0 2 1
A addDataRaw() 0 2 1
A addComputed() 0 3 2
A setHooks() 0 2 1
A addFilter() 0 2 1
A getComputeds() 0 2 1
A onBeforeUpdate() 0 2 1
A addHook() 0 2 1
A onDestroyed() 0 2 1
A onMounted() 0 2 1
A getData() 0 2 1
A onUpdated() 0 2 1
1
<?php
2
namespace PHPMV;
3
4
/**
5
 * Created by PhpStorm.
6
 * User: qgorak
7
 * Date: 19/11/2020
8
 * Time: 14:20
9
 */
10
class AbstractVueJS {
11
    static private $removeQuote = ["start"=>"!!%","end"=>"%!!"];
12
    static protected $global;
13
	protected $data;
14
	protected $methods;
15
	protected $computeds;
16
	protected $watchers;
17
	protected $directives;
18
	protected $filters;
19
	protected $hooks;
20
	
21 11
	public function __construct() {
22 11
	    $this->data=[];
23 11
	    $this->methods=[];
24 11
	    $this->computeds=[];
25 11
	    $this->watchers=[];
26 11
	    $this->directives=[];
27 11
	    $this->filters=[];
28 11
	    $this->hooks=[];
29 11
	}
30
	
31 2
	public function addHook(string $name,string $body):void {
32 2
	    $this->hooks[$name] = self::generateFunction($body);
33 2
	}
34
	
35 1
	public function onBeforeCreate(string $body):void {
36 1
		$this->addHook("beforeCreate", $body);
37 1
	}
38
	
39 1
	public function onCreated(string $body):void {
40 1
		$this->addHook("created", $body);
41 1
	}
42
	
43 1
	public function onBeforeMount(string $body):void {
44 1
		$this->addHook("beforeMount", $body);
45 1
	}
46
	
47 2
	public function onMounted(string $body):void {
48 2
		$this->addHook("mounted", $body);
49 2
	}
50
	
51 1
	public function onBeforeUpdate(string $body):void {
52 1
		$this->addHook("beforeUpdate", $body);
53 1
	}
54
	
55 1
	public function onUpdated(string $body):void {
56 1
		$this->addHook("updated", $body);
57 1
	}
58
	
59 1
	public function onUpdatedNextTick(string $body):void {
60 1
		$this->addHook("updated", "this.\$nextTick(function () {".$body."})");
61 1
	}
62
	
63 1
	public function onBeforeDestroy(string $body):void {
64 1
		$this->addHook("beforeDestroy", $body);
65 1
	}
66
	
67 1
	public function onDestroyed(string $body):void {
68 1
		$this->addHook("destroyed", $body);
69 1
	}
70
71 3
	public function addData(string $name,$value):void {
72 3
        $this->data["data"][$name]=$value;
73 3
	}
74
75 2
	public function addDataRaw(string $name,string $value):void {
76 2
        $this->data["data"][$name]=self::$removeQuote["start"].$value.self::$removeQuote["end"];
77 2
	}
78
	
79 4
	public function addMethod(string $name,string $body, array $params = []):void {
80 4
        $this->methods["methods"][$name]=self::generateFunction($body,$params);
81 4
	}
82
	
83 3
	public function addComputed(string $name,string $get,string $set=null):void {
84 3
	    $vc=(is_null($set)) ? self::generateFunction($get) : self::$removeQuote["start"]."{ get: ".self::generateFunction($get).", set: ".self::generateFunction($set,["v"])." }".self::$removeQuote["end"];
85 3
	    $this->computeds["computeds"][self::$removeQuote["start"].$name.self::$removeQuote["end"]]=$vc;
86 3
	}
87
	
88 2
	public function addWatcher(string $var,string $body,array $params=[]):void {
89 2
	    $this->watchers["watch"][$var]=self::generateFunction($body,$params);
90 2
	}
91
92
	public function addFilter(string $name,string $body, array $params = []):void {
93
        $this->methods["filters"][self::$removeQuote["start"].$name.self::$removeQuote["end"]]=self::generateFunction($body,$params);
94
    }
95
96
    static function addGlobalFilter(string $name,string $body, array $params = []):void {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
97
        self::$global[]=self::$removeQuote["start"]."Vue.filter('".$name."',".self::generateFunction($body,$params).");".self::$removeQuote["end"];
98
    }
99
100 4
	public function getData():array {
101 4
	    return $this->data;
102
	}
103
	
104 1
	public function setData(array $data):void {
105 1
	    $this->data=$data;
106 1
	}
107
	
108 3
	public function getMethods():array {
109 3
	    return $this->methods;
110
	}
111
	
112 1
	public function setMethods(array $methods):void {
113 1
	    $this->methods=$methods;
114 1
	}
115
	
116 3
	public function getComputeds():array {
117 3
		return $this->computeds;
118
	}
119
120 1
	public function setComputeds(array $computeds):void {
121 1
		$this->computeds = $computeds;
122 1
	}
123
124 2
	public function getWatchers():array {
125 2
	    return $this->watchers;
126
	}
127
	
128 1
	public function setWatchers(array $watchers):void {
129 1
		$this->watchers = $watchers;
130 1
	}
131
	
132 2
	public function getHooks():array {
133 2
		return $this->hooks;
134
	}
135
	
136 1
	public function setHooks(array $hooks):void {
137 1
		$this->hooks = $hooks;
138 1
	}
139
140 6
	static function generateFunction(string $body, array $params = []):string {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
141 6
        return self::$removeQuote["start"]."function(".implode(",",$params)."){".$body."}".self::$removeQuote["end"];
142
    }
143
}