<commit_before><?php

namespace Vanthink\Modules\Helper;

use Vanthink\Modules\Modules;
use Illuminate\Http\Request;

class Helper
{
    public function getVersion(Request $request, Modules $modules, $module_name)
    {
        $version  = $request->header('version');
        $versions = $modules->get($module_name.'::version');
        if (!in_array($version, $versions)) {
            $r_versions = array_reverse($versions);
            if (!$version) {
                $version = $r_versions[0];
            } else {
                for ($i = 0; $i < count($r_versions); $i++) {
                    if (version_compare($version, $r_versions[$i], '<')) {
                        continue;
                    }
                    $version = $r_versions[$i];
                    break;
                }
                if (!in_array($version, $versions)) {
                    $version = $versions[0];
                }
            }
        }
        $version = str_replace('.', '_', $version);
        return $version;
    }
    
    public function getAvailableVersion(Request $request, Modules $modules, $router, $module_name, $namespase)
    {
        $version  = $request->header('version');
        $versions = $modules->get($module_name.'::version');
        
        $r_versions = array_reverse($versions);
        if (!$version) {
            $version = $r_versions[0];
        }
        for ($i = 0; $i < count($r_versions); $i++) {
            if (version_compare($version, $r_versions[$i], '<')) {
                continue;
            }
            $version = $r_versions[$i];
            if (!$this->checkActionExists($request, $router, $namespase.'\v'.str_replace('.', '_', $version))) {
                continue;
            }
            break;
        }
        if (!in_array($version, $versions)) {
            $version = $versions[0];
        }
        $version = str_replace('.', '_', $version);
        return $version;
    }
    
    public function checkActionExists($request, $router, $namespace)
    {
        try {
            $action_name = $router->getRoutes()->match($request)->getActionName();
        } catch (\Exception $e) {
            return false;
        }
        list($controller, $action) = explode('@', $action_name);
        return method_exists($namespace.'\\'.$controller, $action);
    }
}<commit_msg>Fix release bug<commit_after><?php

namespace Vanthink\Modules\Helper;

use Illuminate\Http\Request;
use Vanthink\Modules\Modules;

class Helper
{
    public function getVersion(Request $request, Modules $modules, $module_name)
    {
        $version  = $request->header('version');
        $versions = $modules->get($module_name.'::version');
        if (!in_array($version, $versions)) {
            $r_versions = array_reverse($versions);
            if (!$version) {
                $version = $r_versions[0];
            } else {
                for ($i = 0; $i < count($r_versions); $i++) {
                    if (version_compare($version, $r_versions[$i], '<')) {
                        continue;
                    }
                    $version = $r_versions[$i];
                    break;
                }
                if (!in_array($version, $versions)) {
                    $version = $versions[0];
                }
            }
        }
        $version = str_replace('.', '_', $version);
        return $version;
    }

    public function getAvailableVersion(Request $request, Modules $modules, $router, $module_name, $namespase)
    {
        $version  = $request->header('version');
        $versions = $modules->get($module_name.'::version');

        $r_versions = array_reverse($versions);
        if (!$version) {
            $version = $r_versions[0];
        }
        for ($i = 0; $i < count($r_versions); $i++) {
            if (version_compare($version, $r_versions[$i], '<')) {
                continue;
            }
            $version = $r_versions[$i];
            if (!$this->checkActionExists($request, $router, $namespase.'\v'.str_replace('.', '_', $version))) {
                continue;
            }
            break;
        }
        if (!in_array($version, $versions)) {
            $version = $versions[0];
        }
        $version = str_replace('.', '_', $version);
        return $version;
    }

    public function checkActionExists($request, $router, $namespace)
    {
        try {
            $action_name = $router->getRoutes()->match($request)->getActionName();
        } catch (\Exception $e) {
            return false;
        }
        list($controller, $action) = explode('@', $action_name);
        return method_exists($namespace.'\\'.$controller, $action);
    }
}
{'fraction_non_alphanumeric': 0.1582089552238806, 'fraction_numerical': 0.00255863539445629, 'mean_word_length': 1.7939249553305538, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3671652', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1297, 'n_words': 244}