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

CallbackSanitizer::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 6
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