Completed
Push — master ( b0c954...91157d )
by Matt
04:29
created

MarkdownService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Service;
4
5
use Delight\Str\Str;
0 ignored issues
show
Bug introduced by
The type Delight\Str\Str was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
7
use Psr\Log\LoggerInterface;
8
use Symfony\Contracts\Cache\CacheInterface;
9
use Symfony\Contracts\Cache\ItemInterface;
10
use Symfony\Contracts\Cache\TagAwareCacheInterface;
11
12
class MarkdownService
13
{
14
    /** @var TagAwareCacheInterface */
15
    private $cache;
16
17
    /** @var MarkdownParserInterface */
18
    private $markdownParser;
19
20
    /** @var LoggerInterface */
21
    private $logger;
22
23
    public function __construct(
24
        TagAwareCacheInterface $cache,
25
        MarkdownParserInterface $markdownParserInterface,
26
        LoggerInterface $logger
27
        )
28
    {
29
        $this->cache = $cache;
30
        $this->markdownParser = $markdownParserInterface;
31
        $this->logger = $logger;
32
    }
33
34
    public function markdownToText(?string $markdown): string
35
    {
36
        if ($markdown === null || $markdown === '') {
37
            return '';
38
        }
39
        $key = 'md_' . md5($markdown);
40
        return $this->cache->get($key, function(ItemInterface $item) use ($markdown) {
41
            $item->tag('markdown_text');
42
            return strip_tags($this->markdownParser->transformMarkdown($markdown));
43
        });
44
    }
45
}
46