Completed
Push — master ( 83739a...a13ee4 )
by Colin
14s queued 11s
created

src/Extension/Table/TableCellRenderer.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Block\Element\AbstractBlock;
19
use League\CommonMark\Block\Renderer\BlockRendererInterface;
20
use League\CommonMark\ElementRendererInterface;
21
use League\CommonMark\HtmlElement;
22
23
final class TableCellRenderer implements BlockRendererInterface
24
{
25 69
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
26
    {
27 69
        if (!$block instanceof TableCell) {
28
            throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
29
        }
30
31 69
        $attrs = $block->getData('attributes', []);
32
33 69
        if ($block->align) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $block->align of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
34 12
            $attrs['align'] = $block->align;
35
        }
36
37 69
        return new HtmlElement($block->type, $attrs, $htmlRenderer->renderInlines($block->children()));
38
    }
39
}
40