CallbackSanitizer::read()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Sanitizers;
15
16
use Maslosoft\Mangan\Interfaces\Sanitizers\Property\SanitizerInterface;
17
18
/**
19
 * Callback sanitizer
20
 *
21
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
22
 */
23
class CallbackSanitizer implements SanitizerInterface
24
{
25
26
	/**
27
	 * Callback to sanitize value when writing
28
	 * @var callable
29
	 */
30
	public $write = null;
31
32
	/**
33
	 * Callback to sanitize value when reading
34
	 * @var callable
35
	 */
36
	public $read = null;
37
38
	public function read($model, $dbValue)
39
	{
40
		if (null !== $this->read)
41
		{
42
			return call_user_func($this->read, $dbValue);
43
		}
44
		return $dbValue;
45
	}
46
47
	public function write($model, $phpValue)
48
	{
49
		if (null !== $this->write)
50
		{
51
			return call_user_func($this->write, $phpValue);
52
		}
53
		return $phpValue;
54
	}
55
56
}
57