Passed
Push — master ( 0c3b7f...5df6a0 )
by Nicolaas
02:16
created

SalesforceContactLog::hasError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
use SForce\Wsdl\SaveResult;
4
5
class SalesforceContactLog extends DataObject
6
{
7
8
    /**
9
     * create contact log
10
     * @param  string $type
11
     * @param  array $fieldsSent
12
     * @param  array $filters
13
     *
14
     * @return SalesforceContactLog
15
     */
16
    public static function create_contact_log($type, array $fieldsSent, array $filters) : SalesforceContactLog
0 ignored issues
show
Unused Code introduced by
The parameter $filters 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

16
    public static function create_contact_log($type, array $fieldsSent, /** @scrutinizer ignore-unused */ array $filters) : SalesforceContactLog

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...
17
    {
18
        $fieldsSent = serialize($fieldsSent);
19
        $filters = serialize($fieldsSent);
20
        $obj = SalesforceContactLog::create(
21
            [
22
                'Type' => $type,
23
                'FieldsSent' => $fieldsSent,
24
                'Filters' => $filters,
25
            ]
26
        );
27
        $id = $obj->write();
28
29
        return SalesforceContactLog::get()->byID($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return SalesforceContactLog::get()->byID($id) returns the type DataObject which includes types incompatible with the type-hinted return SalesforceContactLog.
Loading history...
30
    }
31
32
    /**
33
     * returns true if the contact update was successful
34
     * @param  mixed $response
35
     *
36
     * @return bool
37
     */
38
    public function confirmContactLog($response) : bool
39
    {
40
        $id = '';
41
        $errors = '';
42
        $hasError = false;
43
        if(is_array($response)) {
44
            $response = $response[0];
45
        }
46
        if($response instanceof \SForce\Wsdl\SaveResult) {
47
            $id = $response->getId();
48
            $errors = serialize($response->getErrors());
49
            if($response->getSuccess()) {
50
                $hasError = false;
51
            } else {
52
                $hasError = true;
53
            }
54
        } else {
55
            $errors = 'Unexpected response: '.serialize($response);
56
            // print_r($response);
57
            user_error('unexptected response');
58
        }
59
        $this->SalesforceIdentifier = $id;
1 ignored issue
show
Bug Best Practice introduced by
The property SalesforceIdentifier does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
60
        $this->Errors = $errors;
1 ignored issue
show
Bug Best Practice introduced by
The property Errors does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
61
        $this->HasError = $hasError;
1 ignored issue
show
Bug Best Practice introduced by
The property HasError does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
62
        $this->write();
63
64
        return $this->HasError;
65
    }
66
67
    /**
68
     * Singular name for CMS
69
     * @var string
70
     */
71
    private static $singular_name = 'Sales Force Contact Log';
1 ignored issue
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
72
73
    /**
74
     * Plural name for CMS
75
     * @var string
76
     */
77
    private static $plural_name = 'Sales Force Contact Log Entries';
1 ignored issue
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
78
79
    /**
80
     * SS4 prep!
81
     * @var string
82
     */
83
    private static $table_name = 'SalesforceContactLog';
1 ignored issue
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
84
85
    private static $db = [
1 ignored issue
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
86
        'SalesforceIdentifier' => 'Varchar(40)',
87
        'Type' => 'Enum("Created,Updated")',
88
        'Executed' => 'Boolean',
89
        'FieldsSent' => 'Text',
90
        'Filters' => 'Text',
91
        'HasError' => 'Boolean',
92
        'Errors' => 'Text',
93
    ];
94
95
96
    private static $default_sort = [
1 ignored issue
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
97
        'ID' => 'DESC'
98
    ];
99
100
    /**
101
     * Defines a default list of filters for the search context
102
     * @var array
103
     */
104
    private static $searchable_fields = [
1 ignored issue
show
introduced by
The private property $searchable_fields is not used, and could be removed.
Loading history...
105
        'Type' => 'ExactMatchFilter',
106
        'Executed' => 'ExactMatchFilter',
107
        'HasError' => 'ExactMatchFilter',
108
        'SalesforceIdentifier' => 'PartialMatchField',
109
        'FieldsSent' => 'PartialMatchField',
110
        'Filters' => 'PartialMatchField',
111
        'Errors' => 'PartialMatchField',
112
    ];
113
114
    /**
115
     * Defines summary fields commonly used in table columns
116
     * as a quick overview of the data for this dataobject
117
     * @var array
118
     */
119
    private static $summary_fields = [
1 ignored issue
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
120
        'Created.Nice' => 'Created',
121
        'SalesforceIdentifier' => 'SF ID',
122
        'Type' => 'Type',
123
        'Executed.Nice' => 'Executed',
124
        'Type' => 'Type',
125
        'HasError.Nice' => 'Errors',
126
        'Errors' => 'Errors',
127
    ];
128
129
    private static $indexes = [
1 ignored issue
show
introduced by
The private property $indexes is not used, and could be removed.
Loading history...
130
        'SalesforceIdentifier' => true
131
    ];
132
133
    /**
134
     * CMS Fields
135
     * @return FieldList
136
     */
137
    public function getCMSFields()
138
    {
139
        $fields = parent::getCMSFields();
140
        $fields->removeFieldsFromTab(
141
            'Root.Main',
142
            [
143
                'FieldsSent',
144
                'Filters',
145
                'HasError',
146
                'Executed',
147
            ]
148
        );
149
        $fields->addFieldsToTab(
150
            'Root.Main',
151
            [
152
                ReadonlyField::create(
153
                    'Created',
154
                    'Created',
155
                    DBField::create_field('SS_DateTime', $this->Created)->Nice()
156
                ),
157
                ReadonlyField::create(
158
                    'SalesforceIdentifier',
159
                    'Sales Force Identifier'
160
                ),
161
                LiteralField::create(
162
                    'FieldsSentNice',
163
                    '<h2>Fields Sent</h2>'.$this->serializedToHTML($this->FieldsSent)
1 ignored issue
show
Bug Best Practice introduced by
The property FieldsSent does not exist on SalesforceContactLog. Since you implemented __get, consider adding a @property annotation.
Loading history...
164
                ),
165
                ReadonlyField::create(
166
                    'Type',
167
                    'Type'
168
                ),
169
                LiteralField::create(
170
                    'FiltersNice',
171
                    '<h2>Filters</h2>'.$this->serializedToHTML($this->Filters)
1 ignored issue
show
Bug Best Practice introduced by
The property Filters does not exist on SalesforceContactLog. Since you implemented __get, consider adding a @property annotation.
Loading history...
172
                ),
173
                ReadonlyField::create(
174
                    'ExecutedNice',
175
                    'Executed',
176
                    DBField::create_field('Boolean', $this->Executed)->Nice()
1 ignored issue
show
Bug Best Practice introduced by
The property Executed does not exist on SalesforceContactLog. Since you implemented __get, consider adding a @property annotation.
Loading history...
177
                ),
178
                ReadonlyField::create(
179
                    'HasErrorNice',
180
                    'HasError',
181
                    DBField::create_field('Boolean', $this->HasError)->Nice()
182
                ),
183
                ReadonlyField::create(
184
                    'Errors',
185
                    'Communication Errors'
186
                )->setRightTitle('Separated by three ||| symbols.')
187
            ]
188
        );
189
190
        return $fields;
191
    }
192
193
    /**
194
     * DataObject create permissions
195
     * @param Member $member
196
     * @return bool
197
     */
198
    public function canCreate($member = null)
199
    {
200
        return false;
201
    }
202
203
    /**
204
     * DataObject edit permissions
205
     * @param Member $member
206
     * @return bool
207
     */
208
    public function canEdit($member = null)
209
    {
210
        return false;
211
    }
212
213
    /**
214
     * DataObject delete permissions
215
     * @param Member $member
216
     * @return bool
217
     */
218
    public function canDelete($member = null)
219
    {
220
        return false;
221
    }
222
223
    /**
224
     *
225
     * @param  string $serializedString (serialised data)
226
     * @return string (html)
227
     */
228
    protected function serializedToHTML($serializedString)
229
    {
230
        $s = unserialize($serializedString);
231
232
        return '<pre>'.print_r($s, 1).'</pre>';
233
    }
234
235
}
236