ConnectorConnectTrait::parentConnect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace ShiftOneLabs\LaravelDbEvents\Traits;
3
4
use ShiftOneLabs\LaravelDbEvents\Exceptions\ConnectingException;
5
use ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnected;
6
use ShiftOneLabs\LaravelDbEvents\Extension\Database\Events\DatabaseConnecting;
7
8
trait ConnectorConnectTrait
9
{
10
    use SupportsEvents;
11
12
    /**
13
     * Establish a database connection.
14
     *
15
     * @param  array  $config
16
     * @return \PDO
17
     */
18 39
    public function connect(array $config)
19
    {
20 39
        if ($this->fireEvent(new DatabaseConnecting($this, array_get($config, 'name'), $config), true) === false) {
21 4
            throw new ConnectingException();
22
        }
23
24 35
        $connection = $this->parentConnect($config);
25
26 33
        $this->fireEvent(new DatabaseConnected($this, array_get($config, 'name'), $config, $connection));
27
28 33
        return $connection;
29
    }
30
31
    /**
32
     * Call connect on the parent class to establish a database connection.
33
     *
34
     * @param  array  $config
35
     * @return \PDO
36
     */
37 3
    protected function parentConnect(array $config)
38
    {
39 3
        return parent::connect($config);
1 ignored issue
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (connect() instead of parentConnect()). Are you sure this is correct? If so, you might want to change this to $this->connect().

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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
40
    }
41
}
42