Permalink
Browse files

Use assert_instances_of()

Summary: D2042

Test Plan:   bin/diviner ../phabricator/

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D2043
  • Loading branch information...
vrana
vrana committed Mar 29, 2012
1 parent 1d3bc7c commit 863f4b8bdf33f7a8af8ce9e6bff6574cbdb90733
Showing with 19 additions and 14 deletions.
  1. +16 −14 src/generator/static/DivinerStaticGenerator.php
  2. +3 −0 src/publisher/DivinerPublisher.php
@@ -1,7 +1,7 @@
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
class DivinerStaticGenerator extends DivinerBaseGenerator {
public function generateDocumentation(array $views) {
+ assert_instances_of($views, 'DivinerBaseAtomView');
$renderer = new DivinerDefaultRenderer();
$this->setRenderer($renderer);
@@ -61,11 +62,11 @@ public function generateDocumentation(array $views) {
unset($groups['radicals']);
$groups['radicals'] = $radicals;
}
-
+
$groups = array_select_keys(
$groups,
array_keys($configuration->getConfig('groups', array()))) + $groups;
-
+
$renderer->setBaseURI('');
$index = array();
$index[] = $this->renderTableOfContents($groups);
@@ -109,10 +110,10 @@ public function generateDocumentation(array $views) {
Filesystem::readFile($stylesheet));
}
}
-
+
private function renderTableOfContents($groups) {
$renderer = $this->getRenderer();
-
+
$out = array();
foreach ($groups as $name => $group) {
$link = phutil_render_tag(
@@ -123,23 +124,23 @@ private function renderTableOfContents($groups) {
$renderer->renderGroup($name));
$out[] = '<li>'.$link.'</li>';
}
-
+
return
'<div class="atom-toc">'.
'<h1>Table of Contents</h1>'.
'<ul>'.implode("\n", $out).'</ul>'.
'</div>';
-
+
}
-
+
private function renderGroup($group) {
$renderer = $this->getRenderer();
$types = array();
foreach ($group as $view) {
$types[$view->getAtom()->getType()][] = $view;
}
-
+
// Reorder the types.
$types = array_select_keys(
$types,
@@ -163,13 +164,13 @@ private function renderGroup($group) {
}
if ($type == 'class') {
$map = array(-1 => array());
-
+
$local = array();
foreach ($views as $view) {
$atom = $view->getAtom();
$local[$atom->getName()] = true;
}
-
+
foreach ($views as $view) {
$atom = $view->getAtom();
$extends = $atom->getParentClasses();
@@ -205,13 +206,13 @@ private function renderGroup($group) {
),
implode("\n", $list));
}
-
+
return
'<div class="atom-group-contents">'.
implode("\n", $index).
'</div>';
- }
-
+ }
+
private function renderView(DivinerBaseAtomView $view) {
$html = $view->renderView();
@@ -270,6 +271,7 @@ private function renderTemplate(array $dictionary) {
}
private function renderClassHierarchy(array $map, array $list) {
+ assert_instances_of($list, 'DivinerBaseAtomView');
$renderer = $this->getRenderer();
$out = array();
@@ -47,13 +47,15 @@ public function publish() {
}
private static function flattenAndGroupAtoms(array $atoms) {
+ assert_instances_of($atoms, 'DivinerAtom');
$atoms = self::flattenAtoms($atoms);
$atoms = self::selectTopLevelAtoms($atoms);
$atoms = mgroup($atoms, 'getType');
return $atoms;
}
private static function flattenAtoms(array $atoms) {
+ assert_instances_of($atoms, 'DivinerAtom');
$all_atoms = array();
foreach ($atoms as $atom) {
$all_atoms[] = array($atom);
@@ -67,6 +69,7 @@ private static function flattenAtoms(array $atoms) {
}
private static function selectTopLevelAtoms(array $atoms) {
+ assert_instances_of($atoms, 'DivinerAtom');
$result = array();
foreach ($atoms as $atom) {
if ($atom->getIsTopLevelAtom()) {

0 comments on commit 863f4b8

Please sign in to comment.