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

ducks-project / encoding-repair / 21228444070

21 Jan 2026 10:45PM UTC coverage: 75.976% (+4.7%) from 71.26%
21228444070

push

github

donaldinou
feat : add object oriented transcoders

97 of 127 new or added lines in 6 files covered. (76.38%)

253 of 333 relevant lines covered (75.98%)

7.94 hits per line

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

11.76
/Transcoder/IconvTranscoder.php
1
<?php
2

3
/**
4
 * Part of EncodingRepair package.
5
 *
6
 * (c) Adrien Loyant <donald_duck@team-df.org>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Ducks\Component\EncodingRepair\Transcoder;
15

16
/**
17
 * Iconv-based transcoder (requires ext-iconv).
18
 *
19
 * @final
20
 */
21
final class IconvTranscoder implements TranscoderInterface
22
{
23
    /**
24
     * @inheritDoc
25
     */
NEW
26
    public function transcode(string $data, string $to, string $from, ?array $options = null): ?string
×
27
    {
NEW
28
        if (!$this->isAvailable()) {
×
NEW
29
            return null;
×
30
        }
31

NEW
32
        $suffix = $this->buildSuffix($options ?? []);
×
33

34
        // Use silence operator (@) instead of
35
        // \set_error_handler(static fn (): bool => true);
36
        // set_error_handler is too expensive for high-volume loops.
NEW
37
        $result = @\iconv($from, $to . $suffix, $data);
×
38

NEW
39
        return false !== $result ? $result : null;
×
40
    }
41

42
    /**
43
     * @inheritDoc
44
     */
45
    public function getPriority(): int
19✔
46
    {
47
        return 50;
19✔
48
    }
49

50
    /**
51
     * @inheritDoc
52
     */
NEW
53
    public function isAvailable(): bool
×
54
    {
NEW
55
        return \function_exists('iconv');
×
56
    }
57

58
    /**
59
     * Build iconv suffix from options.
60
     *
61
     * @param array<string, mixed> $options Conversion options
62
     *
63
     * @return string Suffix string
64
     */
NEW
65
    private function buildSuffix(array $options): string
×
66
    {
NEW
67
        $suffix = '';
×
68

NEW
69
        if (true === ($options['translit'] ?? true)) {
×
NEW
70
            $suffix .= '//TRANSLIT';
×
71
        }
72

NEW
73
        if (true === ($options['ignore'] ?? true)) {
×
NEW
74
            $suffix .= '//IGNORE';
×
75
        }
76

NEW
77
        return $suffix;
×
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc