potievdev /
slim-rbac
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Potievdev\SlimRbac\Models\Entity; |
||
| 4 | |||
| 5 | use DateTime; |
||
| 6 | use Doctrine\ORM\Mapping as ORM; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * UserRole |
||
| 10 | * |
||
| 11 | * @ORM\Table( |
||
| 12 | * name="user_role", |
||
| 13 | * uniqueConstraints={@ORM\UniqueConstraint(name="idx_user_role_unique", columns={"user_id", "role_id"})}, |
||
| 14 | * indexes={@ORM\Index(name="fk_user_role_role", columns={"role_id"})} |
||
| 15 | * ) |
||
| 16 | * @ORM\Entity(repositoryClass="Potievdev\SlimRbac\Models\Repository\UserRoleRepository") |
||
| 17 | * @ORM\HasLifecycleCallbacks |
||
| 18 | */ |
||
| 19 | class UserRole |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var integer |
||
| 23 | * |
||
| 24 | * @ORM\Column(name="id", type="integer", nullable=false) |
||
| 25 | * @ORM\Id |
||
| 26 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
| 27 | */ |
||
| 28 | private $id; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var integer |
||
| 32 | * |
||
| 33 | * @ORM\Column(name="user_id", type="string", nullable=false) |
||
| 34 | */ |
||
| 35 | private $userId; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var integer |
||
| 39 | * |
||
| 40 | * @ORM\Column(name="role_id", type="integer", nullable=false) |
||
| 41 | */ |
||
| 42 | private $roleId; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var DateTime |
||
| 46 | * |
||
| 47 | * @ORM\Column(name="created_at", type="datetime", nullable=false) |
||
| 48 | */ |
||
| 49 | private $createdAt; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var Role |
||
| 53 | * |
||
| 54 | * @ORM\ManyToOne(targetEntity="Potievdev\SlimRbac\Models\Entity\Role") |
||
| 55 | * @ORM\JoinColumns({ |
||
| 56 | * @ORM\JoinColumn(name="role_id", referencedColumnName="id") |
||
| 57 | * }) |
||
| 58 | */ |
||
| 59 | private $role; |
||
| 60 | |||
| 61 | public function getId(): int |
||
| 62 | { |
||
| 63 | return $this->id; |
||
| 64 | } |
||
| 65 | |||
| 66 | public function setId(int $id) |
||
| 67 | { |
||
| 68 | $this->id = $id; |
||
| 69 | } |
||
| 70 | |||
| 71 | public function getUserId(): string |
||
| 72 | { |
||
| 73 | return $this->userId; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function setUserId(string $userId) |
||
| 77 | { |
||
| 78 | $this->userId = $userId; |
||
|
0 ignored issues
–
show
|
|||
| 79 | } |
||
| 80 | |||
| 81 | public function getRoleId(): int |
||
| 82 | { |
||
| 83 | return $this->roleId; |
||
| 84 | } |
||
| 85 | |||
| 86 | public function setRoleId(int $roleId) |
||
| 87 | { |
||
| 88 | $this->roleId = $roleId; |
||
| 89 | } |
||
| 90 | |||
| 91 | public function getCreatedAt(): DateTime |
||
| 92 | { |
||
| 93 | return $this->createdAt; |
||
| 94 | } |
||
| 95 | |||
| 96 | public function setCreatedAt(DateTime $createdAt) |
||
| 97 | { |
||
| 98 | $this->createdAt = $createdAt; |
||
| 99 | } |
||
| 100 | |||
| 101 | public function getRole(): Role |
||
| 102 | { |
||
| 103 | return $this->role; |
||
| 104 | } |
||
| 105 | |||
| 106 | public function setRole(Role $role) |
||
| 107 | { |
||
| 108 | $this->role = $role; |
||
| 109 | } |
||
| 110 | |||
| 111 | /** @ORM\PrePersist */ |
||
| 112 | public function prePersist() |
||
| 113 | { |
||
| 114 | $this->createdAt = new DateTime(); |
||
| 115 | } |
||
| 116 | } |
||
| 117 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.