Honeypot   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 38
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 2
A checkHoneypot() 0 7 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