Completed
Pull Request — master (#75)
by
unknown
03:20 queued 11s
created

MailboxManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BeyondCode\Mailbox;
6
7
use BeyondCode\Mailbox\Drivers\DriverInterface;
8
use Closure;
9
use Illuminate\Contracts\Container\Container;
10
use Illuminate\Support\Manager;
11
12
class MailboxManager extends Manager
13
{
14
    /**
15
     * Create a new manager instance.
16
     *
17
     * @param Container $container
18
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
19
     */
20
    public function __construct(Container $container)
21
    {
22
        parent::__construct($container);
23
24
        $this->registerDrivers();
25
    }
26
27
    public function getDefaultDriver(): string
28
    {
29
        return $this->container['config']['mailbox.driver'];
30
    }
31
32
    protected function registerDrivers(): void
33
    {
34
        $supported = config('mailbox.supported_drivers');
35
36
        foreach ($supported as $driver => $mappedTo) {
37
            $callback = is_callable($mappedTo) ?
38
                $mappedTo : $this->registerDriverCallable($mappedTo);
39
40
            $this->extend($driver, $callback);
0 ignored issues
show
Documentation introduced by
$callback is of type callable, but the function expects a object<Closure>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
        }
42
    }
43
44
    protected function registerDriverCallable(string $driver): Closure
45
    {
46
        return function () use ($driver): DriverInterface {
47
            return new $driver;
48
        };
49
    }
50
}
51