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

nette / security / 20472392440

23 Dec 2025 09:51PM UTC coverage: 84.896% (+0.07%) from 84.828%
20472392440

push

github

dg
User: deprecated magic properties (BC break)

489 of 576 relevant lines covered (84.9%)

0.85 hits per line

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

65.52
/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   array $roles
17
 * @property   array $data
18
 */
19
class SimpleIdentity implements IIdentity
20
{
21
        private string|int $id;
22
        private array $roles;
23
        private array $data;
24

25

26
        public function __construct($id, $roles = null, ?iterable $data = null)
1✔
27
        {
28
                $this->setId($id);
1✔
29
                $this->setRoles((array) $roles);
1✔
30
                $this->data = iterator_to_array($data ?? []);
1✔
31
        }
1✔
32

33

34
        /**
35
         * Sets the ID of user.
36
         */
37
        public function setId(string|int $id): static
1✔
38
        {
39
                $this->id = is_numeric($id) && !is_float($tmp = $id * 1) ? $tmp : $id;
1✔
40
                return $this;
1✔
41
        }
42

43

44
        /**
45
         * Returns the ID of user.
46
         */
47
        public function getId(): string|int
48
        {
49
                return $this->id;
1✔
50
        }
51

52

53
        /**
54
         * Sets a list of roles that the user is a member of.
55
         */
56
        public function setRoles(array $roles): static
1✔
57
        {
58
                $this->roles = $roles;
1✔
59
                return $this;
1✔
60
        }
61

62

63
        /**
64
         * Returns a list of roles that the user is a member of.
65
         */
66
        public function getRoles(): array
67
        {
68
                return $this->roles;
1✔
69
        }
70

71

72
        /**
73
         * Returns a user data.
74
         */
75
        public function getData(): array
76
        {
77
                return $this->data;
1✔
78
        }
79

80

81
        /**
82
         * Sets user data value.
83
         */
84
        public function __set(string $key, $value): void
85
        {
86
                if (in_array($key, ['id', 'roles', 'data'], strict: true)) {
×
87
                        $this->{"set$key"}($value);
×
88

89
                } else {
90
                        $this->data[$key] = $value;
×
91
                }
92
        }
93

94

95
        /**
96
         * Returns user data value.
97
         */
98
        public function &__get(string $key): mixed
1✔
99
        {
100
                if (in_array($key, ['id', 'roles', 'data'], strict: true)) {
1✔
101
                        $res = $this->{"get$key"}();
1✔
102
                        return $res;
1✔
103

104
                } else {
105
                        return $this->data[$key];
1✔
106
                }
107
        }
108

109

110
        public function __isset(string $key): bool
111
        {
112
                return isset($this->data[$key]) || in_array($key, ['id', 'roles', 'data'], strict: true);
×
113
        }
114

115

116
        public function __serialize(): array
117
        {
118
                return [
119
                        'id' => $this->id,
×
120
                        'roles' => $this->roles,
×
121
                        'data' => $this->data,
×
122
                ];
123
        }
124

125

126
        public function __unserialize(array $data): void
127
        {
128
                $this->id = $data['id'] ?? $data["\00Nette\\Security\\Identity\00id"] ?? 0;
×
129
                $this->roles = $data['roles'] ?? $data["\00Nette\\Security\\Identity\00roles"] ?? [];
×
130
                $this->data = $data['data'] ?? $data["\00Nette\\Security\\Identity\00data"] ?? [];
×
131
        }
132
}
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