ValidatorTrait::preSave()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
namespace Frameworkless;
3
4
use Symfony\Component\Validator\Validator\RecursiveValidator;
5
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
6
use Symfony\Component\Validator\ConstraintValidatorFactory;
7
use Symfony\Component\Translation\IdentityTranslator;
8
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
9
use Symfony\Component\Validator\Context\ExecutionContextFactory;
10
use Frameworkless\Exceptions\ValidationException;
11
12
/**
13
 * Description of ValidatorTrait
14
 *
15
 * @author Dmitriy
16
 */
17
trait ValidatorTrait{
18
19
    /**
20
     * 
21
     * @var Symfony\Component\Validator\Validator\RecursiveValidator
22
     */
23
    protected $validator;
24
25
    function __construct(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
	$this->validator = new RecursiveValidator(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Symfony\Component\V...aintValidatorFactory()) of type object<Symfony\Component...tor\RecursiveValidator> is incompatible with the declared type object<Frameworkless\Sym...tor\RecursiveValidator> of property $validator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
		new ExecutionContextFactory(new IdentityTranslator()), new LazyLoadingMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory()
28
	);
29
    }
30
31
    public function preSave(\Propel\Runtime\Connection\ConnectionInterface $con = null){
0 ignored issues
show
Unused Code introduced by
The parameter $con 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...
32
	if(!$result = $this->validate($this->validator)){
33
	    throw new ValidationException($this->getValidationFailures(), "Validation error");
34
	}
35
	return $result;
36
    }
37
38
    public abstract function validate(\Symfony\Component\Validator\Validator\ValidatorInterface $validator = NULL);
39
40
    public abstract function getValidationFailures();
41
}
42