Passed
Push — main ( 057518...00c1b7 )
by Colin
02:29 queued 26s
created

TableExtension::configureSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This is part of the league/commonmark package.
7
 *
8
 * (c) Martin Hasoň <[email protected]>
9
 * (c) Webuni s.r.o. <[email protected]>
10
 * (c) Colin O'Dell <[email protected]>
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 */
15
16
namespace League\CommonMark\Extension\Table;
17
18
use League\CommonMark\Environment\EnvironmentBuilderInterface;
19
use League\CommonMark\Extension\ConfigurableExtensionInterface;
20
use League\CommonMark\Renderer\HtmlDecorator;
21
use League\Config\ConfigurationBuilderInterface;
22
use Nette\Schema\Expect;
23
24
final class TableExtension implements ConfigurableExtensionInterface
25
{
26 128
    public function configureSchema(ConfigurationBuilderInterface $builder): void
27
    {
28 128
        $builder->addSchema('table', Expect::structure([
29 128
            'wrap' => Expect::structure([
30 128
                'enabled' => Expect::bool()->default(false),
31 128
                'tag' => Expect::string()->default('div'),
32 128
                'attributes' => Expect::arrayOf(Expect::string()),
33
            ]),
34
        ]));
35 128
    }
36
37 128
    public function register(EnvironmentBuilderInterface $environment): void
38
    {
39 128
        $tableRenderer = new TableRenderer();
40 128
        if ($environment->getConfiguration()->get('table/wrap/enabled')) {
41 2
            $tableRenderer = new HtmlDecorator($tableRenderer, $environment->getConfiguration()->get('table/wrap/tag'), $environment->getConfiguration()->get('table/wrap/attributes'));
42
        }
43
44
        $environment
45 128
            ->addBlockStartParser(new TableStartParser())
46
47 128
            ->addRenderer(Table::class, $tableRenderer)
48 128
            ->addRenderer(TableSection::class, new TableSectionRenderer())
49 128
            ->addRenderer(TableRow::class, new TableRowRenderer())
50 128
            ->addRenderer(TableCell::class, new TableCellRenderer());
51 128
    }
52
}
53