1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of phpDocumentor. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @link https://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Guides\NodeRenderers\LaTeX; |
15
|
|
|
|
16
|
|
|
use InvalidArgumentException; |
17
|
|
|
use phpDocumentor\Guides\NodeRenderers\NodeRenderer; |
18
|
|
|
use phpDocumentor\Guides\NodeRenderers\NodeRendererFactory; |
19
|
|
|
use phpDocumentor\Guides\Nodes\Node; |
20
|
|
|
use phpDocumentor\Guides\Nodes\SpanNode; |
21
|
|
|
use phpDocumentor\Guides\Nodes\TableNode; |
22
|
|
|
use function count; |
23
|
|
|
use function get_class; |
24
|
|
|
use function implode; |
25
|
|
|
use function max; |
26
|
|
|
|
27
|
|
|
class TableNodeRenderer implements NodeRenderer |
28
|
|
|
{ |
29
|
|
|
/** @var NodeRendererFactory */ |
30
|
|
|
private $nodeRendererFactory; |
31
|
|
|
|
32
|
|
|
public function __construct(NodeRendererFactory $nodeRendererFactory) |
33
|
|
|
{ |
34
|
|
|
$this->nodeRendererFactory = $nodeRendererFactory; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function render(Node $node) : string |
38
|
|
|
{ |
39
|
|
|
if ($node instanceof TableNode === false) { |
40
|
|
|
throw new InvalidArgumentException('Invalid node presented'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$cols = 0; |
44
|
|
|
|
45
|
|
|
$rows = []; |
46
|
|
|
foreach ($node->getData() as $row) { |
47
|
|
|
$rowTex = ''; |
48
|
|
|
$cols = max($cols, count($row->getColumns())); |
49
|
|
|
|
50
|
|
|
/** @var SpanNode $col */ |
51
|
|
|
foreach ($row->getColumns() as $n => $col) { |
52
|
|
|
$rowTex .= $this->nodeRendererFactory->get(get_class($col))->render($col); |
|
|
|
|
53
|
|
|
|
54
|
|
|
if ((int) $n + 1 >= count($row->getColumns())) { |
55
|
|
|
continue; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$rowTex .= ' & '; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$rowTex .= ' \\\\' . "\n"; |
62
|
|
|
$rows[] = $rowTex; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$aligns = []; |
66
|
|
|
for ($i = 0; $i < $cols; $i++) { |
67
|
|
|
$aligns[] = 'l'; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$aligns = '|' . implode('|', $aligns) . '|'; |
71
|
|
|
$rows = "\\hline\n" . implode("\\hline\n", $rows) . "\\hline\n"; |
72
|
|
|
|
73
|
|
|
return "\\begin{tabular}{" . $aligns . "}\n" . $rows . "\n\\end{tabular}\n"; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: