Issues (16)

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/Client.php (16 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
namespace Bedd\BabelNet;
3
4
/**
5
 * Client for the BabelNet HTTP Api
6
 * 
7
 * @see http://babelnet.org/guide
8
 */
9
class Client
10
{
11
    /**
12
     * API Key
13
     * 
14
     * @var string
15
     */
16
    private $api_key = '';
17
    
18
    /**
19
     * Base URL
20
     * 
21
     * @var string
22
     */
23
    private $base_url = 'https://babelnet.io/v4/';
24
    
25
    /**
26
     * @var array
27
     */
28
    private $defaultParams = [];
29
    
30
    /**
31
     * Constructor
32
     * 
33
     * @param string $api_key
34
     * @param array $defaultParams
35
     */
36
    public function __construct($api_key, array $defaultParams = [])
37
    {
38
        $this->api_key = $api_key;
39
        $this->defaultParams = $defaultParams;
40
    }
41
42
    /**
43
     * Executes an api call
44
     * @param string $service
45
     * @param array $params
46
     * @throws \Exception
47
     * @return mixed
48
     */
49
    private function exec($service, $params = array())
50
    {
51
        //add key
52
        $params['key'] = $this->api_key;
53
        //make request
54
        $url = $this->base_url.$service.'?'.http_build_query($params);
55
        $ch = curl_init();
56
        curl_setopt($ch, CURLOPT_URL, $url);
57
        curl_setopt($ch, CURLOPT_POST, false);
58
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
59
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
60
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
61
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
62
        $response = json_decode(curl_exec($ch), true);
63
        $info = curl_getinfo($ch);
64
        if ($info['http_code'] !== 200) {
65
            throw new \Exception($response['message'], $info['http_code']);
66
        }
67
        curl_close($ch);
68
        return $response;
69
    }
70
    
71
    /**
72
     * Returns a param list from a method-reflection and his params
73
     * 
74
     * @param string $method
75
     * @param array $args
76
     * @return array
77
     */
78
    private function getParamsByArguments($method, $args)
79
    {
80
        $params = [];
81
        $m = new \ReflectionMethod($method);
82
        foreach ($m->getParameters() as $param) {
83
            $value = isset($args[$param->getPosition()]) ? $args[$param->getPosition()] : null;
84
            $name = $param->getName();
0 ignored issues
show
Consider using $param->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
85
            if ($value === null && $param->isOptional()) {
86
                if ($param->isDefaultValueAvailable() && ($new_value = $param->getDefaultValue()) !== null) {
87
                    $value = $new_value;
88
                } else if (isset($this->defaultParams[$name])) {
89
                    $value = $this->defaultParams[$name];
90
                }
91
            }
92
            if ($value === null) {
93
                continue;
94
            }
95
            $params[$name] = $value;
96
        }
97
        return $params;
98
    }
99
    
100
    /**
101
     * @see http://babelnet.org/guide#RetrieveBabelNetversion
102
     * @throws \Exception
103
     * @return string
104
     */
105
    public function getVersion()
106
    {
107
        $res = $this->exec('getVersion');
108
        return isset($res['version']) ? $res['version'] : false;
109
    }
110
    
111
    /**
112
     * @see http://babelnet.org/guide#RetrievetheIDsoftheBabelsynsets(concepts)denotedbyagivenword
113
     * @param string $word
114
     * @param string $lang
115
     * @param string $filterLangs
116
     * @param string $pos
117
     * @param string $source
118
     * @param string $normalizer
119
     * @throws \Exception
120
     * @return string[]
121
     */
122
    public function getSynsetIds($word, $lang = null, $filterLangs = null, $pos = null, $source = null, $normalizer = null)
0 ignored issues
show
The parameter $word is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $lang is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $filterLangs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $pos is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $source is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $normalizer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
123
    {
124
        return array_column($this->exec('getSynsetIds', $this->getParamsByArguments(__METHOD__, func_get_args())), 'id');
125
    }
126
    
127
    /**
128
     * @see http://babelnet.org/guide#Retrievetheinformationofagivensynset
129
     * @param string $id
130
     * @param string $filterLangs
131
     * @throws \Exception
132
     * @return array
133
     */
134
    public function getSynsetById($id, $filterLangs = null)
0 ignored issues
show
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $filterLangs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
135
    {
136
        return $this->exec('getSynset', $this->getParamsByArguments(__METHOD__, func_get_args()));
137
    }
138
    
139
    /**
140
     * @see http://babelnet.org/guide#RetrievetheIDsoftheBabelsynsets(concepts)denotedbyagivenword
141
     * @param string $word
142
     * @param string $lang
143
     * @param string $filterLangs
144
     * @param string $pos
145
     * @param string $source
146
     * @param string $normalizer
147
     * @throws \Exception
148
     * @return array
149
     */
150
    public function getSynsets($word, $lang = null, $filterLangs = null, $pos = null, $source = null, $normalizer = null)
151
    {
152
        $synsets = [];
153
        foreach ($this->getSynsetIds($word, $lang, $filterLangs, $pos, $source, $normalizer) as $synset_id) {
154
            $synsets[] = $this->getSynsetById($synset_id, $filterLangs);
155
        }
156
        return $synsets;
157
    }
158
    
159
    /**
160
     * @see http://babelnet.org/guide#Retrievethesensesofagivenword
161
     * @param string $word
162
     * @param string $lang
163
     * @param string $filterLangs
164
     * @param string $pos
165
     * @param string $source
166
     * @param string $normalizer
167
     * @throws \Exception
168
     * @return array
169
     */
170
    public function getSenses($word, $lang = null, $filterLangs = null, $pos = null, $source = null, $normalizer = null)
0 ignored issues
show
The parameter $word is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $lang is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $filterLangs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $pos is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $source is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $normalizer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
171
    {
172
        return $this->exec('getSenses', $this->getParamsByArguments(__METHOD__, func_get_args()));
173
    }
174
    
175
    /**
176
     * @see http://babelnet.org/guide#RetrieveedgesofagivenBabelNetsynset6
177
     * @param string $id
178
     * @throws \Exception
179
     * @return array
180
     */
181
    public function getEdges($id)
0 ignored issues
show
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
182
    {
183
        return $this->exec('getEdges', $this->getParamsByArguments(__METHOD__, func_get_args()));
184
    }
185
}
186