Completed
Push — master ( f8bd36...f2dc96 )
by Jean-Christophe
01:33
created

ValidatorMultiple::mergeMessages()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 4
nc 3
nop 0
1
<?php
2
3
namespace Ubiquity\contents\validation\validators\multiples;
4
5
use Ubiquity\contents\validation\validators\Validator;
6
7
abstract class ValidatorMultiple extends Validator{
8
9
	protected $violation;
10
	
11
	protected function mergeMessages(){
12
		if(!isset($this->modifiedMessage)){
13
			return $this->message;
14
		}else{
15
			if(is_array($this->modifiedMessage) && is_array($this->message)){
16
				return array_merge($this->message,$this->modifiedMessage);
17
			}else{
18
				return $this->modifiedMessage;
19
			}
20
		}
21
	}
22
	
23
	protected function _getMessage(){
24
		$parameters=$this->getParameters();
25
		$message=$this->mergeMessages();
26
		if(isset($this->violation) && is_array($message)){
27
			$message=$this->_getMessageViolation($message);
28
		}
29 View Code Duplication
		foreach ($parameters as $param){
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
			$message=str_replace("{".$param."}", $this->$param, $message);
31
		}
32
		return $message;
33
	}
34
	
35
	protected function _getMessageViolation($messages){
36
		if(isset($messages[$this->violation])){
37
			return $messages[$this->violation];
38
		}
39
		return reset($messages);
40
	}
41
42
43
}
44
45