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

FastyBird / simple-auth / 10030816951

21 Jul 2024 07:23PM UTC coverage: 69.279% (+0.3%) from 68.983%
10030816951

push

github

web-flow
Move enforcer instance into factory (#12)

46 of 50 new or added lines in 4 files covered. (92.0%)

1 existing line in 1 file now uncovered.

548 of 791 relevant lines covered (69.28%)

6.03 hits per line

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

66.67
/src/Security/EnforcerFactory.php
1
<?php declare(strict_types = 1);
2

3
/**
4
 * EnforcerFactory.php
5
 *
6
 * @license        More in LICENSE.md
7
 * @copyright      https://www.fastybird.com
8
 * @author         Adam Kadlec <adam.kadlec@fastybird.com>
9
 * @package        FastyBird:SimpleAuth!
10
 * @subpackage     Security
11
 * @since          0.1.0
12
 *
13
 * @date           21.07.24
14
 */
15

16
namespace FastyBird\SimpleAuth\Security;
17

18
use Casbin;
19
use FastyBird\SimpleAuth\Exceptions;
20

21
/**
22
 * Class security annotation checker
23
 *
24
 * @package        FastyBird:SimpleAuth!
25
 * @subpackage     Security
26
 *
27
 * @author         Adam Kadlec <adam.kadlec@fastybird.com>
28
 */
29
class EnforcerFactory
30
{
31

32
        private Casbin\CachedEnforcer|null $enforcer = null;
33

34
        public function __construct(
35
                private readonly string $modelFile,
36
                private readonly Casbin\Persist\Adapter $adapter,
37
        )
38
        {
39
        }
21✔
40

41
        /**
42
         * @throws Exceptions\InvalidState
43
         */
44
        public function getEnforcer(): Casbin\Enforcer
45
        {
46
                if ($this->enforcer === null) {
15✔
47
                        try {
48
                                $this->enforcer = new Casbin\CachedEnforcer($this->modelFile, $this->adapter);
15✔
NEW
49
                        } catch (Casbin\Exceptions\CasbinException $ex) {
×
NEW
50
                                throw new Exceptions\InvalidState('Failed to create an enforcer', $ex->getCode(), $ex);
×
51
                        }
52
                }
53

54
                return $this->enforcer;
15✔
55
        }
56

57
}
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

© 2025 Coveralls, Inc