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

nette / security / 20848288786

09 Jan 2026 10:01AM UTC coverage: 92.919%. Remained the same
20848288786

push

github

dg
added CLAUDE.md

538 of 579 relevant lines covered (92.92%)

0.93 hits per line

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

80.0
/src/Security/Identity.php
1
<?php
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Nette\Security;
11

12
use function in_array, is_float, is_numeric, iterator_to_array;
13

14

15
/**
16
 * @deprecated  use Nette\Security\SimpleIdentity
17
 * @property   string|int $id
18
 * @property   array $roles
19
 * @property   array $data
20
 */
21
class Identity implements IIdentity
22
{
23
        private string|int $id;
24

25
        /** @var string[] */
26
        private array $roles;
27

28
        /** @var array<string, mixed> */
29
        private array $data;
30

31

32
        public function __construct(string|int $id, $roles = null, ?iterable $data = null)
1✔
33
        {
34
                $this->setId($id);
1✔
35
                $this->setRoles((array) $roles);
1✔
36
                $this->data = $data instanceof \Traversable
1✔
37
                        ? iterator_to_array($data)
×
38
                        : (array) $data;
1✔
39
        }
1✔
40

41

42
        /**
43
         * Sets the ID of user.
44
         */
45
        public function setId(string|int $id): static
1✔
46
        {
47
                $this->id = is_numeric($id) && !is_float($tmp = $id * 1) ? $tmp : $id;
1✔
48
                return $this;
1✔
49
        }
50

51

52
        /**
53
         * Returns the ID of user.
54
         */
55
        public function getId(): string|int
56
        {
57
                return $this->id;
1✔
58
        }
59

60

61
        /**
62
         * Sets a list of roles that the user is a member of.
63
         * @param  string[]  $roles
64
         */
65
        public function setRoles(array $roles): static
1✔
66
        {
67
                $this->roles = $roles;
1✔
68
                return $this;
1✔
69
        }
70

71

72
        /**
73
         * Returns a list of roles that the user is a member of.
74
         * @return string[]
75
         */
76
        public function getRoles(): array
77
        {
78
                return $this->roles;
1✔
79
        }
80

81

82
        /**
83
         * Returns a user data.
84
         * @return array<string, mixed>
85
         */
86
        public function getData(): array
87
        {
88
                return $this->data;
1✔
89
        }
90

91

92
        /**
93
         * Sets user data value.
94
         */
95
        public function __set(string $key, mixed $value): void
96
        {
97
                if (in_array($key, ['id', 'roles', 'data'], strict: true)) {
×
98
                        $this->{"set$key"}($value);
×
99

100
                } else {
101
                        $this->data[$key] = $value;
×
102
                }
103
        }
104

105

106
        /**
107
         * Returns user data value.
108
         */
109
        public function &__get(string $key): mixed
1✔
110
        {
111
                if (in_array($key, ['id', 'roles', 'data'], strict: true)) {
1✔
112
                        $res = $this->{"get$key"}();
1✔
113
                        return $res;
1✔
114

115
                } else {
116
                        return $this->data[$key];
1✔
117
                }
118
        }
119

120

121
        public function __isset(string $key): bool
122
        {
123
                return isset($this->data[$key]) || in_array($key, ['id', 'roles', 'data'], strict: true);
×
124
        }
125
}
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