Completed
Push — master ( ec2c00...c3f83b )
by Markus
05:40
created

SampleAppProductValidator::validate()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 16
nc 5
nop 0
dl 0
loc 26
rs 8.439
c 0
b 0
f 0
1
<?php
2
use Agavi\Validator\Validator;
3
4
class SampleAppProductValidator extends Validator
5
{
6
	public function validate()
7
	{
8
		if($this->hasMultipleArguments()) {
9
			$arguments = $this->getArguments();
10
			if(!isset($arguments['id']) || !isset($arguments['name'])) {
11
				throw new Exception('Expecting arguments "id" and "name"');
12
			}
13
			$id = $this->getData($arguments['id']);
14
			$name = $this->getData($arguments['name']);
15
			
16
			$product = $this->getContext()->getModel('ProductFinder')->retrieveByIdAndName($id, $name);
17
		} else {
18
			$id = $this->getData($this->getArgument());
19
			
20
			$product = $this->getContext()->getModel('ProductFinder')->retrieveById($id);
21
		}
22
		
23
		if(!$product) {
24
			$this->throwError();
25
			return false;
26
		}
27
		
28
		$this->export($product);
29
		
30
		return true;
31
	}
32
}
33
34
?>