Passed
Pull Request — master (#407)
by Kirill
05:21
created

StorageBootloader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
dl 0
loc 36
rs 10
c 1
b 0
f 1
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 30 3
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Bootloader\Storage;
13
14
use Spiral\Boot\Bootloader\Bootloader;
15
use Spiral\Config\ConfiguratorInterface;
16
use Spiral\Core\Container;
17
use Spiral\Core\Exception\InvalidArgumentException;
18
use Spiral\Storage\Manager;
19
use Spiral\Storage\ManagerInterface;
20
use Spiral\Storage\Storage;
21
use Spiral\Storage\StorageInterface;
22
use Spiral\Distribution\ManagerInterface as CdnInterface;
23
24
class StorageBootloader extends Bootloader
25
{
26
    /**
27
     * @param Container $app
28
     * @param ConfiguratorInterface $config
29
     */
30
    public function boot(Container $app, ConfiguratorInterface $config): void
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

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

30
    public function boot(Container $app, /** @scrutinizer ignore-unused */ ConfiguratorInterface $config): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        $app->bindInjector(StorageConfig::class, ConfiguratorInterface::class);
33
34
        $app->bindSingleton(ManagerInterface::class, static function (StorageConfig $config, CdnInterface $cdn) {
35
            $manager = new Manager($config->getDefaultBucket());
36
37
            $distributions = $config->getDistributions();
38
39
            foreach ($config->getAdapters() as $name => $adapter) {
40
                $resolver = isset($distributions[$name])
41
                    ? $cdn->resolver($distributions[$name])
42
                    : null;
43
44
                $manager->add($name, Storage::fromAdapter($adapter, $resolver));
45
            }
46
47
            return $manager;
48
        });
49
50
        $app->bindSingleton(Manager::class, static function (ManagerInterface $manager) {
51
            return $manager;
52
        });
53
54
        $app->bindSingleton(StorageInterface::class, static function (ManagerInterface $manager) {
55
            return $manager->storage();
56
        });
57
58
        $app->bindSingleton(Storage::class, static function (StorageInterface $storage) {
59
            return $storage;
60
        });
61
    }
62
}
63