• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

codeigniter4 / CodeIgniter4 / 28444412384

30 Jun 2026 12:30PM UTC coverage: 89.164% (-0.004%) from 89.168%
28444412384

Pull #10357

github

web-flow
Merge 568b2e800 into 7b7742fd8
Pull Request #10357: feat: add `encrypted` casts for model fields and entities

29 of 32 new or added lines in 3 files covered. (90.63%)

25072 of 28119 relevant lines covered (89.16%)

226.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/system/DataCaster/Cast/EncryptedCast.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\DataCaster\Cast;
15

16
use CodeIgniter\DataCaster\Exceptions\CastException;
17
use Config\Services;
18
use SensitiveParameter;
19

20
/**
21
 * Class EncryptedCast
22
 *
23
 * (PHP) [string --> encrypted string] --> (DB driver) --> (DB column) string
24
 *       [       <-- string          ] <-- (DB driver) <-- (DB column) encrypted string
25
 */
26
class EncryptedCast extends BaseCast
27
{
28
    public static function get(
29
        #[SensitiveParameter]
30
        mixed $value,
31
        array $params = [],
32
        ?object $helper = null,
33
    ): ?string {
34
        if ($value === null) {
6✔
NEW
35
            return null;
×
36
        }
37

38
        if (! is_string($value)) {
6✔
NEW
39
            throw CastException::forInvalidEncryptedValueType();
×
40
        }
41

42
        $decoded = base64_decode($value, true);
6✔
43

44
        if ($decoded === false) {
6✔
45
            throw CastException::forInvalidEncryptedPayload();
1✔
46
        }
47

48
        return Services::encrypter()->decrypt($decoded);
5✔
49
    }
50

51
    public static function set(
52
        #[SensitiveParameter]
53
        mixed $value,
54
        array $params = [],
55
        ?object $helper = null,
56
    ): ?string {
57
        if ($value === null) {
4✔
NEW
58
            return null;
×
59
        }
60

61
        if (! is_string($value)) {
4✔
62
            throw CastException::forInvalidEncryptedValueType();
1✔
63
        }
64

65
        return base64_encode(Services::encrypter()->encrypt($value));
3✔
66
    }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc