<commit_before><?php

namespace User\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;

class ModuleController extends AbstractActionController
{
    public function orgsAction()
    {
        $org = $this->params()->fromRoute('org');

        $sm = $this->getServiceLocator();
        $client = $sm->get('EdpGithub\Client');
        $mapper = $sm->get('application_module_mapper');

        $repos = $client->api('user')->repos($org);
        $repositories = array();
        foreach($repos as $repo) {
            if(!$repo->fork) {
                $module = $mapper->findByName($repo->name);
                if(!$module && $this->isModule($repo)) {
                   $repositories[] = $repo;
                }
            }
        }

        $viewModel = new ViewModel(array('repositories' => $repositories));
        $viewModel->setTerminal(true);
        return $viewModel;
    }

    public function reposAction()
    {
        if (!$this->zfcUserAuthentication()->hasIdentity()) {
            return $this->redirect()->toRoute('zfcuser/login');
        }

        $sm = $this->getServiceLocator();
        $client = $sm->get('EdpGithub\Client');
        $mapper = $sm->get('application_module_mapper');

        $repositories = array();

        $ownerRepos = $client->api('current_user')->repos(array('type' =>'all', 'per_page' => 100));
        foreach($ownerRepos as $repo) {
            if(!$repo->fork) {
                 $module = $mapper->findByName($repo->name);
                if(!$module && $this->isModule($repo)) {
                   $repositories[] = $repo;
                }
            }
        }
        $viewModel = new ViewModel(array('repositories' => $repositories));
        $viewModel->setTerminal(true);
        return $viewModel;
    }

    /**
     * Check if Repo is a ZF Module
     * @param  array  $repo
     * @return boolean
     */
    public function isModule($repo)
    {
        $sm = $this->getServiceLocator();
        $client = $sm->get('EdpGithub\Client');
        $em = $client->getHttpClient()->getEventManager();
        $errorListener = $sm->get('EdpGithub\Listener\Error');
        $em->detachAggregate($errorListener);
        $module = $client->api('repos')->content($repo->owner->login, $repo->name, 'Module.php');
        $module = $client->api('repos')->content($repo->owner->login, $repo->name, 'Module.php');
        $response = $client->getHttpClient()->getResponse();
        $em->attachAggregate($errorListener);
        if(!$response->isSuccess()){
            return false;
        }

        return true;
    }
}<commit_msg>Improved Performance....<commit_after><?php

namespace User\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;

class ModuleController extends AbstractActionController
{
    public function orgsAction()
    {
        $org = $this->params()->fromRoute('org');

        $sm = $this->getServiceLocator();
        $client = $sm->get('EdpGithub\Client');
        $mapper = $sm->get('application_module_mapper');

        $repos = $client->api('user')->repos($org);
        $repositories = array();
        foreach($repos as $repo) {
            if(!$repo->fork) {
                $module = $mapper->findByName($repo->name);
                if(!$module && $this->isModule($repo)) {
                   $repositories[] = $repo;
                }
            }
        }

        $viewModel = new ViewModel(array('repositories' => $repositories));
        $viewModel->setTerminal(true);
        return $viewModel;
    }

    public function reposAction()
    {
        if (!$this->zfcUserAuthentication()->hasIdentity()) {
            return $this->redirect()->toRoute('zfcuser/login');
        }

        $sm = $this->getServiceLocator();
        $client = $sm->get('EdpGithub\Client');
        $mapper = $sm->get('application_module_mapper');

        $repositories = array();

        $ownerRepos = $client->api('current_user')->repos(array('type' =>'all', 'per_page' => 100));
        foreach($ownerRepos as $repo) {
            if(!$repo->fork) {
                 $module = $mapper->findByName($repo->name);
                if(!$module && $this->isModule($repo)) {
                   $repositories[] = $repo;
                }
            }
        }
        $viewModel = new ViewModel(array('repositories' => $repositories));
        $viewModel->setTerminal(true);
        return $viewModel;
    }

    /**
     * Check if Repo is a ZF Module
     * @param  array  $repo
     * @return boolean
     */
    public function isModule($repo)
    {
        $sm = $this->getServiceLocator();
        $client = $sm->get('EdpGithub\Client');
        $em = $client->getHttpClient()->getEventManager();
        $errorListener = $sm->get('EdpGithub\Listener\Error');
        $em->detachAggregate($errorListener);
        $module = $client->api('repos')->content($repo->owner->login, $repo->name, 'Module.php');
        $response = $client->getHttpClient()->getResponse();
        $em->attachAggregate($errorListener);
        if(!$response->isSuccess()){
            return false;
        }

        return true;
    }
}
{'fraction_non_alphanumeric': 0.17133600152468076, 'fraction_numerical': 0.0011435105774728416, 'mean_word_length': 2.2861615529117096, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 98, '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': '2646930', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1512, 'n_words': 241}