This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php namespace Codengine\CustomMigrations; |
||
2 | |||
3 | use Symfony\Component\Console\Input\InputOption; |
||
4 | |||
5 | /** |
||
6 | * Class BatchMigrationTrait |
||
7 | * Provides batch migration functions for multiple database connections |
||
8 | * |
||
9 | * @package Codengine\CustomMigrations |
||
10 | */ |
||
11 | trait BatchMigrationTrait { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $migrationType = 'default'; |
||
16 | |||
17 | /** |
||
18 | * Extends the default options by type-option |
||
19 | * |
||
20 | * @return array |
||
21 | */ |
||
22 | protected function getOptions() |
||
23 | { |
||
24 | $optExtend = array( |
||
25 | array('type', null, InputOption::VALUE_OPTIONAL, 'The migration type to be executed.', 'default'), |
||
26 | ); |
||
27 | |||
28 | return array_merge(parent::getOptions(), $optExtend); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Filters the connections and only returns the ones that match the migration type |
||
33 | * |
||
34 | * @param array $connection The database connections |
||
35 | * @return bool Returns TRUE on a match, else FALSE |
||
36 | */ |
||
37 | protected function filterConnections($connection) |
||
38 | { |
||
39 | switch($this->migrationType) |
||
40 | { |
||
41 | case 'default': |
||
42 | return (empty($connection['migration_type']) || $connection['migration_type'] == 'default'); break; |
||
0 ignored issues
–
show
|
|||
43 | default: |
||
44 | return (!empty($connection['migration_type']) && $connection['migration_type'] == $this->migrationType ? true : false); break; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
45 | } |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Returns the default DB connection |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | protected function getDefaultConnection() |
||
54 | { |
||
55 | $defaultConnection = \DB::getDefaultConnection(); |
||
56 | $connection = \Config::get('database.connections.' . $defaultConnection); |
||
57 | return (empty($connection) ? array() : array($defaultConnection => $connection)); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Retrieves database connections by type |
||
62 | * |
||
63 | * @param null|string $filter When specified (--database option), only this connection will be checked |
||
64 | * @return array An array containing the matching connections |
||
65 | */ |
||
66 | protected function getConnectionsByType($filter = null) |
||
67 | { |
||
68 | $connections = array(); |
||
0 ignored issues
–
show
$connections 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 ![]() |
|||
69 | if($this->migrationType == "default" && empty($filter)) { |
||
70 | return $this->getDefaultConnection(); |
||
71 | } elseif (!empty($filter)) { |
||
72 | $connections = \Config::get('database.connections.' . $filter); |
||
73 | if(!empty($connections)) |
||
74 | { |
||
75 | $connections = array($filter => $connections); |
||
76 | } |
||
77 | } else { |
||
78 | $connections = \Config::get('database.connections'); |
||
79 | } |
||
80 | |||
81 | if(!empty($connections)) |
||
82 | { |
||
83 | $connections = array_filter($connections, array($this, 'filterConnections')); |
||
84 | } |
||
85 | return (array)$connections; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Retrieves and sets the migration type |
||
90 | */ |
||
91 | protected function setMigrationType() |
||
92 | { |
||
93 | $this->migrationType = $this->input->getOption('type'); |
||
0 ignored issues
–
show
The property
input 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;
![]() |
|||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Run a batch migration on the specified connections |
||
98 | * |
||
99 | * @param array $connections |
||
100 | */ |
||
101 | protected function runMigrationsOnConnections($connections) |
||
102 | { |
||
103 | foreach($connections as $name => $connection) |
||
104 | { |
||
105 | $this->input->setOption('database', $name); |
||
106 | if(isset($this->migrator)) |
||
107 | { |
||
108 | $this->migrator->setMigrationType(array_get($connection, 'migration_type', 'default')); |
||
0 ignored issues
–
show
The property
migrator 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;
![]() |
|||
109 | } |
||
110 | parent::fire(); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
fire() instead of runMigrationsOnConnections() ). Are you sure this is correct? If so, you might want to change this to $this->fire() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
111 | } |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Default command override |
||
116 | */ |
||
117 | public function fire() |
||
118 | { |
||
119 | $this->setMigrationType(); |
||
120 | $connections = $this->getConnectionsByType($this->input->getOption('database')); |
||
121 | if(empty($connections)) |
||
122 | { |
||
123 | $this->info("No connections found for the specified migration type"); |
||
0 ignored issues
–
show
It seems like
info() 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 ![]() |
|||
124 | } else { |
||
125 | $this->runMigrationsOnConnections($connections); |
||
126 | } |
||
127 | } |
||
128 | } |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.