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

nette / security / 21943052204

12 Feb 2026 10:33AM UTC coverage: 91.798% (-0.6%) from 92.348%
21943052204

push

github

dg
User: deprecated magic properties (BC break)

526 of 573 relevant lines covered (91.8%)

0.92 hits per line

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

61.29
/src/Security/SimpleIdentity.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

13
/**
14
 * Default implementation of IIdentity.
15
 * @property   string|int $id
16
 * @property   string[] $roles
17
 * @property   array<string, mixed> $data
18
 */
19
class SimpleIdentity implements IIdentity
20
{
21
        private string|int $id;
22

23
        /** @var string[] */
24
        private array $roles;
25

26
        /** @var array<string, mixed> */
27
        private array $data;
28

29

30
        /**
31
         * @param  string|string[]|null  $roles
32
         * @param  ?iterable<string, mixed>  $data
33
         */
34
        public function __construct(string|int $id, string|array|null $roles = null, ?iterable $data = null)
1✔
35
        {
36
                $this->setId($id);
1✔
37
                $this->setRoles((array) $roles);
1✔
38
                $this->data = iterator_to_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
                match ($key) {
×
98
                        'id' => $this->setId($value),
×
99
                        'roles' => $this->setRoles($value),
×
100
                        'data' => $this->data = $value,
×
101
                        default => $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' . ucfirst($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

126

127
        public function __serialize(): array
128
        {
129
                return [
130
                        'id' => $this->id,
×
131
                        'roles' => $this->roles,
×
132
                        'data' => $this->data,
×
133
                ];
134
        }
135

136

137
        public function __unserialize(array $data): void
138
        {
139
                $this->id = $data['id'] ?? $data["\00Nette\\Security\\Identity\00id"] ?? 0;
×
140
                $this->roles = $data['roles'] ?? $data["\00Nette\\Security\\Identity\00roles"] ?? [];
×
141
                $this->data = $data['data'] ?? $data["\00Nette\\Security\\Identity\00data"] ?? [];
×
142
        }
143
}
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