Issues (18)

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/Testing/RefreshDatabase.php (7 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
3
namespace Tonysm\LaravelParatest\Testing;
4
5
use Illuminate\Contracts\Console\Kernel;
6
7
/**
8
 * Trait RefreshDatabase
9
 *
10
 * Most of the code here was copied from Laravel's RefreshDatabase trait.
11
 *
12
 * @package Tonysm\DbCreateCommand\Testing
13
 *
14
 * @see https://github.com/laravel/framework/blob/5.8/src/Illuminate/Foundation/Testing/RefreshDatabase.php
15
 */
16
trait RefreshDatabase
17
{
18
    /**
19
     * Define hooks to migrate the database before and after each test.
20
     *
21
     * @return void
22
     */
23
    public function refreshDatabase()
24
    {
25
        $this->usingInMemoryDatabase()
26
            ? $this->refreshInMemoryDatabase()
27
            : $this->refreshTestDatabase();
28
    }
29
30
    /**
31
     * Determine if an in-memory database is being used.
32
     *
33
     * @return bool
34
     */
35
    protected function usingInMemoryDatabase()
36
    {
37
        $default = config('database.default');
38
39
        return config("database.connections.$default.database") === ':memory:';
40
    }
41
42
    /**
43
     * Refresh the in-memory database.
44
     *
45
     * @return void
46
     */
47
    protected function refreshInMemoryDatabase()
48
    {
49
        $this->artisan('migrate');
0 ignored issues
show
It seems like artisan() 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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
50
51
        $this->app[Kernel::class]->setArtisan(null);
0 ignored issues
show
The property app 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
    }
53
54
    /**
55
     * Refresh a conventional test database.
56
     *
57
     * @return void
58
     */
59
    protected function refreshTestDatabase()
60
    {
61
        $this->swapTestingDatabase();
62
63
        if (! RefreshDatabaseState::$migrated) {
64
            $this->artisan('db:create');
0 ignored issues
show
It seems like artisan() 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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
65
            $this->artisan('migrate:fresh', $this->shouldDropViews() ? [
0 ignored issues
show
It seems like artisan() 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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
66
                '--drop-views' => true,
67
            ] : []);
68
69
            $this->app[Kernel::class]->setArtisan(null);
70
71
            RefreshDatabaseState::$migrated = true;
72
        }
73
74
        $this->beginDatabaseTransaction();
75
    }
76
77
    /**
78
     * Begin a database transaction on the testing database.
79
     *
80
     * @return void
81
     */
82
    public function beginDatabaseTransaction()
83
    {
84
        $database = $this->app->make('db');
85
86
        foreach ($this->connectionsToTransact() as $name) {
87
            $connection = $database->connection($name);
88
            $dispatcher = $connection->getEventDispatcher();
89
90
            $connection->unsetEventDispatcher();
91
            $connection->beginTransaction();
92
            $connection->setEventDispatcher($dispatcher);
93
        }
94
95
        $this->beforeApplicationDestroyed(function () use ($database) {
0 ignored issues
show
It seems like beforeApplicationDestroyed() 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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
96
            foreach ($this->connectionsToTransact() as $name) {
97
                $connection = $database->connection($name);
98
                $dispatcher = $connection->getEventDispatcher();
99
100
                $connection->unsetEventDispatcher();
101
                $connection->rollback();
102
                $connection->setEventDispatcher($dispatcher);
103
                $connection->disconnect();
104
            }
105
        });
106
    }
107
108
    /**
109
     * The database connections that should have transactions.
110
     *
111
     * @return array
112
     */
113
    protected function connectionsToTransact()
114
    {
115
        return property_exists($this, 'connectionsToTransact')
116
            ? $this->connectionsToTransact : [null];
0 ignored issues
show
The property connectionsToTransact 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
     * Determine if views should be dropped when refreshing the database.
121
     *
122
     * @return bool
123
     */
124
    protected function shouldDropViews()
125
    {
126
        return property_exists($this, 'dropViews')
127
            ? $this->dropViews : false;
0 ignored issues
show
The property dropViews 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...
128
    }
129
130
    protected function swapTestingDatabase(): void
131
    {
132
        $driver = config('database.default');
133
        $dbName = config("database.connections.{$driver}.database");
134
135
        // Paratest gives each process a unique TEST_TOKEN env variable.
136
        // When that's not set, we can default to 1 because it's
137
        // probably running on PHPUnit instead.
138
        config([
139
            "database.connections.{$driver}.database" => sprintf(
140
                '%s_test_%s',
141
                $dbName,
142
                env('TEST_TOKEN', 1)
143
            ),
144
        ]);
145
    }
146
}
147