<commit_before><?php

namespace ZfModule\Service;

use EdpGithub\Client;
use EdpGithub\Collection\RepositoryCollection;
use EdpGithub\Http\Client as HttpClient;
use stdClass;
use Zend\Http;
use ZfcBase\EventManager\EventProvider;
use ZfModule\Entity;
use ZfModule\Mapper;

class Module extends EventProvider
{
    /**
     * @var Mapper\Module
     */
    private $moduleMapper;

    /**
     * @var Client
     */
    private $githubClient;

    /**
     * @param Mapper\Module $moduleMapper
     * @param Client $githubClient
     */
    public function __construct(Mapper\Module $moduleMapper, Client $githubClient)
    {
        $this->moduleMapper = $moduleMapper;
        $this->githubClient = $githubClient;
    }

    /**
     * @param stdClass $data
     * @return object|Entity\Module
     */
    public function register($data)
    {
        $module = $this->moduleMapper->findByUrl($data->html_url);

        $update = true;
        if (!$module) {
            $module  = new Entity\Module();
            $update = false;
        }

        $module->setName($data->name);
        $module->setDescription($data->description);
        $module->setUrl($data->html_url);
        $module->setOwner($data->owner->login);
        $module->setPhotoUrl($data->owner->avatar_url);

        if ($update) {
            $this->moduleMapper->update($module);
        } else {
            $this->moduleMapper->insert($module);
        }

        return $module;
    }

    /**
     * Check if Repo is a ZF Module
     *
     * @param stdClass $repository
     * @return bool
     */
    public function isModule(stdClass $repository)
    {
        $query = sprintf(
            'repo:%s/%s filename:Module.php "class Module"',
            $repository->owner->login,
            $repository->name
        );

        $path = sprintf(
            'search/code?q=%s',
            $query
        );

        /* @var HttpClient $httpClient */
        $httpClient = $this->githubClient->getHttpClient();

        /* @var Http\Response $response */
        $response = $httpClient->request($path);

        $result = json_decode($response->getBody(), true);

        if (isset($result['total_count']) && $result['total_count'] > 0) {
            return true;
        }

        return false;
    }

    /**
     * @param $limit
     * @return Entity\Module[]
     */
    public function allModules($limit = null)
    {
        return $this->moduleMapper->findAll(
            $limit,
            'created_at',
            'DESC'
        );
    }

    /**
     * @return Entity\Module[]
     */
    public function currentUserModules()
    {
        /* @var RepositoryCollection $repositoryCollection */
        $repositoryCollection = $this->githubClient->api('current_user')->repos([
            'type' => 'all',
            'per_page' => 100,
        ]);

        $modules = [];

        foreach ($repositoryCollection as $repository) {
            if (true === $repository->fork) {
                continue;
            }

            if (false === $repository->permissions->push) {
                continue;
            }

            $module = $this->moduleMapper->findByName($repository->name);
            if (!($module instanceof Entity\Module)) {
                continue;
            }

            array_push($modules, $module);
        }

        return $modules;
    }
}
<commit_msg>Enhancement: Rename parameter<commit_after><?php

namespace ZfModule\Service;

use EdpGithub\Client;
use EdpGithub\Collection\RepositoryCollection;
use EdpGithub\Http\Client as HttpClient;
use stdClass;
use Zend\Http;
use ZfcBase\EventManager\EventProvider;
use ZfModule\Entity;
use ZfModule\Mapper;

class Module extends EventProvider
{
    /**
     * @var Mapper\Module
     */
    private $moduleMapper;

    /**
     * @var Client
     */
    private $githubClient;

    /**
     * @param Mapper\Module $moduleMapper
     * @param Client $githubClient
     */
    public function __construct(Mapper\Module $moduleMapper, Client $githubClient)
    {
        $this->moduleMapper = $moduleMapper;
        $this->githubClient = $githubClient;
    }

    /**
     * @param stdClass $repository
     * @return Entity\Module
     */
    public function register($repository)
    {
        $module = $this->moduleMapper->findByUrl($repository->html_url);

        $update = true;
        if (!$module) {
            $module  = new Entity\Module();
            $update = false;
        }

        $module->setName($repository->name);
        $module->setDescription($repository->description);
        $module->setUrl($repository->html_url);
        $module->setOwner($repository->owner->login);
        $module->setPhotoUrl($repository->owner->avatar_url);

        if ($update) {
            $this->moduleMapper->update($module);
        } else {
            $this->moduleMapper->insert($module);
        }

        return $module;
    }

    /**
     * Check if Repo is a ZF Module
     *
     * @param stdClass $repository
     * @return bool
     */
    public function isModule(stdClass $repository)
    {
        $query = sprintf(
            'repo:%s/%s filename:Module.php "class Module"',
            $repository->owner->login,
            $repository->name
        );

        $path = sprintf(
            'search/code?q=%s',
            $query
        );

        /* @var HttpClient $httpClient */
        $httpClient = $this->githubClient->getHttpClient();

        /* @var Http\Response $response */
        $response = $httpClient->request($path);

        $result = json_decode($response->getBody(), true);

        if (isset($result['total_count']) && $result['total_count'] > 0) {
            return true;
        }

        return false;
    }

    /**
     * @param $limit
     * @return Entity\Module[]
     */
    public function allModules($limit = null)
    {
        return $this->moduleMapper->findAll(
            $limit,
            'created_at',
            'DESC'
        );
    }

    /**
     * @return Entity\Module[]
     */
    public function currentUserModules()
    {
        /* @var RepositoryCollection $repositoryCollection */
        $repositoryCollection = $this->githubClient->api('current_user')->repos([
            'type' => 'all',
            'per_page' => 100,
        ]);

        $modules = [];

        foreach ($repositoryCollection as $repository) {
            if (true === $repository->fork) {
                continue;
            }

            if (false === $repository->permissions->push) {
                continue;
            }

            $module = $this->moduleMapper->findByName($repository->name);
            if (!($module instanceof Entity\Module)) {
                continue;
            }

            array_push($modules, $module);
        }

        return $modules;
    }
}

{'fraction_non_alphanumeric': 0.13794113340166936, 'fraction_numerical': 0.0011714745936447504, 'mean_word_length': 1.8830730265934994, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 87, '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': '1781989', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1872, 'n_words': 362}