Passed
Pull Request — master (#15)
by Jeff
08:02
created

AliasCrudController::configureFields()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 15
rs 9.5555
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the mailserver-admin package.
6
 * (c) Jeffrey Boehm <https://github.com/jeboehm/mailserver-admin>
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace App\Controller\Admin;
12
13
use App\Entity\Alias;
14
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
15
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
16
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
17
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
18
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
19
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
20
21
class AliasCrudController extends AbstractCrudController
22
{
23
    public static function getEntityFqcn(): string
24
    {
25
        return Alias::class;
26
    }
27
28
    public function configureCrud(Crud $crud): Crud
29
    {
30
        return $crud
31
            ->setEntityLabelInSingular('Alias')
32
            ->setEntityLabelInPlural('Alias')
33
            ->setSearchFields(['id', 'name', 'destination']);
34
    }
35
36
    public function configureFields(string $pageName): iterable
37
    {
38
        $domain = AssociationField::new('domain');
39
        $name = TextField::new('name');
40
        $destination = EmailField::new('destination');
41
        $id = IdField::new('id', 'ID');
42
43
        if (Crud::PAGE_INDEX === $pageName) {
44
            return [$domain, $name, $destination];
45
        } elseif (Crud::PAGE_DETAIL === $pageName) {
46
            return [$id, $name, $destination, $domain];
47
        } elseif (Crud::PAGE_NEW === $pageName) {
48
            return [$domain, $name, $destination];
49
        } elseif (Crud::PAGE_EDIT === $pageName) {
50
            return [$domain, $name, $destination];
51
        }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return iterable. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
52
    }
53
}
54