Passed
Push — master ( 14ed89...8aec5a )
by Nicolaas
01:56
created

MySalesforceConfigViewerApi::select_field()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 17
rs 10
c 1
b 0
f 0
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_field(
30
        $fieldName = 'SalesforceDefaultContactFields',
31
        $title = 'Select Default Fields'
32
    )
33
    {
34
        return CheckboxSetField::create(
35
            $fieldName,
36
            $title,
37
            SalesforceDefaultContactField::get()->map()->toArray()
38
        )
39
            ->setDescription('
40
                Select the default fields that are always sent to Salesforce
41
                when a contact signs up from this page.
42
                <br />
43
                <br />
44
                You can
45
                <a href="/admin/salesforceadmin/'.SalesforceDefaultContactField::class.'/">Add or Edit the options</a>
46
                as required.
47
                Please change with care.
48
            ');
49
    }
50
51
    /**
52
     *
53
     * @param  array|DataList|null $array fields to send
54
     * @param  string $title fields to send
55
     *
56
     * @return LiteralField
57
     */
58
    public static function fields_to_send_field(
59
        $mixed = null,
60
        $title  = 'Fields Added'
61
    )
62
    {
63
        $array = SalesforceDefaultContactField::get_fields_to_send($mixed);
64
        return LiteralField::create(
65
            'FieldsToSendToSalesforce',
66
            '<h2>'.$title.'</h2>'.
67
            self::array_to_html($array)
68
        );
69
    }
70
    /**
71
     *
72
     * @param  array|DataList|null $mixed fields to send
73
     * @param  string $title fields to send
74
     *
75
     * @return LiteralField
76
     */
77
    public static function fields_to_filter_field(
78
        $mixed = null,
79
        $title  = 'Filter Fields'
80
    )
81
    {
82
        $array = SalesforceDefaultContactField::get_fields_to_send($mixed);
83
        return LiteralField::create(
84
            'FieldsToFilterForSalesforce',
85
            '<h2>'.$title.'</h2>'.
86
            self::array_to_html($array)
87
        );
88
    }
89
90
    /**
91
     *
92
     * @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...
93
     * @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...
94
     */
95
    protected static function array_to_html($array) : string
96
    {
97
        $htmlArray = [];
98
        foreach($array as $field => $value) {
99
            $htmlArray[] = $field.' = '.$value.' ('.gettype($value).')';
100
        }
101
        if(count($htmlArray) == 0) {
102
            $htmlArray[] = 'none';
103
        }
104
105
        return '<p>- '.implode('</p><p> - ', $htmlArray).'</p>';
106
    }
107
}
108