Issues (12)

src/bootstrap.php (1 issue)

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 22 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\WCWidth;
6
7
use AlecRabbit\WCWidth\Kernel\UCode;
8
use AlecRabbit\WCWidth\Kernel\UnicodeVersion;
9
use Throwable;
10
11
use function function_exists;
12
13
if ($version = getenv('UNICODE_VERSION')) {
14
    try {
15
        UnicodeVersion::set($version);
16
    } catch (Throwable $_) {
17
        // silently ignore
18
    }
19
}
20
21
if (!function_exists(__NAMESPACE__ . '\ffiEnabled')) {
22
    function ffiEnabled(): bool
23
    {
24
        return
25
            match (getenv('USE_FFI')) {
26
                '1', 'true', 'yes', 'on' => true,
27
                default => false,
28
            };
29
    }
30
}
31
32
if (!function_exists(__NAMESPACE__ . '\wcwidth')) {
33
    if (extension_loaded('ffi') && ffiEnabled()) {
34
        function wcwidth(string $wc, ?string $version = null): int
35
        {
36
            return UCode::ffi_wcwidth($wc, $version);
37
        }
38
    } else {
39
        function wcwidth(string $wc, ?string $version = null): int
40
        {
41
            return UCode::wcwidth($wc, $version);
42
        }
43
    }
44
}
45
46
if (!function_exists(__NAMESPACE__ . '\wcswidth')) {
47
    function wcswidth(?string $subject, ?int $n = null, ?string $version = null): int
48
    {
49
        if (null === $subject) {
50
            return 0;
51
        }
52
        return UCode::wcswidth($subject, $n, $version);
53
    }
54
}
55