Passed
Push — master ( a040f6...1671cd )
by Jan
04:44
created

SEPAExportCrudController::getEntityFqcn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Controller\Admin;
4
5
use App\Admin\Field\VichyFileField;
6
use App\Entity\SEPAExport;
7
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
8
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
9
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
10
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
11
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
12
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
13
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
14
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
15
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
16
use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
17
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
18
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
19
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
20
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
21
use PHP_CodeSniffer\Generators\Text;
22
23
class SEPAExportCrudController extends AbstractCrudController
24
{
25
    public static function getEntityFqcn(): string
26
    {
27
        return SEPAExport::class;
28
    }
29
30
    public function configureCrud(Crud $crud): Crud
31
    {
32
        return $crud
33
            ->setEntityLabelInSingular('sepa_export.label')
34
            ->showEntityActionsInlined()
35
            //->setSearchFields(['name', 'iban', 'bic', 'comment', 'account_name'])
36
            ->setEntityLabelInPlural('sepa_export.labelp');
37
    }
38
39
    public function configureActions(Actions $actions): Actions
40
    {
41
        $actions->setPermissions([
42
            Action::DETAIL => 'ROLE_SHOW_SEPA_EXPORTS',
43
            Action::INDEX => 'ROLE_SHOW_SEPA_EXPORTS',
44
            Action::EDIT => 'ROLE_EDIT_SEPA_EXPORTS',
45
            Action::DELETE => 'ROLE_EDIT_SEPA_EXPORTS',
46
        ]);
47
48
        $actions->disable(Crud::PAGE_NEW);
49
        $actions->add(Crud::PAGE_INDEX, Action::DETAIL);
50
51
        return parent::configureActions($actions); // TODO: Change the autogenerated stub
52
    }
53
54
    public function configureFields(string $pageName): iterable
55
    {
56
        $xml_file = VichyFileField::new('xml_file', 'sepa_export.xml_file');
57
        $id = IdField::new('id', 'sepa_export.id');
58
        $number_of_payments = NumberField::new('number_of_payments', 'sepa_export.number_of_payments');
59
        $initiator_bic = TextField::new('initiator_bic', 'sepa_export.initiator_bic');
60
        $initiator_iban = TextField::new('initiator_iban', 'sepa_export.initiator_iban');
61
        $booking_date = DateTimeField::new('booking_date', 'sepa_export.booking_date');
62
        $total_sum = MoneyField::new('total_sum', 'sepa_export.total_sum')
63
            ->setCurrency('EUR')
64
            ->setStoredAsCents(true);
65
        $sepa_message_id = TextField::new('sepa_message_id', 'sepa_export.message_id');
66
        $description = TextField::new('description', 'sepa_export.description');
67
        $comment = TextEditorField::new('comment', 'sepa_export.comment');
68
        $group_ulid = TextField::new('group_ulid', 'sepa_export.group_ulid')->onlyOnDetail();
69
        $last_modified = DateTimeField::new('last_modified', 'last_modified');
70
        $creationDate = DateTimeField::new('creation_date', 'creation_date')->onlyOnDetail();
71
        $associated_payment_orders = AssociationField::new('associated_payment_orders')
72
            ->setTemplatePath('admin/field/sepa_export_association.html.twig')
73
            ->setCrudController(PaymentOrderCrudController::class);
74
75
76
        if (Crud::PAGE_INDEX === $pageName) {
77
            return [$id, $number_of_payments, $total_sum, $description, $initiator_iban, $booking_date];
78
        }
79
80
        if (Crud::PAGE_DETAIL === $pageName) {
81
            return [
82
                $xml_file,
83
84
                FormField::addPanel('sepa_export.infos')->collapsible(),
85
                $id,
86
                $number_of_payments,
87
                $total_sum,
88
                $initiator_iban,
89
                $initiator_bic,
90
                $description,
91
                $booking_date,
92
                $associated_payment_orders,
93
                $comment,
94
95
                FormField::addPanel('sepa_export.advanced')->collapsible(),
96
                $sepa_message_id,
97
                $group_ulid,
98
                $last_modified,
99
                $creationDate,
100
            ];
101
        }
102
103
        if (Crud::PAGE_EDIT === $pageName) {
104
            return [$comment];
105
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 103 is false. This 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...
106
    }
107
}
108