GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DigestHttpAuthentication::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 2
nop 2
dl 0
loc 23
ccs 11
cts 11
cp 1
crap 4
rs 9.552
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package presentation
4
 * @subpackage requests
5
 * @author marius orcsik <[email protected]>
6
 * @date 2013.09.26
7
 */
8
namespace vsc\presentation\requests;
9
10
class DigestHttpAuthentication extends HttpAuthenticationA {
11
	/**
12
	 * @var string
13
	 */
14
	public $username;
15
	/**
16
	 * @var int
17
	 */
18
	protected $Type = HttpAuthenticationA::DIGEST;
19
	/**
20
	 * @var string
21
	 */
22
	protected $HTTPMethod;
23
	/**
24
	 * @var string
25
	 */
26
	private $nonce;
27
	/**
28
	 * @var string
29
	 */
30
	private $nc;
31
	/**
32
	 * @var string
33
	 */
34
	private $cnonce;
35
	/**
36
	 * @var string
37
	 */
38
	private $qop;
39
	/**
40
	 * @var string
41
	 */
42
	private $uri;
43
	/**
44
	 * @var string
45
	 */
46
	private $response;
47
	/**
48
	 * @param string $sDigestResponse
49
	 * @param string $sHTTPMethod
50
	 */
51 1
	public function __construct($sDigestResponse, $sHTTPMethod = HttpRequestTypes::GET) {
52
		$aNeededParts = array(
53 1
			'nonce' => 1,
54
			'nc' => 1,
55
			'cnonce' => 1,
56
			'qop' => 1,
57
			'username' => 1,
58
			'uri' => 1,
59
			'response' => 1
60
 		);
61
62 1
		$keys = implode('|', array_keys($aNeededParts));
63 1
		$i = preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $sDigestResponse, $aMatches, PREG_SET_ORDER);
64
65 1
		if ($i) {
66 1
			foreach ($aMatches as $m) {
67 1
				$sProperty = $m[1];
68 1
				$this->$sProperty = $m[3] ? $m[3] : $m[4];
69 1
				unset($aNeededParts[$m[1]]);
70
			}
71
		}
72 1
		$this->HTTPMethod = $sHTTPMethod;
73 1
	}
74
75
	/**
76
	 * @param string $sPassword
77
	 * @param string $sRealm
78
	 * @return bool
79
	 */
80 1
	public function validateDigestAuthentication($sPassword, $sRealm) {
81 1
		$a1 = md5($this->username . ':' . $sRealm . ':' . $sPassword);
82 1
		$a2 = md5($this->HTTPMethod . ':' . $this->uri);
83 1
		$sValidResponse = md5($a1 . ':' . $this->nonce . ':' . $this->nc . ':' . $this->cnonce . ':' . $this->qop . ':' . $a2);
84
85 1
		return $sValidResponse == $this->response;
86
	}
87
}
88