Passed
Push — main ( 20d6d7...2f23ef )
by Axel
04:07
created

ExtensionMenu::getBundleName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\UsersBundle\Menu;
15
16
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
17
use Symfony\Bundle\SecurityBundle\Security;
18
use Zikula\CoreBundle\Api\ApiInterface\LocaleApiInterface;
19
use Zikula\ThemeBundle\ExtensionMenu\AbstractExtensionMenu;
20
use Zikula\UsersBundle\Entity\Group;
21
use Zikula\UsersBundle\Entity\User;
22
use Zikula\UsersBundle\UsersConstant;
23
use function Symfony\Component\Translation\t;
24
25
class ExtensionMenu extends AbstractExtensionMenu
26
{
27
    public function __construct(
28
        private readonly Security $security,
29
        private readonly LocaleApiInterface $localeApi,
30
        private readonly bool $registrationEnabled,
31
        private readonly bool $allowSelfDeletion
32
    ) {
33
    }
34
35
    protected function getAdmin(): iterable
36
    {
37
        yield MenuItem::linkToCrud(t('Users'), 'fas fa-user', User::class);
38
        yield MenuItem::linkToCrud(t('Groups'), 'fas fa-people-group', Group::class);
39
    }
40
41
    protected function getUser(): iterable
42
    {
43
        if (null === $this->security->getUser()) {
44
            yield MenuItem::linktoRoute('Login', 'fas fa-sign-in-alt', 'nucleos_user_security_login');
45
            if ($this->registrationEnabled) {
46
                yield MenuItem::linktoRoute('New account', 'fas fa-plus', 'zikulausersbundle_registration_register');
47
            }
48
        }
49
    }
50
51
    protected function getAccount(): iterable
52
    {
53
        $loggedIn = null !== $this->security->getUser();
54
        if (!$loggedIn) {
55
            yield MenuItem::linktoRoute('I would like to login', 'fas fa-sign-in-alt', 'nucleos_user_security_login');
56
            if ($this->registrationEnabled) {
57
                yield MenuItem::linktoRoute('I would like to create a new account', 'fas fa-plus', 'zikulausersbundle_registration_register');
58
                // TODO maybe move to ProfileBundle if we keep one
59
                // | Registration | nucleos_profile_registration_check_email | /registration/check-email |
60
                // | Registration | nucleos_profile_registration_confirmed | /registration/confirmed |
61
                // | Registration | nucleos_profile_registration_register | /registration/ |
62
            }
63
        }
64
        yield MenuItem::linktoRoute('Reset password', 'fas fa-refresh', 'nucleos_user_resetting_request');
65
        if ($loggedIn) {
66
            yield MenuItem::linktoRoute('Change password', 'fas fa-lock', 'nucleos_user_change_password');
67
68
            // TODO maybe move to ProfileBundle if we keep one
69
            yield MenuItem::linktoRoute('My profile', 'fas fa-user', 'nucleos_profile_profile_show');
70
            yield MenuItem::linktoRoute('Edit profile', 'fas fa-user-pen', 'nucleos_profile_profile_edit');
71
72
            if ($this->allowSelfDeletion) {
73
                if (UsersConstant::USER_ID_ADMIN !== $this->security->getUser()->getId()) {
0 ignored issues
show
Bug introduced by
The method getId() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as Zikula\UsersBundle\Entity\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
                if (UsersConstant::USER_ID_ADMIN !== $this->security->getUser()->/** @scrutinizer ignore-call */ getId()) {
Loading history...
74
                    yield MenuItem::linktoRoute('Delete my account', 'fas fa-trash-alt', 'nucleos_user_delete_account')
75
                        ->setCssClass('text-danger')
76
                    ;
77
                }
78
            }
79
            // TODO remove this test entry again
80
            yield MenuItem::linktoRoute('Delete my account', 'fas fa-trash-alt', 'nucleos_user_delete_account')
81
                ->setCssClass('text-danger')
82
            ;
83
        }
84
    }
85
86
    public function getBundleName(): string
87
    {
88
        return 'ZikulaUsersBundle';
89
    }
90
}
91