*/ class DocCoverageAnalysis { protected $typestemplate = array( 'constructors' => array( 'missing' => 0, 'existing' => 0 ), 'methods' => array( 'missing' => 0, 'existing' => 0 ), 'signals' => array( 'missing' => 0, 'existing' => 0 ), 'properties' => array( 'missing' => 0, 'existing' => 0 ), 'fields' => array( 'missing' => 0, 'existing' => 0 ), ); public function run() { $script = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'gen_manual.sh'; if (!file_exists($script)) { echo "Coverage extractor doesn't exist\n" . $script . "\n"; exit(1); } else if (!is_executable($script)) { echo "Coverage extractor is not executable\n" . $script . "\n"; exit(2); } $xmlstring = `$script en coverage`; $doc = simplexml_load_string($xmlstring); $output = << PHP-Gtk2 documentation coverage analysis ' . "\r\n" . '' . '' . '' . '' . '' . '' . '' . '' . "\r\n" . '' . '' . '' . '' . '' . '' . '' . "\r\n" . '' . "\r\n" . '' . "\r\n"; $allMissing = 0; $allExisting = 0; $types = $this->typestemplate; foreach ($doc->classset as $classset) { list($classoutput, $existing, $missing, $settypes) = $this->calcClassset($classset); $types = $this->addTypes($types, $settypes); $allMissing += $missing; $allExisting += $existing; $output .= $classoutput; } $output .= '' . '' . $this->getTypesDisplay($types) . '' . "\r\n"; $output .= '' . '' . '' . '' . '' . '' . "\r\n" . '' . "\r\n"; return $output; }//protected function calcCoverage($doc) public function calcClassset($classset) { $output = ''; $allMissing = 0; $allExisting = 0; $types = $this->typestemplate; foreach ($classset->{'class'} as $class) { list($classoutput, $existing, $missing, $classtypes) = $this->calcClass($class); $types = $this->addTypes($types, $classtypes); $allMissing += $missing; $allExisting += $existing; $output .= $classoutput; } $output .= '' . '' . $this->getTypesDisplay($types) . '' . "\r\n"; return array($output, $allExisting, $allMissing, $types); } public function calcClass($class) { $types = $this->typestemplate; $allMissing = 0; $allExisting = 0; if (isset($class->type)) { foreach ($class->type as $type) { $title = (string)$type['title']; $types[$title]['missing'] = (string)$type['missing']; $types[$title]['existing'] = (string)$type['existing']; $allMissing += $types[$title]['missing']; $allExisting += $types[$title]['existing']; } } $output = '' . $this->getTypesDisplay($types) . '' . "\r\n"; return array($output, $allExisting, $allMissing, $types); }//public function calcClass($class) function getTypesDisplay($types) { return $this->getTypeDisplay($types['constructors']) . $this->getTypeDisplay($types['methods']) . $this->getTypeDisplay($types['signals']) . $this->getTypeDisplay($types['properties']) . $this->getTypeDisplay($types['fields']); }//function getTypesDisplay($types) function getTypeDisplay($type) { $existing = $type['existing']; $missing = $type['missing']; $done = $existing - $missing; if ($existing != 0) { $percent = intval(100 / $existing * $done); } else { $percent = -100; } if ($percent == -100) { $color = 'white'; } else if ($percent == 100) { $color = 'green'; } else if ($percent >= 85) { $color = 'yellow'; } else if ($percent >= 50) { $color = 'orange'; } else { $color = 'red'; } $output = ''; $output .= ''; return $output; }//function getTypeDisplay($type) protected function addTypes($types, $newTypes) { foreach ($newTypes as $name => $numbers) { foreach ($numbers as $numtitle => $number) { $types[$name][$numtitle] += $number; } } return $types; }//protected function addTypes($types, $newTypes) }//class DocCoverageAnalysis $da = new DocCoverageAnalysis(); echo $da->run(); ?>
EOD; $output .= 'PHP-Gtk2 documentation coverage analysis of ' . date('Y-m-d H:i:s'); $output .= << EOD; $output .= $this->calcCoverage($doc); $output .= << EOD; return $output; }//public function run() protected function calcCoverage($doc) { $output = '
NameConstructorsMethodsSignalsPropertiesFields
DoneAllDoneAllDoneAllDoneAllDoneAll
Documentation
All in all' . ($allExisting - $allMissing) . '' . $allExisting . '' . number_format(100 / $allExisting * ($allExisting - $allMissing), 2) . '%
' . htmlspecialchars((string)$classset['title']) . '
' . htmlspecialchars((string)$class['title']) . '
' . $done . '' . $existing . '