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

MySalesforcePartnerApi::debugOutput()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
nc 6
nop 2
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
3
use SForce\Client\Partner;
4
5
use SForce\SObject;
6
use SForce\Wsdl\SaveResult;
7
8
class MySalesforcePartnerApi extends Partner
9
{
10
11
    /**
12
     * turns key value pairs into string
13
     * @param  array $array [description]
14
     * @return string
15
     */
16
    public static function array2sql($array, $glue = ' AND ') : string
17
    {
18
        if(count($array) === 0) {
19
            user_error('must have at least one entry');
20
        }
21
        $inner = [];
22
        foreach($array as $field => $value) {
23
            $inner[$field] =  $field.' = '.Convert::raw2sql($value, true);
1 ignored issue
show
Bug introduced by
Are you sure Convert::raw2sql($value, true) of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

23
            $inner[$field] =  $field.' = './** @scrutinizer ignore-type */ Convert::raw2sql($value, true);
Loading history...
24
        }
25
26
        return implode($glue, $inner);
27
    }
28
29
30
    public function debug($response = null)
31
    {
32
        $this->debugShowRequest();
33
        $this->debugShowResponse($response);
34
    }
35
36
    protected function debugShowRequest()
37
    {
38
        $this->debugOutput('
39
            <h2>Request</h2>
40
            <pre>
41
        ');
42
        $this->debugOutput($this->debugLastRequest(), true);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->debugLastRequest() targeting MySalesforcePartnerApi::debugLastRequest() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
43
        $this->debugOutput('
44
            </pre>
45
        ');
46
    }
47
48
49
    protected function debugShowResponse($response)
50
    {
51
        $this->debugOutput('
52
            <h2>Response</h2>
53
            <pre>
54
        ');
55
        $this->debugOutput($response);
56
        $this->debugOutput('
57
            </pre>
58
        ');
59
    }
60
61
    protected function debugLastRequest()
62
    {
63
        $xml = $this->getLastRequest();
64
65
        if (! $xml) {
66
            return null;
67
        }
68
        $domxml = new \DOMDocument('1.0');
69
        $domxml->preserveWhiteSpace = false;
70
        $domxml->formatOutput = true;
71
        /* @var $xml SimpleXMLElement */
72
        $domxml->loadXML($xml);
73
        echo $domxml->saveXML();
74
    }
75
76
77
78
    protected function debugOutput($html, $escape = false)
79
    {
80
        if (! is_string($html)) {
81
            $html = print_r($html, 1);
82
        }
83
        if ($this->isCli()) {
84
            echo "\n";
85
        } elseif ($escape) {
86
            $html = htmlentities($html);
87
        }
88
89
        echo $html;
90
    }
91
92
    protected function isCli()
93
    {
94
        return PHP_SAPI === 'cli';
95
    }
96
97
98
    #####################################
99
    # overriding parent class to fix bugs
100
    # in the parent class.
101
    #####################################
102
    /**
103
     * Adds one or more new individual objects to your organization's data.
104
     *
105
     * @param SObject[] $sObjects Array of one or more sObjects (up to 200) to create.
106
     * @param null|string $type Unused
107
     *
108
     * @return SaveResult
109
     */
110
    public function create($sObjects, $type = null)
111
    {
112
        foreach ($sObjects as $sObject) {
113
            if (property_exists($sObject, 'fields')) {
114
                $sObject->setAny($this->_convertToAny($sObject->getFields()));
1 ignored issue
show
Bug introduced by
$sObject->getFields() of type object is incompatible with the type array expected by parameter $fields of SForce\Client\Base::_convertToAny(). ( Ignorable by Annotation )

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

114
                $sObject->setAny($this->_convertToAny(/** @scrutinizer ignore-type */ $sObject->getFields()));
Loading history...
115
                // print_r($this->_convertToAny($sObject->getFields()));
116
            }
117
        }
118
        $createObject = new SForce\Wsdl\create($sObjects);
1 ignored issue
show
Bug introduced by
$sObjects of type SForce\SObject[] is incompatible with the type SForce\Wsdl\sObject expected by parameter $sObjects of SForce\Wsdl\create::__construct(). ( Ignorable by Annotation )

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

118
        $createObject = new SForce\Wsdl\create(/** @scrutinizer ignore-type */ $sObjects);
Loading history...
119
120
        return parent::_create($createObject);
121
    }
122
123
    #####################################
124
    # overriding parent class to fix bugs
125
    # in the parent class.
126
    #####################################
127
    /**
128
     * Updates one or more new individual objects to your organization's data.
129
     *
130
     * @param SObject[] $sObjects Array of one or more sObjects (up to 200) to update.
131
     * @param null|string $type Unused
132
     *
133
     * @return SaveResult
134
     */
135
    public function update($sObjects, $type = null)
1 ignored issue
show
Unused Code introduced by
The parameter $type 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

135
    public function update($sObjects, /** @scrutinizer ignore-unused */ $type = null)

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...
136
    {
137
        foreach ($sObjects as $sObject) {
138
            if (property_exists($sObject, 'fields')) {
139
                $sObject->setAny($this->_convertToAny($sObject->getFields()));
1 ignored issue
show
Bug introduced by
$sObject->getFields() of type object is incompatible with the type array expected by parameter $fields of SForce\Client\Base::_convertToAny(). ( Ignorable by Annotation )

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

139
                $sObject->setAny($this->_convertToAny(/** @scrutinizer ignore-type */ $sObject->getFields()));
Loading history...
140
            }
141
        }
142
        $updateObject = new SForce\Wsdl\update($sObjects);
1 ignored issue
show
Bug introduced by
$sObjects of type SForce\SObject[] is incompatible with the type SForce\Wsdl\sObject expected by parameter $sObjects of SForce\Wsdl\update::__construct(). ( Ignorable by Annotation )

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

142
        $updateObject = new SForce\Wsdl\update(/** @scrutinizer ignore-type */ $sObjects);
Loading history...
143
144
        return parent::_update($updateObject);
145
    }
146
147
    /**
148
     * NOTA BENE:
149
     * added here because Describe Layout occurs two times (double) with capital D
150
     * (DescribeLayout) and without capital D (changed to describeLayoutDouble)
151
     *
152
     * Use describeLayoutDouble to retrieve information about the layout (presentation
153
     * of data to users) for a given object type. The describeLayoutDouble call returns
154
     * metadata about a given page layout, including layouts for edit and
155
     * display-only views and record type mappings. Note that field-level security
156
     * and layout editability affects which fields appear in a layout.
157
     *
158
     * @param string $type Object Type
159
     * @param array $recordTypeIds
160
     *
161
     * @return Wsdl\DescribeLayoutResult
1 ignored issue
show
Bug introduced by
The type Wsdl\DescribeLayoutResult was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
162
     */
163
    public function describeLayoutDouble($type, array $recordTypeIds = [])
164
    {
165
        $this->setHeaders(static::CALL_DESCRIBE_LAYOUT);
166
167
        return $this->sforce
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->sforce->de...dTypeIds))->getResult() returns the type SForce\Wsdl\DescribeLayoutResult which is incompatible with the documented return type Wsdl\DescribeLayoutResult.
Loading history...
168
            ->describeLayoutDouble(new Wsdl\describeLayoutDouble($type, $recordTypeIds))
1 ignored issue
show
Bug introduced by
The type Wsdl\describeLayoutDouble was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
169
            ->getResult();
170
    }
171
}
172