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

ValidatorMultiple   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 37
Duplicated Lines 8.11 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 3
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mergeMessages() 0 11 4
A _getMessage() 3 11 4
A _getMessageViolation() 0 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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