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

daycry / auth / 13307494298

07 Feb 2025 02:07PM UTC coverage: 59.266% (-0.04%) from 59.304%
13307494298

push

github

Jordi de la Mano
Feature: validation rules with arrays

0 of 3 new or added lines in 1 file covered. (0.0%)

1858 of 3135 relevant lines covered (59.27%)

22.19 hits per line

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

0.0
/src/Traits/Validation.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Auth.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
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 Daycry\Auth\Traits;
15

16
use CodeIgniter\Validation\ValidationInterface;
17
use Config\Services;
18
use Config\Validation as ValidationConfig;
19
use Daycry\Auth\Exceptions\ValidationException;
20

21
trait Validation
22
{
23
    /**
24
     * Once validation has been run, will hold the Validation instance.
25
     *
26
     * @var ValidationInterface|null
27
     */
28
    protected $validator;
29

30
    protected function dataValidation(array|string $rules, array|object $data, ?ValidationConfig $config = null, bool $getShared = true, ?string $dbGroup = null): array
31
    {
32
        $config ??= config('Validation');
×
33

34
        $this->validator = Services::validation($config, $getShared);
×
35

36
        return $this->runValidate($rules, $data, $dbGroup);
×
37
    }
38

39
    protected function requestValidation(array|string $rules, ?ValidationConfig $config = null, bool $getShared = true, ?string $dbGroup = null): array
40
    {
41
        $config ??= config('Validation');
×
42

43
        $this->validator = Services::validation($config, $getShared)->withRequest(Services::request());
×
44

45
        return $this->runValidate($rules, null, $dbGroup);
×
46
    }
47

48
    private function runValidate(array|string $rules, array|object|null $data = null, ?string $dbGroup = null)
49
    {
50
        if ($data !== null) {
×
51
            if (is_object($data)) {
×
52
                $data = get_object_vars($data);
×
53
            }
54
        }
55

NEW
56
        if (is_string($rules)) {
×
NEW
57
            $this->validator->setRuleGroup($rules);
×
58
        } else {
NEW
59
            $this->validator->setRules($rules);
×
60
        }
61

62
        if (! $this->validator->run($data, null, $dbGroup)) {
×
63
            throw ValidationException::validationData();
×
64
        }
65

66
        return $this->validator->getValidated();
×
67
    }
68
}
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