Skip to content

Instantly share code, notes, and snippets.

@theodorejb theodorejb/parse-log.php
Last active Jul 5, 2019

Embed
What would you like to do?
Analysis of curly brace array syntax usage in top PHP packages
<?php
// parse the output of https://gist.github.com/nikic/b5f811e0423bf051f4492cd6e0c0273e
$contents = file('alternative_array_syntax_usage.txt');
$match = '/home/nikic/package-analysis/sources/';
$matchLen = strlen($match);
$parseErrorMatch = 'Parse error:';
$parseErrorLen = strlen($parseErrorMatch);
$uniqueNamespaces = $uniquePkgs = $uniqueVars = [];
$totalCount = 0;
$lastLine = null;
$checkLine = function (string $line) use ($matchLen, $match, &$totalCount, &$uniqueNamespaces, &$uniquePkgs, &$uniqueVars) {
if (substr($line, 0, $matchLen) === $match) {
$rest = substr($line, $matchLen);
$pkgSlash = strpos($rest, '/', 1);
$srcSlash = strpos($rest, '/', $pkgSlash + 1);
$namespace = substr($rest, 0, $pkgSlash);
$package = substr($rest, $pkgSlash + 1, $srcSlash - $pkgSlash - 1);
$packageFullname = $namespace . '/' . $package;
$totalCount++;
if (!isset($uniqueNamespaces[$namespace])) {
$uniqueNamespaces[$namespace] = 1;
} else {
$uniqueNamespaces[$namespace] += 1;
}
if (!isset($uniquePkgs[$packageFullname])) {
$uniquePkgs[$packageFullname] = 1;
} else {
$uniquePkgs[$packageFullname] += 1;
}
} else {
$curlyPos = strpos($line, '{');
if ($curlyPos !== false) {
$var = trim(substr($line, 0, $curlyPos));
if (!isset($uniqueVars[$var])) {
$uniqueVars[$var] = 1;
} else {
$uniqueVars[$var] += 1;
}
}
}
};
foreach($contents as $line) {
if (substr($line, 0, $parseErrorLen) === $parseErrorMatch) {
$lastLine = null;
continue;
}
if ($lastLine !== null) {
$checkLine($lastLine);
}
$lastLine = $line;
}
if ($lastLine !== null) {
$checkLine($lastLine);
}
echo count($uniqueNamespaces) . ' namespaces with curly brace uses' . PHP_EOL;
echo count($uniquePkgs) . ' packages with curly brace uses' . PHP_EOL;
echo 'Total uses in top 2K packages: ' . $totalCount . PHP_EOL;
arsort($uniquePkgs);
$top15 = $top25 = $twoOrLess = $fourOrLess = 0;
$i = 0;
foreach ($uniquePkgs as $key => $val) {
if ($key !== 'johnpbloch/wordpress-core' && $key !== 'tecnick.com/tcpdf') {
// don't count duplicate projects
$i++;
}
if ($i <= 15) {
$top15 += $val;
}
if ($i <= 25) {
$top25 += $val;
}
if ($val <= 4) {
$fourOrLess++;
}
if ($val <= 2) {
$twoOrLess++;
}
}
echo $top15 . ' uses in 15 unique projects' . PHP_EOL;
echo $top25 . ' uses in 25 unique projects' . PHP_EOL;
echo $fourOrLess . ' projects have 4 or fewer usages' . PHP_EOL;
echo $twoOrLess . ' projects only have 1 or 2 usages' . PHP_EOL;
echo PHP_EOL;
var_export($uniquePkgs);
echo PHP_EOL . PHP_EOL;
arsort($uniqueVars);
echo count($uniqueVars) . ' unique variables:' . PHP_EOL;
var_export($uniqueVars);
75 namespaces with curly brace uses
89 packages with curly brace uses
Total uses in top 2K packages: 2217
1828 uses in 15 unique projects
2036 uses in 25 unique projects
53 projects have 4 or fewer usages
37 projects only have 1 or 2 usages
array (
'james-heinrich/getid3' => 299,
'mpdf/mpdf' => 231,
'phpoffice/phpexcel' => 219,
'roots/wordpress' => 182,
'johnpbloch/wordpress-core' => 182,
'milon/barcode' => 89,
'lukasreschke/id3parser' => 78,
'tecnickcom/tcpdf' => 74,
'tecnick.com/tcpdf' => 74,
'yiisoft/yii' => 64,
'picqer/php-barcode-generator' => 63,
'squizlabs/php_codesniffer' => 56,
'pear/pear' => 55,
'phing/phing' => 46,
'campaignmonitor/createsend-php' => 40,
'georgringer/news' => 38,
'behat/transliterator' => 38,
'lsolesen/pel' => 37,
'zendframework/zendframework1' => 37,
'dflydev/markdown' => 22,
'michelf/php-markdown' => 21,
'magento/zendframework1' => 18,
'adoy/fastcgi-client' => 17,
'phphleb/framework' => 14,
'phphleb/hleb' => 14,
'parsecsv/php-parsecsv' => 14,
'zendframework/zend-json' => 14,
'typo3/cms' => 12,
'typo3/cms-core' => 12,
'pear/console_getopt' => 11,
'zendframework/zend-barcode' => 9,
'mso/idna-convert' => 7,
'braintree/braintree_php' => 6,
'cakephp/cakephp' => 6,
'typo3fluid/fluid' => 6,
'leafo/lessphp' => 5,
'ezyang/htmlpurifier' => 4,
'greenlion/php-sql-parser' => 4,
'ronanguilloux/isocodes' => 4,
'simplepie/simplepie' => 4,
'zendframework/zend-code' => 4,
'amazonwebservices/aws-sdk-for-php' => 4,
'neitanod/forceutf8' => 4,
'globalcitizen/php-iban' => 3,
'khanamiryan/qrcode-detector-decoder' => 3,
'codeigniter/framework' => 3,
'drupal/core' => 3,
'ulrichsg/getopt-php' => 3,
'zendframework/zend-validator' => 3,
'teamtnt/tntsearch' => 3,
'electrolinux/phpquery' => 3,
'propel/propel' => 3,
'apache/thrift' => 2,
'mikey179/vfsstream' => 2,
'phpdocumentor/phpdocumentor' => 2,
'abraham/twitteroauth' => 2,
'acquia/lightning' => 2,
'inacho/php-credit-card-validator' => 2,
'cakephp/cakephp-codesniffer' => 2,
'packaged/thrift' => 2,
'windwalker/structure' => 2,
'hybridauth/hybridauth' => 2,
'zendframework/zend-view' => 2,
'theorchard/monolog-cascade' => 2,
'pear/pear-core-minimal' => 2,
'fzaninotto/faker' => 2,
'xamin/handlebars.php' => 2,
'helios-ag/fm-elfinder-php-connector' => 1,
'snc/redis-bundle' => 1,
'jakub-onderka/php-parallel-lint' => 1,
'mrclay/minify' => 1,
'besimple/soap-client' => 1,
'netresearch/jsonmapper' => 1,
'pear/xml_util' => 1,
'typo3/phar-stream-wrapper' => 1,
'magento/magento2-functional-testing-framework' => 1,
'adodb/adodb-php' => 1,
'icanboogie/inflector' => 1,
'fileeye/mimemap' => 1,
'icecave/repr' => 1,
'akamai-open/edgegrid-client' => 1,
'mk-j/php_xlsxwriter' => 1,
'piwik/piwik-php-tracker' => 1,
'silverstripe/framework' => 1,
'fluidtypo3/vhs' => 1,
'cakephp/plugin-installer' => 1,
'studio-42/elfinder' => 1,
'topthink/framework' => 1,
'mayflower/php-codebrowser' => 1,
)
249 unique variables:
array (
'$string' => 239,
'$code' => 197,
'$c' => 171,
'$col' => 75,
'$var' => 72,
'$Bytestring' => 64,
'$data' => 59,
'$chrs' => 54,
'$Header4Bytes' => 48,
'$seq' => 44,
'$value' => 44,
'$recordData' => 42,
'$utf8' => 42,
'$tag' => 39,
'$this->formula' => 35,
'$SyncPattern1' => 32,
'$text' => 27,
'$str' => 27,
'$header' => 26,
'$xclrValue' => 24,
'$hex' => 20,
'$seq[1]' => 17,
'$numberstring' => 16,
'$token' => 16,
'$binarypointnumber' => 15,
'$byteword' => 15,
'$formula' => 15,
'$bytes' => 14,
'$pair' => 13,
'$path' => 13,
'$footer' => 12,
'$utf16' => 12,
'$bit' => 12,
'$url' => 11,
'$name' => 11,
'$input' => 11,
'$BMPpixelData' => 10,
'$pString' => 10,
'$ts[\'col\']' => 10,
'$col1' => 10,
'$bitword' => 9,
'$asciidata' => 9,
'$chr[$char]' => 9,
'$colour' => 9,
'$dict' => 8,
'$stops[$i][\'col\']' => 8,
'$arg' => 8,
'$encoded' => 8,
'$frame_name' => 8,
'$lucifer[0]' => 8,
'$pb[\'col\']' => 8,
'$strPath' => 8,
'$hash' => 8,
'$id3v1tag' => 8,
'$framedata' => 8,
'$parsedFrame[\'frame_name\']' => 8,
'$this->pdfdata' => 8,
'$utf8text' => 7,
'$line' => 7,
'$ISOtime' => 7,
'$chars' => 6,
'$tokens[$stackPtr][\'content\']' => 6,
'$head4' => 6,
'$dom[$key][\'value\']' => 6,
'$buffer_4k' => 6,
'$version' => 6,
'$this->bytes' => 5,
'$rowDatum' => 5,
'$firstBit' => 5,
'$sh[\'col\']' => 5,
'$key' => 5,
'$METAeventData' => 5,
'$p' => 5,
'$buffer' => 5,
'$raw' => 4,
'$attr[\'size\']' => 4,
'$generate_url' => 4,
'$complexNumber' => 4,
'$filename' => 4,
'$LAMEtocData' => 4,
'$binstring' => 4,
'$functionName' => 4,
'$ThisWord' => 4,
'$this->bodyBackgroundColor' => 4,
'$isbn13' => 4,
'$package[\'platform\'][$file]' => 4,
'$ent' => 4,
'$dir' => 4,
'$base' => 4,
'$number' => 4,
'$PCD_data_Cr' => 4,
'$PCD_data_Cb' => 4,
'$wavpackheader' => 4,
'$chr[$char_space]' => 4,
'$slug' => 4,
'$upce_code' => 4,
'$uri' => 4,
'$details[$side][\'c\']' => 4,
'$chr[$char_bar]' => 4,
'$frame_remainingdata' => 4,
'$entry' => 4,
'$href' => 4,
'$rgb' => 3,
'$bban' => 3,
'$formulaData' => 3,
'$cor' => 3,
'$this->_compile_' => 3,
'$ttaheader' => 3,
'$matches[3]' => 3,
'$Pattern' => 3,
'$pathname' => 3,
'$variable' => 3,
'$argsString' => 3,
'$original_text' => 3,
'$comment' => 3,
'$function' => 3,
'$method' => 3,
'$next4' => 3,
'$fourbit' => 3,
'$majver' => 3,
'$matches[2]' => 3,
'$element' => 2,
'$trackingNumber' => 2,
'$root' => 2,
'$versioncomponents[2]' => 2,
'$opt[1]' => 2,
'$transparency' => 2,
'$outerPad' => 2,
'$spec' => 2,
'$tracking_number' => 2,
'$keyDigest' => 2,
'$innerPad' => 2,
'$result' => 2,
'$this->buffer' => 2,
'$signature' => 2,
'$built' => 2,
'$methodName' => 2,
'$memberName' => 2,
'$hs' => 2,
'$PCD_data_Y1' => 2,
'$platform' => 2,
'$currName' => 2,
'static::$validationKeys' => 2,
'$hetu' => 2,
'$t' => 2,
'$sb' => 2,
'$match[1]' => 2,
'$tmp' => 2,
'$argument' => 2,
'$match[2]' => 2,
'$contentLines[$contentLineIndex + 1]' => 2,
'$file[\'attribs\'][\'name\']' => 2,
'$isbn10' => 2,
'$quotedValue' => 2,
'$DirectoryRecordData' => 2,
'$hdr_data' => 2,
'$prepend' => 2,
'$PCD_data_Y2' => 2,
'$attrib' => 2,
'$matches[1]' => 2,
'$all' => 2,
'$args[0]' => 2,
'$part' => 2,
'$_hl_excluded_key' => 2,
'$secret_key' => 2,
'$workString' => 2,
'$operand' => 2,
'$time' => 2,
'$rowReference' => 2,
'$columnReference' => 2,
'$condition' => 2,
'$tValue' => 2,
'$stroke' => 2,
'$styleSettings' => 2,
'$hl_val_address' => 2,
'$dynamicRuleType' => 2,
'$subData' => 2,
'$matches[0]' => 2,
'$token[\'content\']' => 2,
'$content' => 2,
'$this->_stream' => 1,
'$deletefilemessage' => 1,
'$ArrayPath' => 1,
'$formulaStructure' => 1,
'$atts[\'platform\']' => 1,
'$BlockData' => 1,
'$bar' => 1,
'$ISOheader' => 1,
'$options[\'percent_pad\']' => 1,
'$check' => 1,
'$md5' => 1,
'$type' => 1,
'$ActualFilenameNoExt' => 1,
'$email' => 1,
'$classname' => 1,
'$resp[\'content\']' => 1,
'$child' => 1,
'$domain' => 1,
'$strPathname' => 1,
'$drive' => 1,
'$d' => 1,
'$characters' => 1,
'$PatternFilenameNoExt' => 1,
'$param[\'comment\']' => 1,
'$subPathName' => 1,
'$caption' => 1,
'$tags' => 1,
'$relative' => 1,
'$rule' => 1,
'$newColumn' => 1,
'$max' => 1,
'$param' => 1,
'$beforeColumn' => 1,
'$stringRepresentation' => 1,
'$lpData' => 1,
'$this->data' => 1,
'$operand1' => 1,
'$operand2' => 1,
'$pValue' => 1,
'$package[\'version\']' => 1,
'$subProp[1]' => 1,
'$this->_version' => 1,
'$col_ref' => 1,
'$sql' => 1,
'$funcName' => 1,
'$camelCapsPart' => 1,
'$opt' => 1,
'$xmlFile' => 1,
'$next_option_rest' => 1,
'$wsTitle' => 1,
'$depdb[\'_version\']' => 1,
'$newRow' => 1,
'$this->encryptionKey' => 1,
'$beforeRow' => 1,
'$TagHeaderTest' => 1,
'$metablockheader' => 1,
'$os' => 1,
'$mode' => 1,
'$options[\'fraction_pad\']' => 1,
'$owner_rc4_key' => 1,
'$cOTLdata[$c][\'group\']' => 1,
'$file' => 1,
'$components[\'path\']' => 1,
'$cOTLdata[$nc][\'group\']' => 1,
'$chunkOTLdata[\'group\']' => 1,
'$params[1]' => 1,
'$info[\'arg\']' => 1,
'$OTLdata[\'group\']' => 1,
'$ascii' => 1,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.