Passed
Push — master ( 0a06f9...d0bd04 )
by Nicolaas
02:12
created

MySalesforceConfigViewerApi   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 33
c 2
b 0
f 0
dl 0
loc 107
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A list_of_contact_record_types() 0 11 1
A fields_to_send_field() 0 10 1
A array_to_html() 0 11 3
A fields_to_filter_field() 0 10 1
A select_default_contact_fields() 0 24 2
1
<?php
2
/**
3
 * returns a bunch of form fields that inform the user about the configuration
4
 * of the connection and communication with Salesforce.
5
 */
6
class MySalesforceConfigViewerApi extends Object
7
{
8
9
    public static function list_of_contact_record_types(
10
        $fieldName = 'ListOfContactRecordTypes',
0 ignored issues
show
Unused Code introduced by
The parameter $fieldName 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

10
        /** @scrutinizer ignore-unused */ $fieldName = 'ListOfContactRecordTypes',

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...
11
        $title = 'Contact Record Types Available'
12
    )
13
    {
14
        $data = MySalesforcePartnerApi::retrieve_contact_record_types();
0 ignored issues
show
Bug introduced by
The method retrieve_contact_record_types() does not exist on MySalesforcePartnerApi. Did you maybe mean retrieve()? ( Ignorable by Annotation )

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

14
        /** @scrutinizer ignore-call */ 
15
        $data = MySalesforcePartnerApi::retrieve_contact_record_types();

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...
15
16
        return LiteralField::create(
17
            'ListOfContactRecordTypes',
18
            '<h2>'.$title.'</h2>'.
19
            '<pre>'.print_r($data).'</pre>'
20
        );
21
    }
22
23
    /**
24
     * Needs to link to a many-many relationship (SalesforceDefaultContactFields)
25
     * @param  array $array fields to send
26
     *
27
     * @return CheckboxSetField
28
     */
29
    public static function select_default_contact_fields(
30
        $fieldName = 'SalesforceDefaultContactFields',
31
        $title = 'Select Default Fields'
32
    )
33
    {
34
        $count = SalesforceDefaultContactField::count();
0 ignored issues
show
Bug introduced by
The method count() does not exist on SalesforceDefaultContactField. ( 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
        $count = SalesforceDefaultContactField::count();

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
        if($count === 0) {
36
            return HiddenField::create(
0 ignored issues
show
Bug Best Practice introduced by
The expression return HiddenField::create($fieldName, $title) returns the type HiddenField which is incompatible with the documented return type CheckboxSetField.
Loading history...
37
                $fieldName,
38
                $title
39
            );
40
        }
41
        return CheckboxSetField::create(
42
            $fieldName,
43
            $title,
44
            SalesforceDefaultContactField::get()->map()->toArray()
45
        )
46
            ->setDescription('
47
                Select the default fields that are always sent to Salesforce
48
                when a contact signs up from this page.
49
                <br />
50
                <br />
51
                You can
52
                <a href="/admin/salesforceadmin/'.SalesforceDefaultContactField::class.'/">Add or Edit the options</a>
53
                as required.
54
                Please change with care.
55
            ');
56
    }
57
58
    /**
59
     *
60
     * @param  array|DataList|null $array fields to send
61
     * @param  string $title fields to send
62
     *
63
     * @return LiteralField
64
     */
65
    public static function fields_to_send_field(
66
        $mixed = null,
67
        $title  = 'Fields Added'
68
    )
69
    {
70
        $array = SalesforceDefaultContactField::get_fields_to_send($mixed);
71
        return LiteralField::create(
72
            'FieldsToSendToSalesforce',
73
            '<h2>'.$title.'</h2>'.
74
            self::array_to_html($array)
75
        );
76
    }
77
    /**
78
     *
79
     * @param  array|DataList|null $mixed fields to send
80
     * @param  string $title fields to send
81
     *
82
     * @return LiteralField
83
     */
84
    public static function fields_to_filter_field(
85
        $mixed = null,
86
        $title  = 'Filter Fields'
87
    )
88
    {
89
        $array = SalesforceDefaultContactField::get_fields_to_send($mixed);
90
        return LiteralField::create(
91
            'FieldsToFilterForSalesforce',
92
            '<h2>'.$title.'</h2>'.
93
            self::array_to_html($array)
94
        );
95
    }
96
97
    /**
98
     *
99
     * @param  [type] $array [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
100
     * @return [type]        [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
101
     */
102
    protected static function array_to_html($array) : string
103
    {
104
        $htmlArray = [];
105
        foreach($array as $field => $value) {
106
            $htmlArray[] = $field.' = '.$value.' ('.gettype($value).')';
107
        }
108
        if(count($htmlArray) == 0) {
109
            $htmlArray[] = 'none';
110
        }
111
112
        return '<p>- '.implode('</p><p> - ', $htmlArray).'</p>';
113
    }
114
}
115