Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Platform
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 isWindows
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getBinary
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * Karla Imagemagick wrapper library
5 *
6 * PHP Version 8.0<
7 *
8 * @category Utility
9 * @author   Johannes Skov Frandsen <jsf@greenoak.dk>
10 * @license  http://www.opensource.org/licenses/mit-license.php MIT
11 * @link     https://github.com/localgod/karla Karla
12 * @since    2026-03-25
13 */
14
15declare(strict_types=1);
16
17namespace Karla;
18
19/**
20 * Platform utility class for OS detection
21 *
22 * Centralises OS detection logic using the modern PHP_OS_FAMILY constant,
23 * replacing the scattered `strtoupper(substr(PHP_OS, 0, 3)) == "WIN"` pattern.
24 *
25 * @category Utility
26 * @author   Johannes Skov Frandsen <jsf@greenoak.dk>
27 * @license  http://www.opensource.org/licenses/mit-license.php MIT
28 * @link     https://github.com/localgod/karla Karla
29 */
30class Platform
31{
32    /**
33     * Determine whether the current OS is Windows.
34     *
35     * Uses PHP_OS_FAMILY (available since PHP 7.2) which returns 'Windows' on
36     * all Windows variants, making the check both readable and reliable.
37     */
38    public static function isWindows(): bool
39    {
40        return PHP_OS_FAMILY === 'Windows';
41    }
42
43    /**
44     * Return the platform-appropriate binary name.
45     *
46     * On Windows the `.exe` extension is appended; on all other platforms the
47     * name is returned unchanged.
48     *
49     * @param string $binary Base binary name (e.g. 'convert', 'magick')
50     *
51     * @return string Binary name suitable for the current platform
52     */
53    public static function getBinary(string $binary): string
54    {
55        return self::isWindows() ? $binary . '.exe' : $binary;
56    }
57}