Passed
Pull Request — master (#2068)
by
unknown
118:29 queued 53:27
created

ValidationErrorLogger::containsLegacyFields()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare( strict_types=1 );
4
5
namespace WMDE\Fundraising\Frontend\Infrastructure\Validation;
6
7
use Psr\Log\LoggerInterface;
8
use WMDE\FunValidators\ConstraintViolation;
9
10
class ValidationErrorLogger {
11
12
	private LoggerInterface $logger;
13
14
	public function __construct( LoggerInterface $logger ) {
15
		$this->logger = $logger;
16
	}
17
18
	public function logViolations( string $message, array $fields, array $validationErrors ): void {
19
		if ( $this->hasMoreErrorsThan( 4, $fields ) ) {
20
			return;
21
		}
22
23
		$this->logger->warning( $message, $validationErrors );
24
	}
25
26
	private function hasMoreErrorsThan( int $number, array $violations ): bool {
27
		return count( $violations ) > $number;
28
	}
29
}
30