Passed
Push — master ( f7f26a...2fd308 )
by Atanas
02:20
created

CsrfMiddleware::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 11
ccs 0
cts 8
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace WPEmerge\Csrf;
4
5
use Closure;
6
use WPEmerge\Exceptions\InvalidCsrfTokenException;
7
use WPEmerge\Facades\Csrf as CsrfService;
8
use WPEmerge\Middleware\MiddlewareInterface;
9
10
/**
11
 * Store current request data and clear old request data
12
 */
13
class CsrfMiddleware implements MiddlewareInterface {
14
	/**
15
	 * {@inheritDoc}
16
	 */
17
	public function handle( $request, Closure $next ) {
18
		if ( ! $request->isReadVerb() ) {
19
			$token = CsrfService::getTokenFromRequest( $request );
0 ignored issues
show
Bug introduced by
The method getTokenFromRequest() does not exist on WPEmerge\Facades\Csrf. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
			/** @scrutinizer ignore-call */ 
20
   $token = CsrfService::getTokenFromRequest( $request );
Loading history...
20
			if ( ! CsrfService::isValidToken( $token ) ) {
0 ignored issues
show
Bug introduced by
The method isValidToken() does not exist on WPEmerge\Facades\Csrf. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
			if ( ! CsrfService::/** @scrutinizer ignore-call */ isValidToken( $token ) ) {
Loading history...
21
				throw new InvalidCsrfTokenException();
22
			}
23
		}
24
25
		CsrfService::generateToken();
0 ignored issues
show
Bug introduced by
The method generateToken() does not exist on WPEmerge\Facades\Csrf. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
		CsrfService::/** @scrutinizer ignore-call */ 
26
               generateToken();
Loading history...
26
27
		return $next( $request );
28
	}
29
}
30