Test Failed
Push — master ( 2def23...999d23 )
by Paul
04:14
created

Blacklist::check()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 11
nc 5
nop 1
dl 0
loc 16
ccs 0
cts 12
cp 0
crap 42
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules;
4
5
use GeminiLabs\SiteReviews\Database\OptionManager;
6
7
class Blacklist
8
{
9
	/**
10
	 * @return bool
11
	 */
12
	public function isBlacklisted( array $review )
13
	{
14
		$target = implode( "\n", array_filter([
15
			$review['name'],
16
			$review['content'],
17
			$review['email'],
18
			$review['ip_address'],
19
			$review['title'],
20
		]));
21
		return (bool)apply_filters( 'site-reviews/blacklist/is-blacklisted',
22
			$this->check( $target ),
23
			$review
24
		);
25
	}
26
27
	/**
28
	 * @param string $target
29
	 * @return bool
30
	 */
31
	protected function check( $target )
32
	{
33
		$blacklist = trim( glsr( OptionManager::class )->get( 'settings.submissions.blacklist.entries' ));
34
		if( empty( $blacklist )) {
35
			return false;
36
		}
37
		$lines = explode( "\n", $blacklist );
38
		foreach( (array)$lines as $line ) {
39
			$line = trim( $line );
40
			if( empty( $line ) || 256 < strlen( $line ))continue;
41
			$pattern = sprintf( '#%s#i', preg_quote( $line, '#' ));
42
			if( preg_match( $pattern, $target )) {
43
				return true;
44
			}
45
		}
46
		return false;
47
	}
48
}
49