diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index 8cbf4f9575d..08f99de6bf2 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -12,6 +12,7 @@ use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Resettable; use SilverStripe\Core\Validation\ValidationException; +use SilverStripe\Core\Validation\ValidationInterface; use SilverStripe\Core\Validation\ValidationResult; use SilverStripe\Dev\Debug; use SilverStripe\Dev\Deprecation; @@ -111,7 +112,7 @@ * @property string $Created Date and time of DataObject creation. * @property string $ObsoleteClassName If ClassName no longer exists this will be set to the legacy value */ -class DataObject extends ModelData implements DataObjectInterface, i18nEntityProvider, Resettable +class DataObject extends ModelData implements DataObjectInterface, i18nEntityProvider, Resettable, ValidationInterface { /** * Human-readable singular name. @@ -1252,11 +1253,8 @@ public function forceChange() * * It is expected that you call validate() in your own application to test that an object is valid before * attempting a write, and respond appropriately if it isn't. - * - * @see {@link ValidationResult} - * @return ValidationResult */ - public function validate() + public function validate(): ValidationResult { $result = ValidationResult::create(); // Call DBField::validate() on every DBField diff --git a/src/Security/Group.php b/src/Security/Group.php index 4298c11dd89..6b5a59f1b6a 100755 --- a/src/Security/Group.php +++ b/src/Security/Group.php @@ -37,6 +37,7 @@ use SilverStripe\ORM\Hierarchy\Hierarchy; use SilverStripe\ORM\ManyManyList; use SilverStripe\ORM\UnsavedRelationList; +use SilverStripe\Core\Validation\ValidationResult; /** * A security group. @@ -504,7 +505,7 @@ public function setCode($val) $this->setField('Code', Convert::raw2url($val)); } - public function validate() + public function validate(): ValidationResult { $result = parent::validate(); diff --git a/src/Security/Member.php b/src/Security/Member.php index 7707df74ee2..11eaa0273d7 100644 --- a/src/Security/Member.php +++ b/src/Security/Member.php @@ -1618,7 +1618,7 @@ public function canDelete($member = null) /** * Validate this member object. */ - public function validate() + public function validate(): ValidationResult { // If validation is disabled, skip this step if (!DataObject::config()->uninherited('validation_enabled')) { diff --git a/src/Security/PermissionRoleCode.php b/src/Security/PermissionRoleCode.php index 8893382419e..2383e926838 100644 --- a/src/Security/PermissionRoleCode.php +++ b/src/Security/PermissionRoleCode.php @@ -4,6 +4,7 @@ use SilverStripe\ORM\DataObject; use SilverStripe\Security\PermissionRole; +use SilverStripe\Core\Validation\ValidationResult; /** * A PermissionRoleCode represents a single permission code assigned to a {@link PermissionRole}. @@ -30,7 +31,7 @@ class PermissionRoleCode extends DataObject "Code" => true, ]; - public function validate() + public function validate(): ValidationResult { $result = parent::validate(); diff --git a/tests/php/ORM/DataObjectTest/ValidatedObject.php b/tests/php/ORM/DataObjectTest/ValidatedObject.php index 0912f8e7615..00b57b25fc6 100644 --- a/tests/php/ORM/DataObjectTest/ValidatedObject.php +++ b/tests/php/ORM/DataObjectTest/ValidatedObject.php @@ -14,7 +14,7 @@ class ValidatedObject extends DataObject implements TestOnly 'Name' => 'Varchar(50)' ]; - public function validate() + public function validate(): ValidationResult { $result = ValidationResult::create(); if (empty($this->Name)) {