/** * @param string $sourcode * @param string $language * @param array $configuration */ public function getFormattedText($sourceCode, $language = 'TypoScript', $configuration = array()) { $geshi = new SourceCode($sourceCode, $language); $geshi->setStrictMode(false); $geshi->setLineNumbering(1); return $geshi->getFormatedSourceCode(); }
function computeResults($filecontent) { global $language, $relevance; $sc = new SourceCode($filecontent, $language); $summary = $sc->getSummary(); return array('metrics' => array('size' => $summary['size'], 'loc' => $summary['nloc'], 'ncloc' => $summary['ncloc'], 'relevance' => 'system'), 'tokens' => $sc->getTokens()); }
<?php $input = $argv[1]; $language = $argv[2]; $relevance = $argv[3]; define('_MEGALIB', 'true'); define('DEBUG', 10); define('ABSPATH_BASE', getenv('output101dir') . '/'); define('ABSPATH_EXTERNAL_LIBRARIES', ABSPATH_BASE . '101results/libraries/'); define('ABSPATH_MEGALIB', ABSPATH_EXTERNAL_LIBRARIES . 'megalib/'); define('ABSPATH_SRC_GESHI_LIBRARY', ABSPATH_BASE . '101results/geshi/src/'); require_once 'megalib_leftover.php'; $content = file_get_contents($input); $sc = new SourceCode($content, $language); $summary = $sc->getSummary(); $result = array('metrics' => array('size' => $summary['size'], 'loc' => $summary['nloc'], 'ncloc' => $summary['ncloc'], 'relevance' => $relevance), 'tokens' => $sc->getTokens()); echo json_encode($result);
/** * Create a source code. * * @param String! $text The text representing the source code * * @param GeshiLanguage! $language The geshiLanguage in which this source code is written * * @param String? $sourceid an optional sourceId that will be used to differentiate this source * from other sources if in the same html page. This will be used as a CSS class name and prefix * for CSS id, so it should be short. If nothing is provided an identifier will be automatically * generated. This is probably the best. */ public function __construct($text, $geshiLanguage, $sourceid = null) { $this->plainSourceCode = $text; $this->geshiLanguage = $geshiLanguage; if (isset($sourceid)) { $this->sourceId = $sourceid; } else { $this->sourceId = SourceCode::getNewSourceId(); } }
<?php // TODO: no comments: https://github.com/megaplanet/megalib/blob/master/SourceCode.php#L914-L920 $ifilename = $argv[1]; $ofilename1 = $argv[2]; $ofilename2 = $argv[3]; $language = $argv[4]; $relevance = $argv[5]; define('_MEGALIB', 'true'); define('DEBUG', 10); define('ABSPATH_BASE', dirname(dirname(dirname(__DIR__))) . '/'); define('ABSPATH_EXTERNAL_LIBRARIES', ABSPATH_BASE . '101results/libraries/'); define('ABSPATH_MEGALIB', ABSPATH_EXTERNAL_LIBRARIES . 'megalib/'); define('ABSPATH_SRC_GESHI_LIBRARY', ABSPATH_EXTERNAL_LIBRARIES . 'geshi/'); require_once 'megalib_leftover.php'; $content = file_get_contents($ifilename); $sc = new SourceCode($content, $language); $summary = $sc->getSummary(); $metrics = array('size' => $summary['size'], 'loc' => $summary['nloc'], 'ncloc' => $summary['ncloc'], 'relevance' => $relevance); file_put_contents($ofilename1, json_encode($metrics)); file_put_contents($ofilename2, $sc->getTokensAsJson());