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

nette / security / 22292327079

23 Feb 2026 03:53AM UTC coverage: 91.812% (-0.01%) from 91.826%
22292327079

push

github

dg
User: deprecated magic properties (BC break)

527 of 574 relevant lines covered (91.81%)

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 declare(strict_types=1);
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
namespace Nette\Security;
9

10

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

21
        /** @var string[] */
22
        private array $roles;
23

24
        /** @var array<string, mixed> */
25
        private array $data;
26

27

28
        /**
29
         * @param  string|string[]|null  $roles
30
         * @param  ?iterable<string, mixed>  $data
31
         */
32
        public function __construct(string|int $id, string|array|null $roles = null, ?iterable $data = null)
1✔
33
        {
34
                $this->setId($id);
1✔
35
                $this->setRoles((array) $roles);
1✔
36
                $this->data = iterator_to_array($data ?? []);
1✔
37
        }
1✔
38

39

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

49

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

58

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

69

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

79

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

89

90
        /**
91
         * Sets user data value.
92
         */
93
        public function __set(string $key, mixed $value): void
94
        {
95
                match ($key) {
×
96
                        'id' => $this->setId($value),
×
97
                        'roles' => $this->setRoles($value),
×
98
                        'data' => $this->data = $value,
×
99
                        default => $this->data[$key] = $value,
×
100
                };
101
        }
102

103

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

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

118

119
        public function __isset(string $key): bool
120
        {
121
                return isset($this->data[$key]) || in_array($key, ['id', 'roles', 'data'], strict: true);
×
122
        }
123

124

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

134

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