Test Failed
Push — main ( dfcf0b...cfa9b1 )
by Guillaume
03:09
created

AbstractVueJS::addFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 11
	protected $hooks;
20 11
	
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
	    $this->hooks=[];
29 2
	}
30 2
	
31 2
	public function addHook(string $name,string $body):void {
32
	    $this->hooks[$name] = AbstractVueJS::generateFunction($body);
33 1
	}
34 1
	
35 1
	public function onBeforeCreate(string $body):void {
36
		$this->addHook("beforeCreate", $body);
37 1
	}
38 1
	
39 1
	public function onCreated(string $body):void {
40
		$this->addHook("created", $body);
41 1
	}
42 1
	
43 1
	public function onBeforeMount(string $body):void {
44
		$this->addHook("beforeMount", $body);
45 2
	}
46 2
	
47 2
	public function onMounted(string $body):void {
48
		$this->addHook("mounted", $body);
49 1
	}
50 1
	
51 1
	public function onBeforeUpdate(string $body):void {
52
		$this->addHook("beforeUpdate", $body);
53 1
	}
54 1
	
55 1
	public function onUpdated(string $body):void {
56
		$this->addHook("updated", $body);
57 1
	}
58 1
	
59 1
	public function onUpdatedNextTick(string $body):void {
60
		$this->addHook("updated", "this.\$nextTick(".AbstractVueJS::generateFunction($body).")");
61 1
	}
62 1
	
63 1
	public function onBeforeDestroy(string $body):void {
64
		$this->addHook("beforeDestroy", $body);
65 1
	}
66 1
	
67 1
	public function onDestroyed(string $body):void {
68
		$this->addHook("destroyed", $body);
69 3
	}
70 3
71 3
	public function addData(string $name,$value):void {
72
        $this->data["data"][$name]=$value;
73 2
	}
74 2
75 2
	public function addDataRaw(string $name,string $value):void {
76
        $this->data["data"][$name]=AbstractVueJS::$removeQuote["start"].$value.AbstractVueJS::$removeQuote["end"];
77 4
	}
78 4
	
79 4
	public function addMethod(string $name,string $body, array $params = []):void {
80
        $this->methods["methods"][$name]=AbstractVueJS::generateFunction($body,$params);
81 3
	}
82 3
	
83 3
	public function addComputed(string $name,string $get,string $set=null):void {
84 3
	    $vc=(is_null($set)) ? AbstractVueJS::generateFunction($get) : AbstractVueJS::$removeQuote["start"]."{ get: ".AbstractVueJS::generateFunction($get).", set: ".AbstractVueJS::generateFunction($set,["v"])." }".AbstractVueJS::$removeQuote["end"];
85
	    $this->computeds["computeds"][AbstractVueJS::$removeQuote["start"].$name.AbstractVueJS::$removeQuote["end"]]=$vc;
86 2
	}
87 2
	
88 2
	public function addWatcher(string $var,string $body,array $params=[]):void {
89
	    $this->watchers["watch"][$var]=AbstractVueJS::generateFunction($body,$params);
90 4
	}
91 4
92
	public function addFilter(string $name,string $body, array $params = []):void {
93
        $this->methods["filters"][AbstractVueJS::$removeQuote["start"].$name.AbstractVueJS::$removeQuote["end"]]=AbstractVueJS::generateFunction($body,$params);
94 1
    }
95 1
96 1
    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
        AbstractVueJS::$global[]=AbstractVueJS::$removeQuote["start"]."Vue.filter('".$name."',".AbstractVueJS::generateFunction($body,$params).");".AbstractVueJS::$removeQuote["end"];
98 3
    }
99 3
100
	public function getData():array {
101
	    return $this->data;
102 1
	}
103 1
	
104 1
	public function setData(array $data):void {
105
	    $this->data=$data;
106 3
	}
107 3
	
108
	public function getMethods():array {
109
	    return $this->methods;
110 1
	}
111 1
	
112 1
	public function setMethods(array $methods):void {
113
	    $this->methods=$methods;
114 2
	}
115 2
	
116
	public function getComputeds():array {
117
		return $this->computeds;
118 1
	}
119 1
120 1
	public function setComputeds(array $computeds):void {
121
		$this->computeds = $computeds;
122 2
	}
123 2
124
	public function getWatchers():array {
125
	    return $this->watchers;
126 1
	}
127 1
	
128 1
	public function setWatchers(array $watchers):void {
129 1
		$this->watchers = $watchers;
130
	}
131
	
132
	public function getHooks():array {
133
		return $this->hooks;
134
	}
135
	
136
	public function setHooks(array $hooks):void {
137
		$this->hooks = $hooks;
138
	}
139
140
	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
        return AbstractVueJS::$removeQuote["start"]."function(".implode(",",$params)."){".$body."}".AbstractVueJS::$removeQuote["end"];
142
    }
143
}