Completed
Push — master ( e0f8d3...c7a6bb )
by Peter
16:49
created

CallbackSanitizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 2
cbo 0
dl 0
loc 34
ccs 0
cts 16
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 8 2
A write() 0 8 2
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Mangan\Sanitizers;
10
11
use Maslosoft\Mangan\Interfaces\Sanitizers\Property\SanitizerInterface;
12
13
/**
14
 * Callback sanitizer
15
 *
16
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
17
 */
18
class CallbackSanitizer implements SanitizerInterface
19
{
20
21
	/**
22
	 * Callback to sanitize value when writing
23
	 * @var callable
24
	 */
25
	public $write = null;
26
27
	/**
28
	 * Callback to sanitize value when reading
29
	 * @var callable
30
	 */
31
	public $read = null;
32
33
	public function read($model, $dbValue)
34
	{
35
		if (null !== $this->read)
36
		{
37
			return call_user_func($this->read, $dbValue);
38
		}
39
		return $dbValue;
40
	}
41
42
	public function write($model, $phpValue)
43
	{
44
		if (null !== $this->write)
45
		{
46
			return call_user_func($this->write, $phpValue);
47
		}
48
		return $phpValue;
49
	}
50
51
}
52