Issues (23)

Security Analysis    no request data  

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.

src/Parsers/ResultPage.php (4 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
namespace Sportic\Timing\RaceTecClient\Parsers;
4
5
use DOMElement;
6
use Sportic\Timing\CommonClient\Models\Split;
7
8
/**
9
 * Class ResultPage
10
 * @package Sportic\Timing\RaceTecClient\Parsers
11
 */
12
class ResultPage extends AbstractParser
13
{
14
    protected $returnContent = [];
15
16
    /**
17
     * @inheritdoc
18
     */
19
    protected function generateContent()
20
    {
21
        $this->returnContent['full_name'] = $this->parseFullName();
22
        $this->returnContent['time']      = $this->parseFinishTime();
23
        $this->parsePositions();
24
        $this->parseResultBio();
25
        $this->returnContent['splits'] = $this->parseSplits();
26
27
        return $this->returnContent;
28
    }
29
30
    public function getModelClassName()
31
    {
32
        // TODO: Implement getModelClassName() method.
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    protected function parseFullName()
39
    {
40
        return trim(
41
            $this->getCrawler()->filter('#ctl00_Content_Main_lblName')->text()
42
        );
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    protected function parseFinishTime()
49
    {
50
        return trim(
51
            $this->getCrawler()->filter('#ctl00_Content_Main_lblResFinishTime')->text()
52
        );
53
    }
54
55
    protected function parsePositions()
56
    {
57
        $posGenData = $this->getCrawler()->filter('#ctl00_Content_Main_lblResOPos')->text();
58
        list($posGen, $participants) = explode('/', $posGenData);
59
        $this->returnContent['pos_gen'] = trim($posGen);
60
        $this->returnContent['race']['participants'] = trim($participants);
61
62
        $posGenData = $this->getCrawler()->filter('#ctl00_Content_Main_lblResGPos')->text();
63
        list($posGen, $participants) = explode('/', $posGenData);
64
        $this->returnContent['pos_gender'] = trim($posGen);
65
        $this->returnContent['gender']['participants'] = trim($participants);
66
67
        $posGenData = $this->getCrawler()->filter('#ctl00_Content_Main_lblResCPos')->text();
68
        list($posGen, $participants) = explode('/', $posGenData);
69
        $this->returnContent['pos_category'] = trim($posGen);
70
        $this->returnContent['category']['participants'] = trim($participants);
71
    }
72
73
    protected function parseResultBio()
74
    {
75
        $table = $this->getCrawler()->filter('#ctl00_Content_Main_grdBio');
76
        $rows = $table->filter('tbody > tr');
77
78
        foreach ($rows as $row) {
79
            $indexCount = $row->childNodes->length;
80
            $column = $row->childNodes->item($indexCount-4)->nodeValue;
81
            $value = $row->childNodes->item($indexCount-2)->nodeValue;
82
83
            switch ($column) {
84
                case 'Race No':
85
                    $this->returnContent['bib'] = $value;
86
                    break;
87
                case 'Gender':
88
                    $this->returnContent['gender']['name'] = ($value == 'Female' ? 'female' : 'male');
89
                    break;
90
                case 'Category':
91
                    $this->returnContent['category']['name'] = $value;
92
                    break;
93
                case 'Status':
94
                    $this->returnContent['status']['name'] = $value;
95
                    break;
96
            }
97
        }
98
    }
99
100
    /**
101
     * @return array
102
     */
103
    protected function parseSplits()
104
    {
105
        $return     = [];
106
        $headerData = [];
107
        $splitRows  = $this->getCrawler()->filter(
108
            '#ctl00_Content_Main_grdSplits_DXMainTable > tbody > tr'
109
        );
110
        if ($splitRows->count() > 0) {
111
            foreach ($splitRows as $resultRow) {
112
                if ($resultRow->getAttribute('id') === 'ctl00_Content_Main_grdSplits_DXHeadersRow') {
113
                    $headerData = $this->parseSplitsHeader($resultRow);
114
                } else {
115
                    $result = $this->parseSplitRow($resultRow, $headerData);
0 ignored issues
show
Are you sure the assignment to $result is correct as $this->parseSplitRow($resultRow, $headerData) (which targets Sportic\Timing\RaceTecCl...ltPage::parseSplitRow()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
116
                    if ($result) {
117
                        $return[] = $result;
118
                    }
119
120
                }
121
            }
122
        }
123
        return $return;
124
    }
125
126
    /**
127
     * @param DOMElement $row
128
     *
129
     * @return array
130
     */
131
    protected function parseSplitsHeader($row)
132
    {
133
        $return = [];
134
135
        $fieldMap = self::getLabelMaps();
136
        $colNum   = 0;
137 View Code Duplication
        foreach ($row->childNodes as $node) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
138
            if ($node instanceof DOMElement) {
139
                $fieldName = trim($node->nodeValue);
140
                $labelFind = array_search($fieldName, $fieldMap);
141
                if ($labelFind) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $labelFind of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
142
                    $return[$colNum] = $labelFind;
143
                }
144
                $colNum++;
145
            }
146
        }
147
148
        return $return;
149
    }
150
151
    /**
152
     * @param $row
153
     * @param $headerData
154
     *
155
     * @return Split|null
156
     */
157 View Code Duplication
    protected function parseSplitRow($row, $headerData)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159
        $parameters = [];
160
        $i          = 0;
161
        foreach ($row->childNodes as $cell) {
162
            if ($cell instanceof DOMElement) {
163
                $parameters = $this->parseSplitCell($i, $cell, $headerData, $parameters);
164
                $i++;
165
            }
166
        }
167
        if (count($parameters)) {
168
            return new Split($parameters);
169
        }
170
171
        return null;
172
    }
173
174
175
    /**
176
     * @param $colCount
177
     * @param $cell
178
     * @param $headerData
179
     * @param $parameters
180
     *
181
     * @return array
182
     */
183
    protected function parseSplitCell($colCount, $cell, $headerData, $parameters)
184
    {
185
        if (isset($headerData[$colCount])) {
186
            $field              = $headerData[$colCount];
187
            $parameters[$field] = trim($cell->nodeValue);
188
        }
189
190
        return $parameters;
191
    }
192
    /**
193
     * @return array
194
     */
195
    protected static function getLabelMaps()
196
    {
197
        return [
198
            'name' => 'Split Name',
199
            'timeFromStart' => 'Time',
200
            'time' => 'Time From Previous Split',
201
        ];
202
    }
203
}
204