ServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 6
dl 0
loc 33
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 17 2
1
<?php
2
3
namespace Buttress\Concrete\Client;
4
5
use Buttress\Concrete\Client\Adapter\Adapter;
6
use Buttress\Concrete\Client\Adapter\AdapterFactory;
7
use Buttress\Concrete\Client\Adapter\LegacyAdapter;
8
use Buttress\Concrete\Client\Adapter\ModernAdapter;
9
use Buttress\Concrete\Client\Connection\Connection;
10
use Buttress\Concrete\Console\Console;
11
use Buttress\Concrete\Locator\Site;
12
use League\Container\ServiceProvider\AbstractServiceProvider;
13
14
class ServiceProvider extends AbstractServiceProvider
15
{
16
17
    protected $provides = [
18
        Adapter::class,
19
        Connection::class
20
    ];
21
22
    /**
23
     * Use the register method to register items with the container via the
24
     * protected $this->container property or the `getContainer` method
25
     * from the ContainerAwareTrait.
26
     *
27
     * @return void
28
     */
29
    public function register()
30
    {
31
        $container = $this->getContainer();
32
33
        // Get the adapter instance from the factory
34
        $container->add(Adapter::class, function(AdapterFactory $factory, Site $site) {
35
            return $factory->fromSite($site);
36
        })->withArgument(AdapterFactory::class)->withArgument(Site::class);
37
38
        // Connect to concrete5
39
        $container->add(Connection::class, function(Concrete5 $client, Console $console) {
40
            if ($result = $client->connect()) {
41
                $console->registerErrorHandler();
42
                return $result;
43
            }
44
        })->withArguments([Concrete5::class, Console::class]);
45
    }
46
}
47