GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (1)

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/Crawler.php (1 issue)

Labels
Severity

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 BilginPro\Agency\Dha;
4
5
use Carbon\Carbon;
6
use GuzzleHttp;
7
8
/**
9
 * Class Crawler
10
 * @package BilginPro\Ajans\Dha
11
 */
12
class Crawler
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $x_code = '';
18
19
    /**
20
     * @var string
21
     */
22
    protected $y_code = '';
23
24
    /**
25
     * @var int
26
     */
27
    protected $summary_length = 150;
28
29
    /**
30
     * @var array
31
     */
32
    protected $attributes = [
33
        'limit' => '5',
34
    ];
35
36
    /**
37
     * Create a new Crawler Instance
38
     */
39
    public function __construct($config)
40
    {
41
        $this->setParameters($config);
42
    }
43
44
    /**
45
     * Does the magic.
46
     * @return array
47
     */
48
    public function crawl($attributes = [])
49
    {
50
        $this->setAttributes($attributes);
51
52
        $response = $this->fetchUrl($this->getUrl());
53
        $xml = new \SimpleXMLElement($response);
54
        $result = [];
55
        $i = 0;
56
        foreach ($xml->channel->item as $item) {
57
            if ($this->attributes['limit'] > $i) {
58
                $news = new \stdClass;
59
                $news->code = (string)$item->guid;
60
                $news->title = (string)$item->title;
61
                $news->summary = $this->createSummary($item->description);
62
                $news->content = (string)trim(preg_replace('/\s+/', ' ', $item->description));
63
                // preg_replace is for cleaning newlines.
64
                $news->created_at = (new Carbon($item->pubDate))->format('d.m.Y H:i:s');
65
                $news->category = $this->titleCase(str_replace('DHA-', '', $item->category));
66
                $news->city = (!empty($item->location) ? $this->titleCase($item->location) : '');
67
                $news->images = [];
68
                if (isset($item->photoshd) && count($item->photoshd) > 0) {
69
                    foreach ($item->photoshd as $image) {
70
                        $news->images[] = (string)$image;
71
                    }
72
                }
73
74
                $result[] = $news;
75
                $i++;
76
            }
77
        }
78
79
        return $result;
80
    }
81
82
    /**
83
     * Creates short summary of the news, strip credits.
84
     * @param $text
85
     * @return string
86
     */
87
    public function createSummary($text)
88
    {
89
        if (strpos($text, '(DHA)') > 0) {
90
            $split = explode('(DHA)', $text);
91
            if (count($split) > 1) {
92
                $text = $split[1];
93
                $text = trim($text, ' \t\n\r\0\x0B-');
94
            }
95
        }
96
        $summary = (string)$this->shortenString(strip_tags($text), $this->summary_length);
97
98
        return $summary;
99
    }
100
101
    /**
102
     * Sets config parameters.
103
     */
104
    public function setParameters($config)
105
    {
106
        if (!is_array($config)) {
107
            throw new \InvalidArgumentException('$config variable must be an array.');
108
        }
109
        if (array_key_exists('x_code', $config)) {
110
            $this->x_code = $config['x_code'];
111
        }
112
        if (array_key_exists('y_code', $config)) {
113
            $this->y_code = $config['y_code'];
114
        }
115
        if (array_key_exists('limit', $config)) {
116
            $this->limit = $config['limit'];
0 ignored issues
show
The property limit does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
117
        }
118
    }
119
120
    /**
121
     * Sets filter attributes.
122
     * @param $attributes array
123
     */
124
    protected function setAttributes($attributes)
125
    {
126
        foreach ($attributes as $key => $value) {
127
            $this->attributes[$key] = $value;
128
        }
129
    }
130
131
    /**
132
     * Returns full url for crawling.
133
     * @return string
134
     */
135
    public function getUrl()
136
    {
137
        $url = 'http://ajans.dha.com.tr/dhayharss_resimli.php'
138
            . '?x=' . $this->x_code
139
            . '&y=' . $this->y_code;
140
141
        return $url;
142
    }
143
144
145
    /**
146
     * Fethches given url and returns response as string.
147
     * @param $url
148
     * @param string $method
149
     * @param array $options
150
     *
151
     * @return string
152
     */
153
    public function fetchUrl($url, $method = 'GET', $options = [])
154
    {
155
        $client = new GuzzleHttp\Client();
156
        $res = $client->request($method, $url, $options);
157
        if ($res->getStatusCode() == 200) {
158
            return (string)$res->getBody();
159
        }
160
        return '';
161
    }
162
163
    /**
164
     * Cuts the given string from the end of the appropriate word.
165
     * @param $str
166
     * @param $len
167
     * @return string
168
     */
169
    public function shortenString($str, $len)
170
    {
171
        if (strlen($str) > $len) {
172
            $str = rtrim(mb_substr($str, 0, $len, 'UTF-8'));
173
            $str = substr($str, 0, strrpos($str, ' '));
174
            $str .= '...';
175
            $str = str_replace(',...', '...', $str);
176
        }
177
        return $str;
178
    }
179
180
    /**
181
     * Converts a string to "Title Case"
182
     * @param $str
183
     * @return string
184
     */
185
    public function titleCase($str)
186
    {
187
        $str = mb_convert_case($str, MB_CASE_TITLE, 'UTF-8');
188
        return $str;
189
    }
190
}
191