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

SecretAnnotation::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
crap 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\Annotations;
10
11
use Maslosoft\Mangan\Decorators\Property\SecretDecorator;
12
use Maslosoft\Mangan\Meta\ManganPropertyAnnotation;
13
use Maslosoft\Mangan\Meta\SecretMeta;
14
15
/**
16
 * Secret Annotation
17
 *
18
 * Use this annotation to create "write-only" field, with possible callback when saving.
19
 * When this annotation is active, only non empty values will be stored in database.
20
 *
21
 * Optional callback can be used to transform value before save, ie hash function:
22
 *
23
 * ```php
24
 * Secret('sha1')
25
 * ```
26
 *
27
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
28
 */
29
class SecretAnnotation extends ManganPropertyAnnotation
30
{
31
32
	public $value;
33
34 1
	public function init()
35
	{
36 1
		$data = [];
37 1
		if ($this->value)
38 1
		{
39 1
			$data['callback'] = $this->value;
40 1
			$this->_entity->decorators[] = SecretDecorator::class;
41 1
		}
42 1
		$this->_entity->secret = new SecretMeta($data);
43 1
	}
44
45
}
46