Issues (124)

src/Traits/MongoConnection.php (3 issues)

1
<?php
2
3
namespace CodexShaper\DBM\Traits;
4
5
use Illuminate\Support\Facades\DB;
6
use MongoDB\Client;
0 ignored issues
show
The type MongoDB\Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
trait MongoConnection
9
{
10
    /* @var object */
11
    protected static $connection;
12
    /* @var string */
13
    protected $admin = 'admin';
14
15
    /**
16
     * Create new Mongo Client.
17
     *
18
     * @return void
19
     */
20
    public function __construct()
21
    {
22
        if (! self::$connection = DB::connection()->getMongoClient()) {
0 ignored issues
show
The method getMongoClient() does not exist on Illuminate\Database\ConnectionInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        if (! self::$connection = DB::connection()->/** @scrutinizer ignore-call */ getMongoClient()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
            $host = config('database.connections.mongodb.host');
24
            $port = config('database.connections.mongodb.port');
25
            $options = config('database.connections.mongodb.options');
0 ignored issues
show
The assignment to $options is dead and can be removed.
Loading history...
26
            $auth_db = config('database.connections.mongodb.options.database') ? config('database.connections.mongodb.options.database') : null;
27
            $dsn = config('database.connections.mongodb.dsn');
28
29
            if (! $dsn) {
30
                $dsn = 'mongodb://'.$host.':'.$port.($auth_db ? '/'.$auth_db : '');
31
            }
32
33
            self::$connection = new Client($dsn);
34
        }
35
36
        $this->admin = config('database.connections.mongodb.options.database', 'admin');
37
    }
38
39
    /**
40
     * Get mongo client instance.
41
     *
42
     * @return \MongoDB\Client
43
     */
44
    public function getMongoClient()
45
    {
46
        if (! self::$connection) {
47
            new self();
48
        }
49
50
        return self::$connection;
51
    }
52
}
53