ContactDetailForm_ItemRequest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 31
c 1
b 0
f 0
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doCreateUser() 0 16 3
A ItemEditForm() 0 25 6
1
<?php
2
3
namespace SilverCommerce\CatalogueAdmin\Forms\GridField;
4
5
use SilverCommerce\ContactAdmin\Helpers\ContactHelper;
6
use SilverCommerce\ContactAdmin\Model\Contact;
7
use SilverStripe\Forms\FormAction;
8
use SilverStripe\Security\Security;
9
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
10
11
/**
12
 * Custom detailform that allows generating user account from a contact
13
 *
14
 * @author ilateral
15
 */
16
class ContactDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
17
{
18
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
19
        'edit',
20
        'view',
21
        'ItemEditForm'
22
    ];
23
24
    public function ItemEditForm()
25
    {
26
        $form = parent::ItemEditForm();
27
        $record = $this->record;
28
29
        if ($record instanceof Contact
30
            && $form && $record->ID !== 0
31
            && $record->canEdit()
32
            && !$record->Member()->exists()
0 ignored issues
show
Bug introduced by
The method Member() does not exist on SilverCommerce\ContactAdmin\Model\Contact. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

32
            && !$record->/** @scrutinizer ignore-call */ Member()->exists()
Loading history...
33
        ) {
34
            $actions = $form->Actions();
0 ignored issues
show
Bug introduced by
The method Actions() does not exist on SilverStripe\Control\HTTPResponse. ( Ignorable by Annotation )

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

34
            /** @scrutinizer ignore-call */ 
35
            $actions = $form->Actions();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
            $actions->insertAfter(
36
                FormAction::create(
37
                    'doCreateUser',
38
                    _t('ContactAdmin.CreateUser', 'Create User Account')
39
                )->setUseButtonTag(true)
40
                ->addExtraClass('btn btn-outline-info')
41
                ->addExtraClass('action font-icon-torso'),
42
                "action_doSave"
43
            );
44
        }
45
        
46
        $this->extend("updateItemEditForm", $form);
47
        
48
        return $form;
49
    }
50
51
    public function doCreateUser($data, $form)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

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

51
    public function doCreateUser(/** @scrutinizer ignore-unused */ $data, $form)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $form is not used and could be removed. ( Ignorable by Annotation )

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

51
    public function doCreateUser($data, /** @scrutinizer ignore-unused */ $form)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        $record = $this->record;
54
55
        if ($record && !$record->canEdit()) {
56
            return Security::permissionFailure($this);
0 ignored issues
show
Bug introduced by
$this of type SilverCommerce\Catalogue...tDetailForm_ItemRequest is incompatible with the type SilverStripe\Control\Controller expected by parameter $controller of SilverStripe\Security\Se...ty::permissionFailure(). ( Ignorable by Annotation )

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

56
            return Security::permissionFailure(/** @scrutinizer ignore-type */ $this);
Loading history...
57
        }
58
59
        $helper = ContactHelper::create()
60
            ->setContact($record);
61
62
        $member = $helper->findOrMakeMember();
63
        $helper->setMember($member);
64
        $helper->linkMemberToGroups();
65
        
66
        return $this->redirectAfterSave(false);
67
    }
68
}
69