Passed
Push — master ( 99a753...df0863 )
by Remco
19:34 queued 09:07
created

Message   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 51
ccs 9
cts 14
cp 0.6429
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get_signature() 0 2 1
A set_signature() 0 2 1
A is_valid() 0 8 2
A sign() 0 4 1
1
<?php
2
/**
3
 * Message
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\OmniKassa2
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;
12
13
/**
14
 * Message
15
 *
16
 * @author  Remco Tolsma
17
 * @version 2.1.0
18
 * @since   2.0.2
19
 */
20
abstract class Message implements Signable {
21
	/**
22
	 * Signature.
23
	 *
24
	 * @var string
25
	 */
26
	private $signature;
27
28
	/**
29
	 * Get signature.
30
	 *
31
	 * @return string
32
	 */
33 5
	public function get_signature() {
34 5
		return $this->signature;
35
	}
36
37
	/**
38
	 * Set signature.
39
	 *
40
	 * @param string $signature Signature.
41
	 */
42 5
	protected function set_signature( $signature ) {
43 5
		$this->signature = $signature;
44 5
	}
45
46
	/**
47
	 * Sign this message with specified signing key.
48
	 *
49
	 * @param string $signing_key Signing key.
50
	 */
51
	public function sign( $signing_key ) {
52
		$signature = Security::get_signature( $this, $signing_key );
53
54
		$this->set_signature( $signature );
55
	}
56
57
	/**
58
	 * Check if this message is valid.
59
	 *
60
	 * @param string $signing_key Signing key.
61
	 * @return bool True if valid, false otherwise.
62
	 */
63 3
	public function is_valid( $signing_key ) {
64 3
		$signature = Security::get_signature( $this, $signing_key );
65
66 3
		if ( empty( $signature ) ) {
67
			return false;
68
		}
69
70 3
		return Security::validate_signature( $signature, $this->get_signature() );
71
	}
72
}
73