Exakat\Tasks\Phploc::run PHP Метод

run() публичный Метод

public run ( )
    public function run()
    {
        $loc = array('files' => 0, 'total' => 0, 'tokens' => 0, 'comments' => 0, 'code' => 0);
        $project = $this->config->project;
        if ($project != 'default') {
            $projectPath = $this->config->projects_root . '/projects/' . $project;
            if (!file_exists($projectPath)) {
                throw new NoSuchProject($this->config->project);
            }
            if (!file_exists($projectPath . '/datastore.sqlite')) {
                throw new NoDatastore($this->config->project);
            }
            $datastore = new Datastore($this->config);
            $files = $datastore->getCol('files', 'file');
            foreach ($files as $file) {
                $counts = $this->countLocInFile($this->config->projects_root . '/projects/' . $project . '/code' . $file);
                array_add($loc, $counts);
                if ($counts['error'] != self::OK) {
                    $datastore->deleteRow('files', array('file' => $file));
                    $datastore->addRow('ignoredFiles', array(array('file' => $file, 'reason' => $counts['error'])));
                    display("Finally ignoring {$file}\n");
                }
            }
            $this->datastore->addRow('hash', array(array('key' => 'loc', 'value' => $loc['code']), array('key' => 'locTotal', 'value' => $loc['total']), array('key' => 'files', 'value' => $loc['files']), array('key' => 'tokens', 'value' => $loc['tokens'])));
        } elseif (!empty($this->config->dirname)) {
            $dirPath = $this->config->dirname;
            $ignoreDirs = array();
            $ignoreName = array();
            foreach ($this->config->ignore_dirs as $ignore) {
                if ($ignore[0] == '/') {
                    $d = $dirPath . $ignore;
                    if (file_exists($d)) {
                        $ignoreDirs[] = $d;
                    }
                } else {
                    $ignoreName[] = $ignore;
                }
            }
            $files = $this->readRecursiveDir($dirPath, $ignoreName, $ignoreDirs);
            foreach ($files as $file) {
                array_add($loc, $this->countLocInFile($file));
            }
        } elseif (!empty($this->config->filename)) {
            $loc = $this->countLocInFile($this->config->filename);
        } else {
            print "Usage : php exakat phploc <-p project> <-d dirname> <-f filename>\n";
            return;
        }
        if ($this->config->json) {
            print json_encode($loc);
        } elseif ($this->config->verbose) {
            foreach ($loc as $k => $v) {
                print substr("{$k}        ", 0, 8) . " : {$v}\n";
            }
        }
    }

Usage Example

Пример #1
0
 public function execute(Config $config)
 {
     switch ($config->command) {
         case 'doctor':
             $doctor = new Tasks\Doctor($this->gremlin, $this->config);
             $doctor->run($config);
             break;
         case 'init':
             $task = new Tasks\Initproject($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'anonymize':
             $task = new Tasks\Anonymize($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'files':
             $task = new Tasks\Files($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'load':
             $task = new Tasks\Load($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'stat':
             $task = new Tasks\Stat($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'analyze':
             $task = new Tasks\Analyze($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'results':
             $task = new Tasks\Results($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'export':
             $task = new Tasks\Export($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'report':
             $task = new Tasks\Report2($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'project':
             $task = new Tasks\Project($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'magicnumber':
             $task = new Tasks\Magicnumber($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'clean':
             $task = new Tasks\Clean($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'status':
             $task = new Tasks\Status($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'help':
             $task = new Tasks\Help($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'cleandb':
             $task = new Tasks\CleanDb($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'onepage':
             $task = new Tasks\OnePage($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'update':
             $task = new Tasks\Update($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'onepagereport':
             $task = new Tasks\OnepageReport($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'phploc':
             $task = new Tasks\Phploc($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'findextlib':
             $task = new Tasks\FindExternalLibraries($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'dump':
             $task = new Tasks\Dump($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'jobqueue':
             $task = new Tasks\Jobqueue($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'queue':
             $task = new Tasks\Queue($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'test':
             $task = new Tasks\Test($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'remove':
             $task = new Tasks\Remove($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'server':
             $task = new Tasks\Server($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'upgrade':
             $task = new Tasks\Upgrade($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'version':
         default:
             $version = self::VERSION;
             $build = self::BUILD;
             $date = date('r', filemtime(__FILE__));
             echo "\n ________                 __              _    \n|_   __  |               [  |  _         / |_  \n  | |_ \\_| _   __  ,--.   | | / ]  ,--. `| |-' \n  |  _| _ [ \\ [  ]`'_\\ :  | '' <  `'_\\ : | |   \n _| |__/ | > '  < // | |, | |`\\ \\ // | |,| |,  \n|________|[__]`\\_]\\'-;__/[__|  \\_]\\'-;__/\\__/  \n                                               \n\nExakat : @ 2014-2016 Damien Seguy. \nVersion : ", $version, ' - Build ', $build, ' - ', $date, "\n";
             break;
     }
 }
All Usage Examples Of Exakat\Tasks\Phploc::run