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

nette / security / 22292290616

23 Feb 2026 03:52AM UTC coverage: 92.466%. Remained the same
22292290616

push

github

dg
added CLAUDE.md

540 of 584 relevant lines covered (92.47%)

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 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
use function in_array, is_float, is_numeric, iterator_to_array;
11

12

13
/**
14
 * @deprecated  use Nette\Security\SimpleIdentity
15
 * @property   string|int $id
16
 * @property   string[] $roles
17
 * @property   array<string, mixed> $data
18
 */
19
class Identity 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 = $data instanceof \Traversable
1✔
39
                        ? iterator_to_array($data)
×
40
                        : (array) $data;
1✔
41
        }
1✔
42

43

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

53

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

62

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

73

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

83

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

93

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

107

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

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

122

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