Exakat\Reports\Devoops::generate PHP Метод

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

public generate ( $folder, $name = 'report' )
    public function generate($folder, $name = 'report')
    {
        $finalName = $name;
        $name = '.' . $name;
        if ($name === null) {
            return "Can't produce Devoops format to stdout";
        }
        // Clean final destination
        if ($folder . '/' . $finalName !== '/') {
            rmdirRecursive($folder . '/' . $finalName);
        }
        if (file_exists($folder . '/' . $finalName)) {
            display($folder . '/' . $finalName . " folder was not cleaned. Please, remove it before producing the report. Aborting report\n");
            return;
        }
        // Clean temporary destination
        if (file_exists($folder . '/' . $name)) {
            rmdirRecursive($folder . '/' . $name);
        }
        mkdir($folder . '/' . $name, Devoops::FOLDER_PRIVILEGES);
        mkdir($folder . '/' . $name . '/ajax', Devoops::FOLDER_PRIVILEGES);
        copyDir($this->config->dir_root . '/media/devoops/css', $folder . '/' . $name . '/css');
        copyDir($this->config->dir_root . '/media/devoops/img', $folder . '/' . $name . '/img');
        copyDir($this->config->dir_root . '/media/devoops/js', $folder . '/' . $name . '/js');
        copyDir($this->config->dir_root . '/media/devoops/plugins', $folder . '/' . $name . '/plugins');
        $this->dump = new \Sqlite3($folder . '/dump.sqlite', SQLITE3_OPEN_READONLY);
        // This is an overwriting. Leave it here.
        $this->datastore = new \Sqlite3($folder . '/datastore.sqlite', SQLITE3_OPEN_READONLY);
        // Compatibility
        $compatibility = array('Compilation' => 'Compilation');
        foreach ($this->config->other_php_versions as $code) {
            if ($code == 52) {
                continue;
            }
            $version = $code[0] . '.' . substr($code, 1);
            $compatibility['Compatibility ' . $version] = 'Compatibility';
        }
        // Analyze
        $analyze = array();
        $themes = array('CompatibilityPHP53', 'CompatibilityPHP54', 'CompatibilityPHP55', 'CompatibilityPHP56', 'CompatibilityPHP70', 'CompatibilityPHP71', '"Dead code"', 'Security', 'Analyze');
        $analyzers = Analyzer::getThemeAnalyzers($themes);
        $themesList = '("' . implode('", "', $analyzers) . '")';
        $res = $this->dump->query('SELECT * FROM resultsCounts WHERE count > 0 AND analyzer in ' . $themesList);
        while ($row = $res->fetchArray()) {
            $analyzer = Analyzer::getInstance($row['analyzer']);
            $this->analyzers[$analyzer->getDescription()->getName()] = $analyzer;
            $analyze[$analyzer->getDescription()->getName()] = 'OneAnalyzer';
        }
        uksort($analyze, function ($a, $b) {
            return strtolower($a) > strtolower($b);
        });
        $analyze = array_merge(array('Results Counts' => 'AnalyzersResultsCounts'), $analyze);
        // Files
        $files = array();
        $res = $this->dump->query('SELECT DISTINCT file FROM results ORDER BY file');
        while ($row = $res->fetchArray()) {
            $files[$row['file']] = 'OneFile';
        }
        $files = array_merge(array('Files Counts' => 'FilesResultsCounts'), $files);
        $summary = array('Report presentation' => array('Audit configuration' => 'AuditConfiguration'), 'Analysis' => array('Code Smells' => 'Dashboard', 'Dead Code' => 'Dashboard', 'Security' => 'Dashboard', 'Performances' => 'Dashboard'), 'Compatibility' => $compatibility, 'By analyze' => $analyze, 'By file' => $files, 'Application' => array('Appinfo()' => 'Appinfo', 'PHP Directives' => 'Directives', 'PHP Bugfixes' => 'Bugfixes', 'Altered Directives' => 'AlteredDirectives', 'Dynamic Code' => 'DynamicCode', 'Stats' => 'Stats', 'Global Variables List' => 'GlobalVariablesList', 'External Config Files' => 'ExternalConfigFiles', 'Error Messages' => 'ErrorMessages'), 'Annexes' => array('Documentation' => 'Documentation', 'Processed Files' => 'ProcessedFiles', 'Non-processed Files' => 'NonProcessedFiles', 'External Libraries' => 'ExternalLibraries', 'Analyzers' => 'Analyzers', 'About This Report' => 'AboutThisReport'));
        $summaryHtml = $this->makeSummary($summary);
        $faviconHtml = '';
        if (file_exists($this->config->dir_root . '/projects/' . $this->config->project . '/code/favicon.ico')) {
            // Should be checked and reported
            copy($this->config->dir_root . '/projects/' . $this->config->project . '/code/favicon.ico', $folder . '/' . $name . '/img/' . $this->config->project . '.ico');
            $faviconHtml = <<<HTML
<img src="img/{$this->config->project}.ico" class="img-circle" alt="{$this->config->project} logo" />
HTML;
            if (!empty($this->config->project_url)) {
                $faviconHtml = "<a href=\"{$this->config->project_url}\" class=\"avatar\">{$faviconHtml}</a>";
            }
            $faviconHtml = <<<HTML
\t\t\t\t<div class="avatar">
\t\t\t\t\t{$faviconHtml}
\t\t\t\t</div>
HTML;
        }
        $html = file_get_contents($this->config->dir_root . '/media/devoops/index.exakat.html');
        $html = str_replace('<menu>', $summaryHtml, $html);
        $html = str_replace('EXAKAT_VERSION', Exakat::VERSION, $html);
        $html = str_replace('EXAKAT_BUILD', Exakat::BUILD, $html);
        $html = str_replace('PROJECT_NAME', $this->config->project_name, $html);
        $html = str_replace('PROJECT_FAVICON', $faviconHtml, $html);
        file_put_contents($folder . '/' . $name . '/index.html', $html);
        foreach ($summary as $titleUp => $section) {
            foreach ($section as $title => $method) {
                if (method_exists($this, $method)) {
                    $html = $this->{$method}($title);
                } else {
                    $html = 'Using default for ' . $title . "\n";
                    display($html);
                }
                $filename = $this->makeFileName($title);
                $html = <<<HTML
<script language="javascript">
if (!document.getElementById("main")) {
    window.location.href = "../index.html#ajax/{$filename}";
}
</script >
<div class="row">
\t<div id="breadcrumb" class="col-xs-12">
\t\t<a href="#" class="show-sidebar">
\t\t\t<i class="fa fa-bars"></i>
\t\t</a>
\t\t<ol class="breadcrumb pull-left">
\t\t\t<li><a href="index.html">Dashboard</a></li>
\t\t\t<li><a href="#ajax/About-This-Report.html">About This Report</a></li>
\t\t</ol>
\t</div>
</div>

<h4 class="page-header">{$title}</h4>
<div class="row">
\t<div class="col-xs-12">
{$html}
    </div>
</div>
HTML;
                file_put_contents($folder . '/' . $name . '/ajax/' . $filename, $html);
            }
        }
        rename($folder . '/' . $name, $folder . '/' . $finalName);
        return '';
    }