SecuredTrait::isSecured()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.2
cc 4
eloc 6
nc 6
nop 1
crap 4
1
<?php
2
3
/**
4
 * This file is part of Lekarna.cz (http://www.lekarna.cz/)
5
 *
6
 * Copyright (c) 2014 Pears Health Cyber, s.r.o. (http://pearshealthcyber.cz)
7
 *
8
 * For the full copyright and license information, please view
9
 * the file LICENSE that was distributed with this source code.
10
 */
11
12
namespace App;
13
14
use Slim\Http\Request;
15
16
17
trait SecuredTrait
18
{
19
20
	/**
21
	 * @var string
22
	 */
23
	private $secret;
24
25
26
	/**
27
	 * @param Request $request
28
	 * @return bool
29
	 */
30 15
	private function isSecured(Request $request)
31
	{
32 15
		$secured = FALSE;
33 15
		foreach ($request->getHeader(self::SECRET_HEADER) as $secret) {
34 13
			if ($secret == $this->secret) { // allow cast
35 13
				$secured = TRUE;
36 13
			}
37 15
		}
38
39 15
		return $this->secret === NULL || $secured;
40
	}
41
42
}
43