Completed
Push — master ( d732f2...827150 )
by smiley
01:50
created

MemzeroDestructorTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __destruct() 0 11 3
1
<?php
2
/**
3
 * Trait MemzeroDestructorTrait
4
 *
5
 * @filesource   MemzeroDestructorTrait.php
6
 * @created      25.01.2018
7
 * @package      chillerlan\Traits\Crypto
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2018 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Traits\Crypto;
14
15
trait MemzeroDestructorTrait{
16
17
	/**
18
	 * @return void
19
	 */
20
	public function __destruct(){
21
22
		foreach(array_keys(get_object_vars($this)) as $key){
23
24
			if(is_scalar($this->{$key})){
25
				$this->{$key} = (string)$this->{$key};
26
27
				sodium_memzero($this->{$key});
28
			}
29
30
			unset($this->{$key});
31
		}
32
33
	}
34
35
36
}
37