Issues (12)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Classes/Service/OnPageService.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 *
4
 */
5
6
namespace HDNET\OnpageIntegration\Service;
7
8
use HDNET\OnpageIntegration\Loader\ApiResultLoader;
9
10
class OnPageService extends AbstractService
11
{
12
13
    /**
14
     * @var ApiResultLoader
15
     */
16
    protected $loader;
17
18
    /**
19
     * OnPageService constructor.
20
     *
21
     * @param ApiResultLoader $loader
22
     */
23
    public function __construct(ApiResultLoader $loader)
24
    {
25
        $this->loader = $loader;
26
    }
27
28
    /**
29
     * So that you get the error report of an
30
     * api call you have to crawl the graph api call
31
     * from a filter.
32
     *
33
     * In the next the you load the error report keys and
34
     * commit it into the errorReport function.
35
     *
36
     * errorReport generates the error report and afterwards
37
     * its stores in the field 'errors'.
38
     * '     *
39
     *
40
     * @param array           $buildData
41
     * @param string          $section
42
     * @param ApiResultLoader $loader
0 ignored issues
show
There is no parameter named $loader. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
43
     */
44
    public function build($buildData, $section)
45
    {
46
        $i = 0;
47
        foreach ($buildData as &$element) {
48
            $graphDataArray = $this->loader->load('zoom_' . $section . '_' . $i . '_graph');
49
            $errorReportKey = $element['errors'];
50
            $element['errors'] = $this->errorReport($graphDataArray, $errorReportKey);
51
            $i++;
52
        }
53
        return $buildData;
54
    }
55
56
    /**
57
     * Generates the error report key of an api call and
58
     * return the result.
59
     *
60
     * @param mixed $graphApiCallResult
61
     * @param mixed $errorReportKey
62
     *
63
     * @return int
64
     */
65
    protected function errorReport($graphApiCallResult, $errorReportKey)
66
    {
67
        $totalErrors = 0;
68
        foreach ($graphApiCallResult as $element) {
69
            if (in_array('sum', $errorReportKey)) {
70
                foreach ($errorReportKey['hidden'] as $hidden) {
71
                    if (in_array($hidden, $element)) {
72
                        continue 2;
73
                    }
74
                }
75
                $totalErrors += $element['count'];
76
            }
77
            if (in_array($errorReportKey['show'], $element)) {
78
                $totalErrors += $element['count'];
79
            }
80
        }
81
        return $totalErrors;
82
    }
83
84
    /**
85
     * Fitted $tableApiCallResult by the elements of
86
     * $showTableKey
87
     *
88
     * @param string $apiCall
89
     * @param array  $showTableKey
90
     *
91
     * @return array
92
     */
93
    public function showColumns($apiCall, array $showTableKey)
94
    {
95
        $apiCallResult = $this->loader->load($apiCall);
96
97
        $fittedTablesRecords = [];
98
        foreach ($apiCallResult as $singleCallElement) {
99
            foreach ($showTableKey as $key) {
100
                if (array_key_exists($key, $singleCallElement)) {
101
                    $singleRecordArray[$key] = $singleCallElement[$key];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$singleRecordArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $singleRecordArray = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
102
                }
103
                if ($key === 'documents') {
104
                    $documents = [
105
                        'mime'       => $singleCallElement['mime'],
106
                        'meta_title' => $singleCallElement['meta_title'],
107
                        'url'        => $singleCallElement['url'],
108
                    ];
109
                    $singleRecordArray['document'] = $documents;
0 ignored issues
show
The variable $singleRecordArray does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
110
                }
111
            }
112
            $fittedTablesRecords[] = $this->replaceNULL($singleRecordArray);
113
        }
114
        return $fittedTablesRecords;
115
    }
116
117
    /**
118
     * Build only for development
119
     */
120
    public function replaceNULL($array)
121
    {
122
        foreach ($array as &$element) {
123
            if (empty($element)) {
124
                $element = "Keine";
125
            }
126
        }
127
        return $array;
128
    }
129
}
130