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

Validator::getMember()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Ubiquity\contents\validation\validators;
4
5
abstract class Validator implements ValidatorInterface{
6
	protected $modifiedMessage;
7
	protected $message;
8
	protected $member;
9
	protected $value;
10
	
11
	public function validate_($value,$member,$instance,$params,$severity='warning',$message=null){
1 ignored issue
show
Unused Code introduced by
The parameter $instance is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
12
		$this->value=$value;
13
		$this->setParams($params);
14
		if(!$this->validate($value)){
15
			$this->modifiedMessage=$message;
16
			return new ConstraintViolation($this->_getMessage(), $value, $member, get_class($this),$severity);
17
		}
18
		return true;
19
	}
20
	
21
	protected function setParams(array $params){
22
		foreach ($params as $member=>$value){
23
			$this->$member=$value;
24
		}
25
	}
26
	/**
27
	 * @return mixed
28
	 */
29
	public function getMember() {
30
		return $this->member;
31
	}
32
33
	/**
34
	 * @param mixed $member
35
	 */
36
	public function setMember($member) {
37
		$this->member = $member;
38
	}
39
	
40
	/**
41
	 * {@inheritDoc}
42
	 * @see \Ubiquity\contents\validation\validators\ValidatorInterface::getParameters()
43
	 */
44
	public function getParameters(): array {
45
		return [];
46
		
47
	}
48
	
49
	protected function mergeMessages(){
50
		if(!isset($this->modifiedMessage)){
51
			return $this->message;
52
		}else{
53
			return $this->modifiedMessage;
54
		}
55
	}
56
	
57
	protected function _getMessage(){
58
		$parameters=$this->getParameters();
59
		$message=$this->mergeMessages();
60 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...
61
			$message=str_replace("{".$param."}", $this->$param, $message);
62
		}
63
		return $message;
64
	}
65
66
}
67
68