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

nette / security / 21812889120

09 Feb 2026 04:55AM UTC coverage: 92.414% (-0.5%) from 92.919%
21812889120

push

github

dg
added CLAUDE.md

536 of 580 relevant lines covered (92.41%)

0.92 hits per line

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

74.07
/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   string[] $roles
19
 * @property   array<string, mixed> $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
        /**
33
         * @param  string|string[]|null  $roles
34
         * @param  ?iterable<string, mixed>  $data
35
         */
36
        public function __construct(string|int $id, string|array|null $roles = null, ?iterable $data = null)
1✔
37
        {
38
                $this->setId($id);
1✔
39
                $this->setRoles((array) $roles);
1✔
40
                $this->data = $data instanceof \Traversable
1✔
41
                        ? iterator_to_array($data)
×
42
                        : (array) $data;
1✔
43
        }
1✔
44

45

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

55

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

64

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

75

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

85

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

95

96
        /**
97
         * Sets user data value.
98
         */
99
        public function __set(string $key, mixed $value): void
100
        {
101
                match ($key) {
×
102
                        'id' => $this->setId($value),
×
103
                        'roles' => $this->setRoles($value),
×
104
                        'data' => $this->data = $value,
×
105
                        default => $this->data[$key] = $value,
×
106
                };
107
        }
108

109

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

119
                } else {
120
                        return $this->data[$key];
1✔
121
                }
122
        }
123

124

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