| Conditions | 7 |
| Paths | 2 |
| Total Lines | 22 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | public function validate(ValidationResult $validationResult) |
||
| 6 | { |
||
| 7 | $requiredFields = Config::inst()->get($this->owner->class, 'required_fields', Config::INHERITED); |
||
| 8 | if ($requiredFields) { |
||
| 9 | foreach ($requiredFields as $name) { |
||
| 10 | $error = false; |
||
| 11 | if ($this->owner->hasMethod($name)) { |
||
| 12 | $object = $this->owner->$name(); |
||
| 13 | if (! $object->exists()) { |
||
| 14 | $error = true; |
||
| 15 | } |
||
| 16 | } elseif (! $this->owner->$name) { |
||
| 17 | $error = true; |
||
| 18 | } |
||
| 19 | if ($error) { |
||
| 20 | $label = $this->owner->fieldLabel($name); |
||
| 21 | $validationResult->error(sprintf(_t('Form.FIELDISREQUIRED', '%s is required'), "\"$label\""), $name); |
||
| 22 | } |
||
| 23 | } |
||
| 24 | } |
||
| 25 | return $validationResult; |
||
| 26 | } |
||
| 27 | } |
||
| 28 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.