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

nette / security / 20546871958

28 Dec 2025 01:17AM UTC coverage: 84.79% (-0.1%) from 84.896%
20546871958

push

github

dg
User: deprecated magic properties (BC break)

485 of 572 relevant lines covered (84.79%)

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

24
        /** @var mixed[] */
25
        private array $data;
26

27

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

35

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

45

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

54

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

64

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

73

74
        /**
75
         * Returns a user data.
76
         * @return mixed[]
77
         */
78
        public function getData(): array
79
        {
80
                return $this->data;
1✔
81
        }
82

83

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

92
                } else {
93
                        $this->data[$key] = $value;
×
94
                }
95
        }
96

97

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

107
                } else {
108
                        return $this->data[$key];
1✔
109
                }
110
        }
111

112

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

118

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

128

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