Honeypot::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 11
rs 9.4286
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Cerbero\Auth\Http\Middleware;
4
5
use Closure;
6
use Cerbero\Auth\Exceptions\DisplayException;
7
8
/**
9
 * Protect from spam and bots.
10
 *
11
 * @author	Andrea Marco Sartori
12
 */
13
class Honeypot
14
{
15
16
	/**
17
	 * Handle an incoming request.
18
	 *
19
	 * @param  \Illuminate\Http\Request  $request
20
	 * @param  \Closure  $next
21
	 * @return mixed
22
	 */
23
	public function handle($request, Closure $next)
24
	{
25
		if(config('_auth.honeypot.enabled'))
26
		{
27
			$value = $request->input(config('_auth.honeypot.field'));
28
29
			$this->checkHoneypot($value);
30
		}
31
32
		return $next($request);
33
	}
34
35
	/**
36
	 * Throw an exception if the honeypot field is not empty.
37
	 *
38
	 * @author	Andrea Marco Sartori
39
	 * @param	string	$value
40
	 * @return	void
41
	 */
42
	protected function checkHoneypot($value)
43
	{
44
		if($value !== null)
45
		{
46
			throw new DisplayException('auth::honeypot.error');
47
		}
48
	}
49
50
}
51