LaravelFreelancerNL /
laravel-arangodb
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 LaravelFreelancerNL\Aranguent\Schema\Concerns; |
||
| 4 | |||
| 5 | use Illuminate\Support\Fluent; |
||
| 6 | |||
| 7 | trait Tables |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Indicate that the table needs to be created. |
||
| 11 | * |
||
| 12 | * @param array $options |
||
| 13 | * @return Fluent |
||
| 14 | */ |
||
| 15 | public function create($options = []) |
||
| 16 | { |
||
| 17 | $parameters['options'] = $options; |
||
| 18 | $parameters['explanation'] = "Create '{$this->table}' table."; |
||
|
0 ignored issues
–
show
|
|||
| 19 | $parameters['handler'] = 'table'; |
||
| 20 | |||
| 21 | return $this->addCommand('create', $parameters); |
||
|
0 ignored issues
–
show
It seems like
addCommand() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the Loading history...
|
|||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Determine if the blueprint has a create command. |
||
| 26 | * |
||
| 27 | * @return bool |
||
| 28 | */ |
||
| 29 | protected function creating() |
||
| 30 | { |
||
| 31 | return collect($this->commands)->contains(function ($command) { |
||
|
0 ignored issues
–
show
The property
commands 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...
|
|||
| 32 | return $command->name === 'create'; |
||
| 33 | }); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function executeCreateCommand($command) |
||
| 37 | { |
||
| 38 | if ($this->connection->pretending()) { |
||
| 39 | $this->connection->logQuery('/* '.$command->explanation." */\n", []); |
||
|
0 ignored issues
–
show
The property
connection 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...
|
|||
| 40 | |||
| 41 | return; |
||
| 42 | } |
||
| 43 | $options = $command->options; |
||
| 44 | if ($this->temporary === true) { |
||
|
0 ignored issues
–
show
The property
temporary 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...
|
|||
| 45 | $options['isVolatile'] = true; |
||
| 46 | } |
||
| 47 | if ($this->autoIncrement === true) { |
||
|
0 ignored issues
–
show
The property
autoIncrement 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...
|
|||
| 48 | $options['keyOptions']['autoincrement'] = true; |
||
| 49 | } |
||
| 50 | |||
| 51 | $collections = $this->collectionHandler->getAllCollections(['excludeSystem' => true]); |
||
|
0 ignored issues
–
show
The property
collectionHandler 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...
|
|||
| 52 | if (! isset($collections[$this->table])) { |
||
| 53 | $this->collectionHandler->create($this->table, $options); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Alias for getCollection. |
||
| 59 | * |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | public function getTable() |
||
| 63 | { |
||
| 64 | return $this->table; |
||
| 65 | } |
||
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * Rename the table to a given name. |
||
| 70 | * |
||
| 71 | * @param string $to |
||
| 72 | * @return Fluent |
||
| 73 | */ |
||
| 74 | public function rename($to) |
||
| 75 | { |
||
| 76 | return $this->addCommand('rename', compact('to')); |
||
|
0 ignored issues
–
show
It seems like
addCommand() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the Loading history...
|
|||
| 77 | } |
||
| 78 | |||
| 79 | |||
| 80 | /** |
||
| 81 | * Indicate that the table should be dropped. |
||
| 82 | * |
||
| 83 | * @return Fluent |
||
| 84 | */ |
||
| 85 | public function drop() |
||
| 86 | { |
||
| 87 | $parameters['explanation'] = "Drop the '{$this->table}' table."; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = 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 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...
|
|||
| 88 | $parameters['handler'] = 'table'; |
||
| 89 | |||
| 90 | return $this->addCommand('drop', $parameters); |
||
|
0 ignored issues
–
show
It seems like
addCommand() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the Loading history...
|
|||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Indicate that the table should be dropped if it exists. |
||
| 95 | * |
||
| 96 | * @return Fluent |
||
| 97 | */ |
||
| 98 | public function dropIfExists() |
||
| 99 | { |
||
| 100 | $parameters['explanation'] = "Drop the '{$this->table}' table."; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = 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 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...
|
|||
| 101 | $parameters['handler'] = 'table'; |
||
| 102 | |||
| 103 | return $this->addCommand('dropIfExists'); |
||
|
0 ignored issues
–
show
It seems like
addCommand() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the Loading history...
|
|||
| 104 | } |
||
| 105 | |||
| 106 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: