Completed
Pull Request — master (#74)
by
unknown
02:12 queued 57s
created

MailboxManager::mailbox()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace BeyondCode\Mailbox;
4
5
use BeyondCode\Mailbox\Drivers\DriverInterface;
6
use Closure;
7
use Illuminate\Contracts\Container\Container;
8
use Illuminate\Support\Manager;
9
10
class MailboxManager extends Manager
11
{
12
    /**
13
     * Create a new manager instance.
14
     *
15
     * @param Container $container
16
     * @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...
17
     */
18
    public function __construct(Container $container)
19
    {
20
        parent::__construct($container);
21
22
        $this->registerDrivers();
23
    }
24
25
    public function getDefaultDriver()
26
    {
27
        return $this->container['config']['mailbox.driver'];
28
    }
29
30
    protected function registerDrivers(): void
31
    {
32
        $supported = config('mailbox.supported_drivers');
33
34
        foreach ($supported as $driver => $mappedTo) {
35
            $callback = is_callable($mappedTo) ?
36
                $mappedTo : $this->registerDriverCallable($mappedTo);
37
38
            $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...
39
        }
40
    }
41
42
    protected function registerDriverCallable(string $driver): Closure
43
    {
44
        return function () use ($driver): DriverInterface {
45
            return new $driver;
46
        };
47
    }
48
}
49