55use Exception ;
66use Madmatt \EncryptAtRest \Traits \EncryptedFieldGetValueTrait ;
77use SilverStripe \Core \Injector \Injector ;
8+ use SilverStripe \Model \ModelData ;
89use SilverStripe \ORM \DB ;
910use SilverStripe \ORM \FieldType \DBEnum ;
10- use SilverStripe \ORM \ArrayLib ;
11+ use SilverStripe \Core \ArrayLib ;
1112use Madmatt \EncryptAtRest \AtRestCryptoService ;
1213
1314/**
@@ -32,7 +33,7 @@ public function __construct($name = null, $enum = null, $default = 0, $options =
3233 $ this ->service = Injector::inst ()->get (AtRestCryptoService::class);
3334 }
3435
35- public function setValue ($ value , $ record = null , $ markChanged = true )
36+ public function setValue (mixed $ value , null | array | ModelData $ record = null , bool $ markChanged = true ): static
3637 {
3738 if (is_array ($ record ) && array_key_exists ($ this ->name , $ record ) && $ value === null ) {
3839 $ this ->value = $ record [$ this ->name ];
@@ -42,6 +43,8 @@ public function setValue($value, $record = null, $markChanged = true)
4243 } else {
4344 $ this ->value = $ value ;
4445 }
46+
47+ return $ this ;
4548 }
4649
4750 public function getDecryptedValue (string $ value = '' )
@@ -58,7 +61,7 @@ public function getDecryptedValue(string $value = '')
5861 return $ value ;
5962 }
6063
61- public function requireField ()
64+ public function requireField (): void
6265 {
6366 $ values = array (
6467 'type ' => 'text ' ,
@@ -72,7 +75,7 @@ public function requireField()
7275 DB ::require_field ($ this ->tableName , $ this ->name , $ values );
7376 }
7477
75- public function prepValueForDB ($ value )
78+ public function prepValueForDB (mixed $ value ): array | string | null
7679 {
7780 $ value = parent ::prepValueForDB ($ value );
7881 $ ciphertext = $ this ->service ->encrypt ($ value );
@@ -88,7 +91,8 @@ public function prepValueForDB($value)
8891 *
8992 * @return array
9093 */
91- public function enumValues ($ hasEmpty = true ) {
94+ public function enumValues (bool $ hasEmpty = false ): array
95+ {
9296 $ this ->enum = array ();
9397 return ($ hasEmpty )
9498 ? array_merge (array ('' => '' ), ArrayLib::valuekey ($ this ->enum ))
0 commit comments