<commit_before><?php
declare(strict_types=1);

namespace ManaPHP\Commands;

use ManaPHP\Helper\LocalFS;
use ReflectionClass;
use ReflectionMethod;

class RpcCommand extends \ManaPHP\Cli\Command
{
    /**
     * generate services stub for client
     *
     * @param string $output
     *
     * @return void
     * @throws \ManaPHP\Exception\RuntimeException
     */
    public function servicesAction(string $output = '@tmp/rpc_services'): void
    {
        foreach (LocalFS::glob('@app/Controllers/?*Controller.php') as $file) {
            $className = 'App\\Controllers\\' . basename($file, '.php');

            $methods = [];
            foreach (get_class_methods($className) as $method) {
                if (preg_match('#^(.*)Action$#', $method, $match)) {
                    $methods[] = $method;
                }
            }

            if ($methods !== []) {
                $content = $this->renderService($className, $methods);
                $file = rtrim($output, '/') . '/' . basename($className, 'Controller') . 'Service.php';
                LocalFS::filePut($file, $content);

                $serviceName = basename($className, 'Controller') . 'Service';
                $this->console->writeLn("`$serviceName` saved to `$file`");
            }
        }
    }

    /**
     * @param string $class<commit_msg>fix Unused local variable 'match'. The value of the variable is not used anywhere.<commit_after><?php
declare(strict_types=1);

namespace ManaPHP\Commands;

use ManaPHP\Helper\LocalFS;
use ReflectionClass;
use ReflectionMethod;

class RpcCommand extends \ManaPHP\Cli\Command
{
    /**
     * generate services stub for client
     *
     * @param string $output
     *
     * @return void
     * @throws \ManaPHP\Exception\RuntimeException
     */
    public function servicesAction(string $output = '@tmp/rpc_services'): void
    {
        foreach (LocalFS::glob('@app/Controllers/?*Controller.php') as $file) {
            $className = 'App\\Controllers\\' . basename($file, '.php');

            $methods = [];
            foreach (get_class_methods($className) as $method) {
                if (str_ends_with('Action', $method)) {
                    $methods[] = $method;
                }
            }

            if ($methods !== []) {
                $content = $this->renderService($className, $methods);
                $file = rtrim($output, '/') . '/' . basename($className, 'Controller') . 'Service.php';
                LocalFS::filePut($file, $content);

                $serviceName = basename($className, 'Controller') . 'Service';
                $this->console->writeLn("`$serviceName` saved to `$file`");
            }
        }
    }

    /**
     * @param string $class
{'fraction_non_alphanumeric': 0.15164835164835164, 'fraction_numerical': 0.0007326007326007326, 'mean_word_length': 2.117579908675799, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6695161', 'n_tokens_mistral': 789, 'n_tokens_neox': 765, 'n_words': 159}