Passed
Push — master ( 2c87cc...10e3e7 )
by Borislav
06:41
created

NotSpam::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace App\Validator\Constraints;
2
3
use Symfony\Component\Validator\Constraint;
4
5
/**
6
 * @Annotation
7
 */
8
class NotSpam extends Constraint {
9
	public $message = 'notspam';
10
	public $urlLimit = 2;
11
	public $stopWords = [];
12
	public $stopWordsFile = __DIR__.'/../../config/spam_phrases.ini';
13
14
	public function __construct($options = null, string $stopWordsFile = null) {
15
		parent::__construct($options);
16
		$this->stopWordsFile = $stopWordsFile ?? $this->stopWordsFile;
17
		$this->stopWords = $this->fetchStopWords();
18
	}
19
20
	private function fetchStopWords() {
21
		$lines = file($this->stopWordsFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
0 ignored issues
show
Bug introduced by
It seems like $this->stopWordsFile can also be of type mixed; however, parameter $filename of file() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

21
		$lines = file(/** @scrutinizer ignore-type */ $this->stopWordsFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
Loading history...
22
		return array_filter($lines, function(string $line) {
23
			return $line[0] !== '#';
24
		});
25
	}
26
}
27