public function generate($dirName, $fileName = null)
{
$sqlite = new \sqlite3($dirName . '/dump.sqlite', \SQLITE3_OPEN_READONLY);
$sqlQuery = <<<SQL
SELECT id AS id,
fullcode AS code,
file AS file,
line AS line,
analyzer AS analyzer
FROM results
WHERE analyzer IN {$this->themesList}
SQL;
$res = $sqlite->query($sqlQuery);
$config = Config::factory();
$datastore = new Datastore($config);
$items = array();
while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$ini = parse_ini_file($config->dir_root . '/human/en/' . $row['analyzer'] . '.ini');
$row['error'] = $ini['name'];
$a = Analyzer::getInstance($row['analyzer']);
$row['severity'] = $a->getSeverity();
$row['impact'] = $a->getTimeToFix();
$row['recipes'] = $a->getThemes();
$items[] = $row;
$this->count();
}
if ($fileName === null) {
$json = json_encode($items, JSON_PARTIAL_OUTPUT_ON_ERROR);
// @todo Log if $json == false
return $json;
} else {
file_put_contents($dirName . '/' . $fileName . '.' . self::FILE_EXTENSION, json_encode($items));
return true;
}
}