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

SecretAnnotation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 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