CallbackSanitizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 8 2
A write() 0 8 2
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