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

SalesforceContactLog::serializedToHTML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
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  SalesforceContactLog $obj
35
     * @param  mixed $response
36
     *
37
     * @return bool
38
     */
39
    public function endContactLog(SalesforceContactLog $obj, $response) : bool
0 ignored issues
show
Unused Code introduced by
The parameter $obj 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

39
    public function endContactLog(/** @scrutinizer ignore-unused */ SalesforceContactLog $obj, $response) : bool

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