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

sweetrdf / quickRdfIo / #164

18 Mar 2026 01:02PM UTC coverage: 90.776% (-0.05%) from 90.824%
#164

push

php-coveralls

zozlak
NQuadsSerializer: fix graphs handling

1 of 1 new or added line in 1 file covered. (100.0%)

14 existing lines in 2 files now uncovered.

866 of 954 relevant lines covered (90.78%)

6.45 hits per line

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

78.57
/src/quickRdfIo/StreamSkipBomTrait.php
1
<?php
2

3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2024 zozlak.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26

27
namespace quickRdfIo;
28

29
use Psr\Http\Message\StreamInterface;
30

31
/**
32
 * Description of StreamSkipBomTrait
33
 *
34
 * @author zozlak
35
 */
36
trait StreamSkipBomTrait {
37

38
    /** @var array<string, string> */
39
    private array $invalidBoms2B = [
40
        "\xEF\xFF" => "UTF-16 BE",
41
        "\xFF\xFE" => "UTF-16 LE",
42
    ];
43
    /** @var array<string, string> */
44
    private array $invalidBoms3B = [
45
        "\x2B\x2F\x76" => "UTF-7",
46
        "\xF7\x64\x4C" => "UTF-1",
47
        "\x0E\xFE\xFF" => "SCSU",
48
        "\xFB\xEE\x28" => "BOCU-1",
49
    ];
50
    /** @var array<string, string> */
51
    private array $invalidBoms4B = [
52
        "\x00\x00\xFE\xFF" => "UTF-32 BE",
53
        "\xFF\xFE\x00\x00" => "UTF-32 LE",
54
        "\xDD\x73\x66\x73" => "UTF-EBCDIC",
55
        "\x84\x31\x95\x33" => "GB18030",
56
    ];
57
    private string $bomUtf8 = "\xEF\xBB\xBF";
58

59
    private function skipBom(StreamInterface $stream): void {
60
        if ($stream->isSeekable()) {
30✔
61
            $bom = $stream->read(4);
30✔
62
            if (isset($this->invalidBoms4B[$bom])) {
30✔
UNCOV
63
                throw new RdfIoException("Input stream has wrong encoding " . $this->invalidBoms4B[$bom]);
×
64
            }
65
            $bom = substr($bom, 0, 3);
30✔
66
            if ($bom === $this->bomUtf8) {
30✔
67
                $stream->seek(-1, SEEK_CUR);
2✔
68
                return;
2✔
69
            }
70
            if (isset($this->invalidBoms3B[$bom])) {
28✔
UNCOV
71
                throw new RdfIoException("Input stream has wrong encoding " . $this->invalidBoms3B[$bom]);
×
72
            }
73
            $bom = substr($bom, 0, 2);
28✔
74
            if (isset($this->invalidBoms2B[$bom])) {
28✔
UNCOV
75
                throw new RdfIoException("Input stream has wrong encoding " . $this->invalidBoms2B[$bom]);
×
76
            }
77
            // no BOM recognized - rewind
78
            $stream->seek(-4, SEEK_CUR);
28✔
79
        }
80
    }
81
}
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

© 2026 Coveralls, Inc