• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

michalsn / codeigniter-htmx / 13707691824

06 Mar 2025 08:36PM UTC coverage: 74.783%. First build
13707691824

Pull #83

github

web-flow
Merge 7f79fbae7 into 2ec7f6426
Pull Request #83: chore: update workflow to support PHP 8.4

17 of 22 new or added lines in 6 files covered. (77.27%)

258 of 345 relevant lines covered (74.78%)

7.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/src/Format/HTMLFormatter.php
1
<?php
2

3
namespace Michalsn\CodeIgniterHtmx\Format;
4

5
use CodeIgniter\Format\FormatterInterface;
6
use CodeIgniter\View\Table;
7

8
/**
9
 * HTML data formatter
10
 */
11
class HTMLFormatter implements FormatterInterface
12
{
13
    /**
14
     * Takes the given data and formats it.
15
     *
16
     * @param array|string|null $data
17
     */
18
    public function format($data): string
19
    {
20
        if ($data === null || $data === '' || $data === []) {
4✔
21
            return '';
1✔
22
        }
23

24
        if (is_array($data)) {
3✔
25
            if (array_keys($data) === ['status', 'error', 'messages']) {
2✔
26
                if (isset($data['messages']['error']) && count($data['messages']) === 1) {
2✔
27
                    return $data['messages']['error'];
1✔
28
                }
29

30
                $data = $data['messages'];
1✔
31
            }
32

33
            $data = $this->formatTable($data);
1✔
34
        }
35

36
        return $data;
2✔
37
    }
38

39
    /**
40
     * Format data as a table.
41
     *
42
     * @param mixed $data
43
     */
44
    protected function formatTable($data): string
45
    {
46
        if (isset($data[0]) && count($data) !== count($data, COUNT_RECURSIVE)) {
1✔
47
            // Multi-dimensional array
48
            $headings = array_keys($data[0]);
×
49
        } else {
50
            // Single array
51
            $headings = array_keys($data);
1✔
52
            $data     = [$data];
1✔
53
        }
54

55
        $table = new Table();
1✔
56
        $table->setHeading($headings);
1✔
57

58
        foreach ($data as $row) {
1✔
59
            // Suppressing the "array to string conversion" notice
60
            // Keep the "evil" @ here
61
            $row = @array_map('strval', $row);
1✔
62

63
            $table->addRow($row);
1✔
64
        }
65

66
        return $table->generate();
1✔
67
    }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc