public static function detectCmdLocation(string $cmd, string $path = '', array $optionalLocations = []) : string
    {
        $detectionSteps = [
            function($cmd) use ($path) {
                if (!empty($path)) {
                    return self::detectCmdLocationInPath($cmd, $path);
                }
                return '';
            },
            function($cmd) {
                return self::detectCmdLocationWithWhich($cmd);
            },
            function($cmd) {
                $paths = explode(PATH_SEPARATOR, self::getEnvPath());
                return self::detectCmdLocationInPaths($cmd, $paths);
            },
            function($cmd) use ($optionalLocations) {
                return self::detectCmdLocationInPaths($cmd, $optionalLocations);
            }
        ];

        foreach ($detectionSteps as $step) {
            $bin = $step($cmd);
            if (!empty($bin)) {
                return $bin;
            }
        }

        throw new RuntimeException(sprintf('\'%s\' was nowhere to be found please specify the correct path', $cmd));
    }