Completed
Push — master ( 19ee41...299996 )
by Josh
16:50
created

TemplateSafeness   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 97
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A isSafe() 0 5 1
A isSafeAsURL() 0 4 1
A isSafeInCSS() 0 4 1
A isSafeInJS() 0 4 1
A markAsSafeAsURL() 0 6 1
A markAsSafeInCSS() 0 6 1
A markAsSafeInJS() 0 6 1
A resetSafeness() 0 6 1
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2015 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Configurator\Traits;
9
10
trait TemplateSafeness
11
{
12
	/**
13
	* @var array Contexts in which this object is considered safe to be used
14
	*/
15
	protected $markedSafe = [];
16
17
	/**
18
	* Return whether this object is safe to be used in given context
19
	*
20
	* @param  string $context Either 'AsURL', 'InCSS' or 'InJS'
21
	* @return bool
22
	*/
23
	protected function isSafe($context)
24
	{
25
		// Test whether this attribute was marked as safe in given context
26
		return !empty($this->markedSafe[$context]);
27
	}
28
29
	/**
30
	* Return whether this object is safe to be used as a URL
31
	*
32
	* @return bool
33
	*/
34
	public function isSafeAsURL()
35
	{
36
		return $this->isSafe('AsURL');
37
	}
38
39
	/**
40
	* Return whether this object is safe to be used in CSS
41
	*
42
	* @return bool
43
	*/
44
	public function isSafeInCSS()
45
	{
46
		return $this->isSafe('InCSS');
47
	}
48
49
	/**
50
	* Return whether this object is safe to be used in JavaScript
51
	*
52
	* @return bool
53
	*/
54
	public function isSafeInJS()
55
	{
56
		return $this->isSafe('InJS');
57
	}
58
59
	/**
60
	* Return whether this object is safe to be used as a URL
61
	*
62
	* @return self
63
	*/
64
	public function markAsSafeAsURL()
65
	{
66
		$this->markedSafe['AsURL'] = true;
67
68
		return $this;
69
	}
70
71
	/**
72
	* Return whether this object is safe to be used in CSS
73
	*
74
	* @return self
75
	*/
76
	public function markAsSafeInCSS()
77
	{
78
		$this->markedSafe['InCSS'] = true;
79
80
		return $this;
81
	}
82
83
	/**
84
	* Return whether this object is safe to be used in JavaScript
85
	*
86
	* @return self
87
	*/
88
	public function markAsSafeInJS()
89
	{
90
		$this->markedSafe['InJS'] = true;
91
92
		return $this;
93
	}
94
95
	/**
96
	* Reset the "marked safe" statuses
97
	*
98
	* @return self
99
	*/
100
	public function resetSafeness()
101
	{
102
		$this->markedSafe = [];
103
104
		return $this;
105
	}
106
}