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

php-casbin / php-casbin / 15422853167

03 Jun 2025 04:34PM UTC coverage: 94.307% (-0.2%) from 94.485%
15422853167

push

github

leeqvip
refactor: Upgrade phpstan to level 8

52 of 63 new or added lines in 8 files covered. (82.54%)

2 existing lines in 1 file now uncovered.

1938 of 2055 relevant lines covered (94.31%)

231.19 hits per line

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

86.36
/src/Persist/AdapterHelper.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Casbin\Persist;
6

7
use Casbin\Model\Assertion;
8
use Casbin\Model\Model;
9
use Casbin\Model\Policy;
10

11
/**
12
 * Trait AdapterHelper.
13
 *
14
 * @author techlee@qq.com
15
 */
16
trait AdapterHelper
17
{
18
    /**
19
     * Loads a text line as a policy rule to model.
20
     *
21
     * @param string $line
22
     * @param Model $model
23
     */
24
    public function loadPolicyLine(string $line, Model $model): void
25
    {
26
        if ('' == $line) {
1,140✔
27
            return;
820✔
28
        }
29

30
        if ('#' == substr($line, 0, 1)) {
1,140✔
31
            return;
×
32
        }
33

34
        $tokens = array_map(
1,140✔
35
            fn($item) => $item ? trim($item) : '',
1,140✔
36
            str_getcsv($line, ",", '"', ""),
1,140✔
37
        );
1,140✔
38

39
        $this->loadPolicyArray($tokens, $model);
1,140✔
40
    }
41

42
    /**
43
     * Loads a policy rule to model.
44
     *
45
     * @param array<string> $rule
46
     * @param Model $model
47
     */
48
    public function loadPolicyArray(array $rule, Model $model): void
49
    {
50
        $key = $rule[0];
1,140✔
51
        $sec = $key[0];
1,140✔
52

53
        if (!isset($model[$sec][$key])) {
1,140✔
54
            return;
×
55
        }
56

57
        $assertions = $model[$sec];
1,140✔
58
        $assertion = $assertions[$key];
1,140✔
59
        if (!($assertion instanceof Assertion)) {
1,140✔
60
            return;
×
61
        }
62

63
        $rule = array_slice($rule, 1);
1,140✔
64
        $assertion->policy[] = $rule;
1,140✔
65
        $assertion->policyMap[implode(Policy::DEFAULT_SEP, $rule)] = count($assertion->policy) - 1;
1,140✔
66

67
        $assertions[$key] = $assertion;
1,140✔
68
        $model[$sec] = $assertions;
1,140✔
69
    }
70
}
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