Completed
Push — master ( c814ba...8cfaee )
by Jan
04:18
created

MarkdownParser::markForRendering()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php
2
/**
3
 *
4
 * part-db version 0.1
5
 * Copyright (C) 2005 Christoph Lechner
6
 * http://www.cl-projects.de/
7
 *
8
 * part-db version 0.2+
9
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
10
 * http://code.google.com/p/part-db/
11
 *
12
 * Part-DB Version 0.4+
13
 * Copyright (C) 2016 - 2019 Jan Böhmer
14
 * https://github.com/jbtronics
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
29
 *
30
 */
31
32
namespace App\Services;
33
34
use Symfony\Contracts\Translation\TranslatorInterface;
35
36
/**
37
 * This class allows you to convert markdown text to HTML.
38
 * @package App\Services
39
 */
40
class MarkdownParser
41
{
42
    protected $translator;
43
44
    public function __construct(TranslatorInterface $translator)
45
    {
46
        $this->translator = $translator;
47
    }
48
49
    /**
50
     * Mark the markdown for rendering.
51
     * The rendering of markdown is done on client side
52
     * @param string $markdown The markdown text that should be parsed to html.
53
     * @param bool $inline_mode Only allow inline markdown codes like (*bold* or **italic**), not something like tables
54
     * @return string The markdown in a version that can be parsed on client side.
55
     */
56
    public function markForRendering(string $markdown, bool $inline_mode = false) : string
0 ignored issues
show
Unused Code introduced by
The parameter $inline_mode 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

56
    public function markForRendering(string $markdown, /** @scrutinizer ignore-unused */ bool $inline_mode = false) : string

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...
57
    {
58
        return sprintf(
59
            '<div class="markdown" data-markdown="%s">%s</div>',
60
            htmlspecialchars($markdown),
61
            $this->translator->trans('markdown.loading')
62
        );
63
    }
64
}