Completed
Pull Request — v4.0-dev (#203)
by
unknown
01:35
created

EscapedProxy   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __unwrap() 0 3 1
A __toString() 0 3 1
A create() 0 10 4
1
<?php
2
3
namespace League\Plates\Extension\AutoEscape;
4
5
abstract class EscapedProxy
6
{
7
    protected $escape;
8
    protected $wrapped;
9
10 28
    protected function __construct($wrapped, callable $escape) {
11 28
        $this->wrapped = $wrapped;
12 28
        $this->escape = $escape;
13 28
    }
14
15 4
    public function __unwrap() {
16 4
        return $this->wrapped;
17
    }
18
19 24
    public function __toString() {
20 24
        return ($this->escape)($this->wrapped);
21
    }
22
23 32
    public static function create($wrapped, callable $escape) {
24 32
        if (is_object($wrapped) || is_array($wrapped)) {
25 24
            return new ObjectEscapedProxy($wrapped, $escape);
26
        }
27 28
        if (is_string($wrapped)) {
28 24
            return new ScalarEscapedProxy($wrapped, $escape);
29
        }
30
31 16
        return $wrapped;
32
    }
33
}
34