Services   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
c 1
b 0
f 0
dl 0
loc 68
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 63 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Rarst\Hugo\wprss2hugo;
5
6
use Pimple\Container;
7
use Pimple\ServiceProviderInterface;
8
use Rarst\Hugo\wprss2hugo\Command\Import;
9
use Rarst\Hugo\wprss2hugo\Filesystem\Storage;
10
use Rarst\Hugo\wprss2hugo\Filesystem\Write;
11
use Rarst\Hugo\wprss2hugo\Handler\Author;
12
use Rarst\Hugo\wprss2hugo\Handler\Config;
13
use Rarst\Hugo\wprss2hugo\Handler\Handler;
14
use Rarst\Hugo\wprss2hugo\Handler\Post;
15
use Rarst\Hugo\wprss2hugo\Handler\Term;
16
use Rarst\Hugo\wprss2hugo\Serializer\Content;
17
use Rarst\Hugo\wprss2hugo\Serializer\Html;
18
use Rarst\Hugo\wprss2hugo\Serializer\Data;
19
use Rarst\Hugo\wprss2hugo\Serializer\Yaml;
20
use Symfony\Component\Filesystem\Filesystem;
21
22
/**
23
 * Default services definitions for a dependency injection container.
24
 *
25
 * @psalm-suppress MoreSpecificReturnType
26
 * @psalm-suppress LessSpecificReturnStatement
27
 */
28
class Services implements ServiceProviderInterface
29
{
30
    /**
31
     * Register services on a container.
32
     */
33
    public function register(Container $container): void
34
    {
35
        $container['serializer.content.class'] = Html::class;
36
        $container['serializer.content']       = static function () use ($container) : Content {
37
            return new $container['serializer.content.class'];
38
        };
39
40
        $container['serializer.front-matter.class'] = Yaml::class;
41
        $container['serializer.front-matter']       = static function () use ($container) : Data {
42
            return new $container['serializer.front-matter.class'];
43
        };
44
45
        $container['serializer.data.class'] = Yaml::class;
46
        $container['serializer.data']       = static function () use ($container) : Data {
47
            return new $container['serializer.data.class'];
48
        };
49
50
        $container['filesystem'] = static function (): Filesystem {
51
            return new Filesystem();
52
        };
53
54
        $container['storage'] = static function () use ($container) : Write {
55
            return new Storage(
56
                'output', $container['filesystem'], $container['serializer.content'],
57
                $container['serializer.front-matter'], $container['serializer.data']
58
            );
59
        };
60
61
        $container['handler.config'] = static function () use ($container) : Config {
62
            return new Config($container['storage']);
63
        };
64
65
        $container['handler.author'] = static function () use ($container) : Handler {
66
            return new Author($container['storage']);
67
        };
68
69
        $container['handler.term'] = static function () use ($container) : Handler {
70
            return new Term($container['storage'], $container['handler.config']);
71
        };
72
73
        $container['handler.post'] = static function () use ($container) : Handler {
74
            return new Post($container['storage']);
75
        };
76
77
        $container['processor'] = static function () use ($container) : Processor {
78
            $processor = new Processor();
79
            $config    = $container['handler.config'];
80
            $term      = $container['handler.term'];
81
82
            $processor->addHandler('title', $config);
83
            $processor->addHandler('description', $config);
84
            $processor->addHandler('link', $config);
85
            $processor->addHandler('author', $container['handler.author']);
86
            $processor->addHandler('category', $term);
87
            $processor->addHandler('tag', $term);
88
            $processor->addHandler('term', $term);
89
            $processor->addHandler('item', $container['handler.post']);
90
91
            return $processor;
92
        };
93
94
        $container['command.import'] = static function () use ($container) : Import {
95
            return new Import($container);
96
        };
97
    }
98
}
99