Passed
Push — master ( 5f7a8f...e93faf )
by Nicolaas
02:10
created

SalesforceContactLog::confirmContactLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 11
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 = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
41
        $errors = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $errors is dead and can be removed.
Loading history...
42
        print_r($response);
43
        die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. 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...
44
        $this->SalesforceIdentifier = $id;
0 ignored issues
show
Unused Code introduced by
$this->SalesforceIdentifier = $id is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
45
        $this->Errors = $errors;
46
        $this->write();
47
48
        return $this->hasError();
49
    }
50
51
    public function hasError() : bool
52
    {
53
        return $this->SalesforceIdentifier ? false : true;
54
    }
55
56
    /**
57
     * Singular name for CMS
58
     * @var string
59
     */
60
    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...
61
62
    /**
63
     * Plural name for CMS
64
     * @var string
65
     */
66
    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...
67
68
    /**
69
     * SS4 prep!
70
     * @var string
71
     */
72
    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...
73
74
    private static $db = [
1 ignored issue
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
75
        'SalesforceIdentifier' => 'Varchar(40)',
76
        'Type' => 'Enum("Created,Updated")',
77
        'FieldsSent' => 'Text',
78
        'Filters' => 'Text',
79
        'Errors' => 'Text',
80
    ];
81
82
83
    private static $default_sort = [
1 ignored issue
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
84
        'ID' => 'DESC'
85
    ];
86
87
    /**
88
     * Defines a default list of filters for the search context
89
     * @var array
90
     */
91
    private static $searchable_fields = [
1 ignored issue
show
introduced by
The private property $searchable_fields is not used, and could be removed.
Loading history...
92
        'Type' => 'ExactMatchFilter',
93
        'SalesforceIdentifier' => 'PartialMatchField',
94
        'FieldsSent' => 'PartialMatchField',
95
        'Filters' => 'PartialMatchField',
96
        'Errors' => 'PartialMatchField',
97
    ];
98
99
    /**
100
     * Defines summary fields commonly used in table columns
101
     * as a quick overview of the data for this dataobject
102
     * @var array
103
     */
104
    private static $summary_fields = [
1 ignored issue
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
105
        'SalesforceIdentifier' => 'SF ID',
106
        'Type' => 'Type',
107
        'Errors' => 'Errors'
108
    ];
109
110
    private static $indexes = [
1 ignored issue
show
introduced by
The private property $indexes is not used, and could be removed.
Loading history...
111
        'SalesforceIdentifier' => true
112
    ];
113
114
    /**
115
     * CMS Fields
116
     * @return FieldList
117
     */
118
    public function getCMSFields()
119
    {
120
        $fields = parent::getCMSFields();
121
        $fields->addFieldsToTab(
122
            'Root.Main',
123
            [
124
                ReadonlyField::create(
125
                    'SalesforceIdentifier',
126
                    'Sales Force Identifier'
127
                ),
128
                ReadonlyField::create(
129
                    'FieldsSent',
130
                    'Fields Sent',
131
                    $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...
132
                ),
133
                ReadonlyField::create(
134
                    'Type',
135
                    'Type'
136
                ),
137
                ReadonlyField::create(
138
                    'Filters',
139
                    'Filters',
140
                    $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...
141
                ),
142
                ReadonlyField::create(
143
                    'Errors',
144
                    'Communication Errors'
145
                )->setRightTitle('Separated by three ||| symbols.')
146
            ]
147
        );
148
149
        return $fields;
150
    }
151
152
    /**
153
     * DataObject create permissions
154
     * @param Member $member
155
     * @return bool
156
     */
157
    public function canCreate($member = null)
158
    {
159
        return false;
160
    }
161
162
    /**
163
     * DataObject edit permissions
164
     * @param Member $member
165
     * @return bool
166
     */
167
    public function canEdit($member = null)
168
    {
169
        return false;
170
    }
171
172
    /**
173
     * DataObject delete permissions
174
     * @param Member $member
175
     * @return bool
176
     */
177
    public function canDelete($member = null)
178
    {
179
        return false;
180
    }
181
182
    /**
183
     *
184
     * @param  string $serializedString (serialised data)
185
     * @return string (html)
186
     */
187
    protected function serializedToHTML($serializedString)
188
    {
189
        $s = unserialize($serializedString);
190
191
        return '<pre>'.print_r($s, 1).'</pre>';
192
    }
193
194
}
195