icanhazstring/systemctl-php

View on GitHub
src/Utils/OutputFetcher.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace icanhazstring\SystemCtl\Utils;

/**
 * Class OutputFetcher
 *
 * @package icanhazstring\SystemCtl\Utils
 */
class OutputFetcher
{
    /**
     * Fetch unit names from a command output
     *
     * @param string $suffix
     * @param string $output
     *
     * @return string[]
     */
    public static function fetchUnitNames(string $suffix, string $output): array
    {
        preg_match_all('/^[^[:alnum:]\-_.@]*(?<unit>.*)\.' . $suffix . '\s.*$/m', $output, $matches);
        return $matches['unit'] ?? [];
    }
}