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

azjezz / psl / 23094963263

14 Mar 2026 07:40PM UTC coverage: 98.483% (-0.004%) from 98.487%
23094963263

push

github

web-flow
feat(encoding): introduce `Psl\Encoding\QuotedPrintable` (#627)

33 of 34 new or added lines in 4 files covered. (97.06%)

2 existing lines in 1 file now uncovered.

9865 of 10017 relevant lines covered (98.48%)

34.96 hits per line

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

95.65
/src/Psl/Encoding/QuotedPrintable/encode_line.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Encoding\QuotedPrintable;
6

7
use function chr;
8
use function ord;
9
use function strlen;
10

11
/**
12
 * Encode a single line using quoted-printable encoding.
13
 *
14
 * Trailing whitespace is encoded, and soft line breaks are inserted
15
 * to keep lines within $max_line_length (default 76 per RFC 2045).
16
 *
17
 * @param positive-int $max_line_length
18
 * @param non-empty-string $line_ending
19
 */
20
function encode_line(string $line, int $max_line_length = 76, string $line_ending = "\r\n"): string
21
{
22
    if ($line === '') {
30✔
NEW
23
        return '';
×
24
    }
25

26
    $soft_break = '=' . $line_ending;
30✔
27
    $encoded = '';
30✔
28
    $lineLength = 0;
30✔
29
    $len = strlen($line);
30✔
30

31
    for ($i = 0; $i < $len; $i++) {
30✔
32
        $byte = ord($line[$i]);
30✔
33
        $isLast = $i === ($len - 1);
30✔
34

35
        if ($byte === 0x09 || $byte === 0x20) {
30✔
36
            if ($isLast) {
9✔
37
                $char = Internal\encode_octet($byte);
3✔
38
            } else {
39
                $char = chr($byte);
6✔
40
            }
41
        } elseif ($byte >= 33 && $byte <= 126 && $byte !== 61) {
30✔
42
            $char = chr($byte);
24✔
43
        } else {
44
            $char = Internal\encode_octet($byte);
9✔
45
        }
46

47
        $charLen = strlen($char);
30✔
48

49
        if (($lineLength + $charLen) > ($max_line_length - 1)) {
30✔
50
            $encoded .= $soft_break;
9✔
51
            $lineLength = 0;
9✔
52
        }
53

54
        $encoded .= $char;
30✔
55
        $lineLength += $charLen;
30✔
56
    }
57

58
    return $encoded;
30✔
59
}
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