These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | require 'vendor/autoload.php'; |
||
4 | |||
5 | use GuzzleHttp\Client; |
||
6 | |||
7 | class DataslangApi { |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
8 | |||
9 | public function __construct(){ |
||
10 | $this->client = new Client([ |
||
0 ignored issues
–
show
The property
client 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;
![]() |
|||
11 | // Base URI is used with relative requests |
||
12 | 'base_uri' => 'http://api.dataslang.com', |
||
13 | // You can set any number of default request options. |
||
14 | 'timeout' => 2.0, |
||
15 | ]); |
||
16 | } |
||
17 | |||
18 | public function validate($xml, $xsd){ |
||
0 ignored issues
–
show
|
|||
19 | $b = false; |
||
20 | $response = $this->client->request('POST', '/validate', [ |
||
0 ignored issues
–
show
$response is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
21 | 'form_params' => [ |
||
22 | 'field_name' => 'abc', |
||
23 | 'other_field' => '123', |
||
24 | 'nested_field' => [ |
||
25 | 'nested' => 'hello' |
||
26 | ] |
||
27 | ] |
||
28 | ]); |
||
29 | return $b; |
||
30 | } |
||
31 | |||
32 | } |
||
33 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.