| Conditions | 7 |
| Paths | 4 |
| Total Lines | 34 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 3 | Features | 0 |
| 1 | <?php |
||
| 27 | public function validate($value, Constraint $constraint) |
||
| 28 | { |
||
| 29 | if (!$value) { |
||
| 30 | return; |
||
| 31 | } |
||
| 32 | |||
| 33 | if (!$value instanceof Contact) { |
||
| 34 | throw new \InvalidArgumentException(sprintf( |
||
| 35 | 'Validator expects $value to be instance of "%s"', |
||
| 36 | 'OroCRM\Bundle\ContactBundle\Entity\Contact' |
||
| 37 | )); |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($value->getFirstName() || |
||
| 41 | $value->getLastName() || |
||
| 42 | $value->getEmails()->count() > 0 || |
||
| 43 | $value->getPhones()->count() > 0 |
||
| 44 | ) { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | $this->context->addViolation( |
||
| 49 | $constraint->message, |
||
| 50 | [ |
||
| 51 | '%fields%' => sprintf( |
||
| 52 | '%s, %s, %s or %s', |
||
| 53 | $this->translator->trans('orocrm.contact.first_name.label'), |
||
| 54 | $this->translator->trans('orocrm.contact.last_name.label'), |
||
| 55 | $this->translator->trans('orocrm.contact.emails.label'), |
||
| 56 | $this->translator->trans('orocrm.contact.phones.label') |
||
| 57 | ), |
||
| 58 | ] |
||
| 59 | ); |
||
| 60 | } |
||
| 61 | } |
||
| 62 |