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

GeneralRuntime::markdownToPlainText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Twig;
4
5
use App\Service\MarkdownService;
6
use ByteUnits\Binary;
7
use ByteUnits\Metric;
8
use DateInterval;
9
use DateTime;
10
use Twig\Extension\RuntimeExtensionInterface;
11
12
class GeneralRuntime implements RuntimeExtensionInterface
13
{
14
    /** @var $markdownService */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $markdownService at position 0 could not be parsed: Unknown type name '$markdownService' at position 0 in $markdownService.
Loading history...
15
    private $markdownService;
16
17
    public function __construct(MarkdownService $markdownService)
18
    {
19
        $this->markdownService = $markdownService;
20
    }
21
22
    public function durationToHMS(?DateInterval $interval): string
23
    {
24
        if (!isset($interval))
25
            return "";
26
27
        return $interval->format('%H:%I:%S');
28
    }
29
30
    public function starRating(?int $rating): string
31
    {
32
        if (is_int($rating) && $rating >= 0) {
33
            return str_repeat('★', $rating);
34
        }
35
        return "-";
36
    }
37
38
    public function formatMetricBytes(int $bytes, string $format = null): string
39
    {
40
        return Metric::bytes($bytes)->format($format);
41
    }
42
    public function formatBinaryBytes(int $bytes, string $format = null): string
43
    {
44
        return Binary::bytes($bytes)->format($format);
45
    }
46
    public function markdownToPlainText(?string $markdown): string
47
    {
48
        return $this->markdownService->markdownToText($markdown);
49
    }
50
}