Commit 992db0ef by Alexander Makarov

apidoc minor fixes: phpdoc, use statements, comments

parent 6c88467a
...@@ -31,6 +31,11 @@ abstract class BaseController extends Controller ...@@ -31,6 +31,11 @@ abstract class BaseController extends Controller
public $exclude; public $exclude;
/**
* Checks that target directory is valid. Asks questions in tricky cases.
* @param string $target
* @return boolean|string
*/
protected function normalizeTargetDir($target) protected function normalizeTargetDir($target)
{ {
$target = rtrim(Yii::getAlias($target), '\\/'); $target = rtrim(Yii::getAlias($target), '\\/');
...@@ -52,6 +57,11 @@ abstract class BaseController extends Controller ...@@ -52,6 +57,11 @@ abstract class BaseController extends Controller
return $target; return $target;
} }
/**
* Finds files to process
* @param array $sourceDirs
* @return array|boolean list of files to process or false on failure
*/
protected function searchFiles($sourceDirs) protected function searchFiles($sourceDirs)
{ {
$this->stdout('Searching files to process... '); $this->stdout('Searching files to process... ');
...@@ -81,8 +91,20 @@ abstract class BaseController extends Controller ...@@ -81,8 +91,20 @@ abstract class BaseController extends Controller
return $files; return $files;
} }
/**
* Finds files
*
* @param string $dir directory to search files in.
* @param array $except list of names to exclude from search.
* @return array files found.
*/
abstract protected function findFiles($dir, $except = []); abstract protected function findFiles($dir, $except = []);
/**
* Loads context from cache
* @param string $location
* @return Context
*/
protected function loadContext($location) protected function loadContext($location)
{ {
$context = new Context(); $context = new Context();
...@@ -99,6 +121,11 @@ abstract class BaseController extends Controller ...@@ -99,6 +121,11 @@ abstract class BaseController extends Controller
return $context; return $context;
} }
/**
* Writes context into cache file
* @param Context $context
* @param string $location
*/
protected function storeContext($context, $location) protected function storeContext($context, $location)
{ {
$cacheFile = $location . '/cache/apidoc.data'; $cacheFile = $location . '/cache/apidoc.data';
......
...@@ -11,8 +11,18 @@ use cebe\jssearch\Indexer; ...@@ -11,8 +11,18 @@ use cebe\jssearch\Indexer;
use cebe\jssearch\tokenizer\StandardTokenizer; use cebe\jssearch\tokenizer\StandardTokenizer;
use cebe\jssearch\TokenizerInterface; use cebe\jssearch\TokenizerInterface;
/**
* ApiIndexer indexes framework API
*/
class ApiIndexer extends Indexer class ApiIndexer extends Indexer
{ {
/**
* @param string $file
* @param string $contents
* @param string $basePath
* @param string $baseUrl
* @return array
*/
protected function generateFileInfo($file, $contents, $basePath, $baseUrl) protected function generateFileInfo($file, $contents, $basePath, $baseUrl)
{ {
// create file entry // create file entry
......
...@@ -33,7 +33,7 @@ class ApiMarkdown extends GithubMarkdown ...@@ -33,7 +33,7 @@ class ApiMarkdown extends GithubMarkdown
/** /**
* Renders a code block * @inheritdoc
*/ */
protected function renderCode($block) protected function renderCode($block)
{ {
...@@ -46,6 +46,13 @@ class ApiMarkdown extends GithubMarkdown ...@@ -46,6 +46,13 @@ class ApiMarkdown extends GithubMarkdown
} }
} }
/**
* Highlights code
*
* @param string $code code to highlight
* @param string $language language of the code to highlight
* @return string HTML of highlighted code
*/
public static function highlight($code, $language) public static function highlight($code, $language)
{ {
if ($language !== 'php') { if ($language !== 'php') {
......
...@@ -30,6 +30,9 @@ class ApiMarkdownLaTeX extends GithubMarkdown ...@@ -30,6 +30,9 @@ class ApiMarkdownLaTeX extends GithubMarkdown
protected $renderingContext; protected $renderingContext;
/**
* @inheritdoc
*/
protected function renderApiLink($block) protected function renderApiLink($block)
{ {
// TODO allow break also on camel case // TODO allow break also on camel case
...@@ -37,6 +40,9 @@ class ApiMarkdownLaTeX extends GithubMarkdown ...@@ -37,6 +40,9 @@ class ApiMarkdownLaTeX extends GithubMarkdown
return $latex; return $latex;
} }
/**
* @inheritdoc
*/
protected function renderBrokenApiLink($block) protected function renderBrokenApiLink($block)
{ {
return $this->renderApiLink($block); return $this->renderApiLink($block);
......
...@@ -112,11 +112,21 @@ trait ApiMarkdownTrait ...@@ -112,11 +112,21 @@ trait ApiMarkdownTrait
return [['text', '[['], 2]; return [['text', '[['], 2];
} }
/**
* Renders API link
* @param array $block
* @return string
*/
protected function renderApiLink($block) protected function renderApiLink($block)
{ {
return $block[1]; return $block[1];
} }
/**
* Renders API link that is broken i.e. points nowhere
* @param array $block
* @return string
*/
protected function renderBrokenApiLink($block) protected function renderBrokenApiLink($block)
{ {
return $block[1]; return $block[1];
......
...@@ -9,6 +9,9 @@ namespace yii\apidoc\helpers; ...@@ -9,6 +9,9 @@ namespace yii\apidoc\helpers;
use cebe\markdown\Markdown; use cebe\markdown\Markdown;
/**
* IndexFileAnalyzer analyzes index file with TOC. Typically README.md.
*/
class IndexFileAnalyzer extends Markdown class IndexFileAnalyzer extends Markdown
{ {
public $title; public $title;
...@@ -18,6 +21,11 @@ class IndexFileAnalyzer extends Markdown ...@@ -18,6 +21,11 @@ class IndexFileAnalyzer extends Markdown
private $_chapters = []; private $_chapters = [];
/**
* Parses text and returns list of chapters got from it
* @param string $text
* @return array
*/
public function analyze($text) public function analyze($text)
{ {
$this->parse($text); $this->parse($text);
...@@ -25,6 +33,9 @@ class IndexFileAnalyzer extends Markdown ...@@ -25,6 +33,9 @@ class IndexFileAnalyzer extends Markdown
return $this->_chapters; return $this->_chapters;
} }
/**
* @inheritdoc
*/
protected function renderHeadline($block) protected function renderHeadline($block)
{ {
if ($this->_chapter === 0) { if ($this->_chapter === 0) {
...@@ -41,6 +52,9 @@ class IndexFileAnalyzer extends Markdown ...@@ -41,6 +52,9 @@ class IndexFileAnalyzer extends Markdown
return parent::renderHeadline($block); return parent::renderHeadline($block);
} }
/**
* @inheritdoc
*/
protected function renderParagraph($block) protected function renderParagraph($block)
{ {
if ($this->_chapter < 1) { if ($this->_chapter < 1) {
...@@ -49,6 +63,9 @@ class IndexFileAnalyzer extends Markdown ...@@ -49,6 +63,9 @@ class IndexFileAnalyzer extends Markdown
return parent::renderParagraph($block); return parent::renderParagraph($block);
} }
/**
* @inheritdoc
*/
protected function renderList($block) protected function renderList($block)
{ {
if ($this->_chapter > 0) { if ($this->_chapter > 0) {
......
...@@ -18,6 +18,10 @@ use PHPParser_Node_Expr_Array; ...@@ -18,6 +18,10 @@ use PHPParser_Node_Expr_Array;
*/ */
class PrettyPrinter extends \phpDocumentor\Reflection\PrettyPrinter class PrettyPrinter extends \phpDocumentor\Reflection\PrettyPrinter
{ {
/**
* @param PHPParser_Node_Expr_Array $node
* @return string
*/
public function pExpr_Array(PHPParser_Node_Expr_Array $node) public function pExpr_Array(PHPParser_Node_Expr_Array $node)
{ {
return '[' . $this->pCommaSeparated($node->items) . ']'; return '[' . $this->pCommaSeparated($node->items) . ']';
......
...@@ -39,6 +39,11 @@ class BaseDoc extends Object ...@@ -39,6 +39,11 @@ class BaseDoc extends Object
public $tags = []; public $tags = [];
/**
* Checks if doc has tag of a given name
* @param string $name tag name
* @return boolean if doc has tag of a given name
*/
public function hasTag($name) public function hasTag($name)
{ {
foreach ($this->tags as $tag) { foreach ($this->tags as $tag) {
...@@ -49,6 +54,10 @@ class BaseDoc extends Object ...@@ -49,6 +54,10 @@ class BaseDoc extends Object
return false; return false;
} }
/**
* Removes tag of a given name
* @param string $name
*/
public function removeTag($name) public function removeTag($name)
{ {
foreach ($this->tags as $i => $tag) { foreach ($this->tags as $i => $tag) {
...@@ -125,6 +134,11 @@ class BaseDoc extends Object ...@@ -125,6 +134,11 @@ class BaseDoc extends Object
// return implode("", array_slice($lines, $this->startLine - 1, $this->endLine - $this->startLine + 1)); // return implode("", array_slice($lines, $this->startLine - 1, $this->endLine - $this->startLine + 1));
// } // }
/**
* Extracts first sentence out of text
* @param string $text
* @return string
*/
public static function extractFirstSentence($text) public static function extractFirstSentence($text)
{ {
if (mb_strlen($text) > 4 && ($pos = mb_strpos($text, '.', 4, 'utf-8')) !== false) { if (mb_strlen($text) > 4 && ($pos = mb_strpos($text, '.', 4, 'utf-8')) !== false) {
......
...@@ -37,6 +37,9 @@ class ClassDoc extends TypeDoc ...@@ -37,6 +37,9 @@ class ClassDoc extends TypeDoc
public $constants = []; public $constants = [];
/**
* @inheritdoc
*/
public function findSubject($subjectName) public function findSubject($subjectName)
{ {
if (($subject = parent::findSubject($subjectName)) !== null) { if (($subject = parent::findSubject($subjectName)) !== null) {
...@@ -73,9 +76,7 @@ class ClassDoc extends TypeDoc ...@@ -73,9 +76,7 @@ class ClassDoc extends TypeDoc
} }
/** /**
* @param \phpDocumentor\Reflection\ClassReflector $reflector * @inheritdoc
* @param Context $context
* @param array $config
*/ */
public function __construct($reflector = null, $context = null, $config = []) public function __construct($reflector = null, $context = null, $config = [])
{ {
......
...@@ -36,6 +36,11 @@ class Context extends Component ...@@ -36,6 +36,11 @@ class Context extends Component
public $errors = []; public $errors = [];
/**
* Returning TypeDoc for a type given
* @param string $type
* @return null|ClassDoc|InterfaceDoc|TraitDoc
*/
public function getType($type) public function getType($type)
{ {
$type = ltrim($type, '\\'); $type = ltrim($type, '\\');
...@@ -50,6 +55,10 @@ class Context extends Component ...@@ -50,6 +55,10 @@ class Context extends Component
return null; return null;
} }
/**
* Adds file to context
* @param string $fileName
*/
public function addFile($fileName) public function addFile($fileName)
{ {
$this->files[$fileName] = sha1_file($fileName); $this->files[$fileName] = sha1_file($fileName);
...@@ -71,6 +80,9 @@ class Context extends Component ...@@ -71,6 +80,9 @@ class Context extends Component
} }
} }
/**
* Updates references
*/
public function updateReferences() public function updateReferences()
{ {
// update all subclass references // update all subclass references
...@@ -208,7 +220,8 @@ class Context extends Component ...@@ -208,7 +220,8 @@ class Context extends Component
/** /**
* @param MethodDoc $method * @param MethodDoc $method
* @param ClassDoc $parent * @param ClassDoc $class
* @return mixed
*/ */
private function inheritMethodRecursive($method, $class) private function inheritMethodRecursive($method, $class)
{ {
......
...@@ -30,11 +30,17 @@ class PropertyDoc extends BaseDoc ...@@ -30,11 +30,17 @@ class PropertyDoc extends BaseDoc
public $definedBy; public $definedBy;
/**
* @return bool if property is read only
*/
public function getIsReadOnly() public function getIsReadOnly()
{ {
return $this->getter !== null && $this->setter === null; return $this->getter !== null && $this->setter === null;
} }
/**
* @return bool if property is write only
*/
public function getIsWriteOnly() public function getIsWriteOnly()
{ {
return $this->getter === null && $this->setter !== null; return $this->getter === null && $this->setter !== null;
......
...@@ -158,6 +158,7 @@ abstract class BaseRenderer extends Component ...@@ -158,6 +158,7 @@ abstract class BaseRenderer extends Component
/** /**
* @param BaseDoc $context * @param BaseDoc $context
* @return string
*/ */
private function resolveNamespace($context) private function resolveNamespace($context)
{ {
......
...@@ -27,6 +27,11 @@ abstract class GuideRenderer extends BaseRenderer ...@@ -27,6 +27,11 @@ abstract class GuideRenderer extends BaseRenderer
abstract public function render($files, $targetDir); abstract public function render($files, $targetDir);
/**
* Loads guide structure from a set of files
* @param array $files
* @return array
*/
protected function loadGuideStructure($files) protected function loadGuideStructure($files)
{ {
$chapters = []; $chapters = [];
......
...@@ -92,6 +92,9 @@ class ApiRenderer extends \yii\apidoc\templates\html\ApiRenderer ...@@ -92,6 +92,9 @@ class ApiRenderer extends \yii\apidoc\templates\html\ApiRenderer
} }
} }
/**
* @inheritdoc
*/
public function getSourceUrl($type, $line = null) public function getSourceUrl($type, $line = null)
{ {
if (is_string($type)) { if (is_string($type)) {
......
...@@ -7,8 +7,16 @@ ...@@ -7,8 +7,16 @@
namespace yii\apidoc\templates\bootstrap; namespace yii\apidoc\templates\bootstrap;
use yii\apidoc\models\TypeDoc;
/**
* Common methods for renderers
*/
trait RendererTrait trait RendererTrait
{ {
/**
* @var array official Yii extensions
*/
public $extensions = [ public $extensions = [
'apidoc', 'apidoc',
'authclient', 'authclient',
...@@ -29,6 +37,12 @@ trait RendererTrait ...@@ -29,6 +37,12 @@ trait RendererTrait
'twig', 'twig',
]; ];
/**
* Returns nav TypeDocs
* @param TypeDoc $type typedoc to take category from
* @param TypeDoc[] $types TypeDocs to filter
* @return array
*/
public function getNavTypes($type, $types) public function getNavTypes($type, $types)
{ {
if ($type === null) { if ($type === null) {
...@@ -38,6 +52,11 @@ trait RendererTrait ...@@ -38,6 +52,11 @@ trait RendererTrait
return $this->filterTypes($types, $this->getTypeCategory($type)); return $this->filterTypes($types, $this->getTypeCategory($type));
} }
/**
* Returns category of TypeDoc
* @param TypeDoc $type
* @return string
*/
protected function getTypeCategory($type) protected function getTypeCategory($type)
{ {
$extensions = $this->extensions; $extensions = $this->extensions;
...@@ -60,6 +79,13 @@ trait RendererTrait ...@@ -60,6 +79,13 @@ trait RendererTrait
return $navClasses; return $navClasses;
} }
/**
* Returns types of a given class
*
* @param TypeDoc[] $types
* @param string $navClasses
* @return array
*/
protected function filterTypes($types, $navClasses) protected function filterTypes($types, $navClasses)
{ {
switch ($navClasses) { switch ($navClasses) {
......
...@@ -10,6 +10,7 @@ namespace yii\apidoc\templates\bootstrap; ...@@ -10,6 +10,7 @@ namespace yii\apidoc\templates\bootstrap;
use Yii; use Yii;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\bootstrap\BootstrapAsset; use yii\bootstrap\BootstrapAsset;
use yii\bootstrap\Widget;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Url; use yii\helpers\Url;
use yii\helpers\Html; use yii\helpers\Html;
...@@ -48,7 +49,7 @@ use yii\helpers\Html; ...@@ -48,7 +49,7 @@ use yii\helpers\Html;
* @author Antonio Ramirez <amigo.cobos@gmail.com> * @author Antonio Ramirez <amigo.cobos@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class SideNavWidget extends \yii\bootstrap\Widget class SideNavWidget extends Widget
{ {
/** /**
* @var array list of items in the nav widget. Each array element represents a single * @var array list of items in the nav widget. Each array element represents a single
...@@ -134,7 +135,6 @@ class SideNavWidget extends \yii\bootstrap\Widget ...@@ -134,7 +135,6 @@ class SideNavWidget extends \yii\bootstrap\Widget
} }
$label = $this->encodeLabels ? Html::encode($item['label']) : $item['label']; $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];
// $options = ArrayHelper::getValue($item, 'options', []);
$items = ArrayHelper::getValue($item, 'items'); $items = ArrayHelper::getValue($item, 'items');
$url = Url::to(ArrayHelper::getValue($item, 'url', '#')); $url = Url::to(ArrayHelper::getValue($item, 'url', '#'));
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace yii\apidoc\templates\bootstrap\assets; namespace yii\apidoc\templates\bootstrap\assets;
use yii\web\AssetBundle;
use yii\web\View; use yii\web\View;
/** /**
...@@ -15,7 +16,7 @@ use yii\web\View; ...@@ -15,7 +16,7 @@ use yii\web\View;
* @author Carsten Brandt <mail@cebe.cc> * @author Carsten Brandt <mail@cebe.cc>
* @since 2.0 * @since 2.0
*/ */
class JsSearchAsset extends \yii\web\AssetBundle class JsSearchAsset extends AssetBundle
{ {
public $sourcePath = '@vendor/cebe/js-search'; public $sourcePath = '@vendor/cebe/js-search';
public $js = [ public $js = [
......
<?php <?php
use yii\apidoc\renderers\BaseRenderer;
use yii\bootstrap\Nav; use yii\bootstrap\Nav;
use yii\bootstrap\NavBar; use yii\bootstrap\NavBar;
use yii\helpers\Html; use yii\helpers\Html;
......
...@@ -127,6 +127,12 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface ...@@ -127,6 +127,12 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface
} }
} }
/**
* Renders file applying layout
* @param string $viewFile the view name
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return string
*/
protected function renderWithLayout($viewFile, $params) protected function renderWithLayout($viewFile, $params)
{ {
$output = $this->getView()->render($viewFile, $params, $this); $output = $this->getView()->render($viewFile, $params, $this);
...@@ -259,11 +265,19 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface ...@@ -259,11 +265,19 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface
. ApiMarkdown::highlight(str_replace(' ', ' ', '( ' . implode(', ', $params) . ' )'), 'php'); . ApiMarkdown::highlight(str_replace(' ', ' ', '( ' . implode(', ', $params) . ' )'), 'php');
} }
/**
* @inheritdoc
*/
public function generateApiUrl($typeName) public function generateApiUrl($typeName)
{ {
return $this->generateFileName($typeName); return $this->generateFileName($typeName);
} }
/**
* Generates file name for API page for a given type
* @param string $typeName
* @return string
*/
protected function generateFileName($typeName) protected function generateFileName($typeName)
{ {
return strtolower(str_replace('\\', '-', $typeName)) . '.html'; return strtolower(str_replace('\\', '-', $typeName)) . '.html';
...@@ -287,7 +301,10 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface ...@@ -287,7 +301,10 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface
return Html::a($text, null, $options); return Html::a($text, null, $options);
} }
public function getSourceUrl($type) /**
* @inheritdoc
*/
public function getSourceUrl($type, $line = null)
{ {
return null; return null;
} }
......
...@@ -35,6 +35,9 @@ abstract class GuideRenderer extends BaseGuideRenderer ...@@ -35,6 +35,9 @@ abstract class GuideRenderer extends BaseGuideRenderer
private $_targetDir; private $_targetDir;
/**
* @inheritdoc
*/
public function init() public function init()
{ {
parent::init(); parent::init();
...@@ -65,9 +68,10 @@ abstract class GuideRenderer extends BaseGuideRenderer ...@@ -65,9 +68,10 @@ abstract class GuideRenderer extends BaseGuideRenderer
} }
/** /**
* Renders a given [[Context]]. * Renders a set of files given into target directory.
* *
* @param Controller $controller the apidoc controller instance. Can be used to control output. * @param array $files
* @param string $targetDir
*/ */
public function render($files, $targetDir) public function render($files, $targetDir)
{ {
...@@ -112,6 +116,11 @@ abstract class GuideRenderer extends BaseGuideRenderer ...@@ -112,6 +116,11 @@ abstract class GuideRenderer extends BaseGuideRenderer
} }
} }
/**
* Given markdown file name generates resulting html file name
* @param string $file markdown file name
* @return string
*/
protected function generateGuideFileName($file) protected function generateGuideFileName($file)
{ {
return $this->guidePrefix . basename($file, '.md') . '.html'; return $this->guidePrefix . basename($file, '.md') . '.html';
...@@ -128,6 +137,11 @@ abstract class GuideRenderer extends BaseGuideRenderer ...@@ -128,6 +137,11 @@ abstract class GuideRenderer extends BaseGuideRenderer
// return $refs; // return $refs;
} }
/**
* Adds guide name to link URLs in markdown
* @param string $content
* @return string
*/
protected function fixMarkdownLinks($content) protected function fixMarkdownLinks($content)
{ {
$content = preg_replace('/href\s*=\s*"([^"\/]+)\.md(#.*)?"/i', 'href="' . $this->guidePrefix . '\1.html\2"', $content); $content = preg_replace('/href\s*=\s*"([^"\/]+)\.md(#.*)?"/i', 'href="' . $this->guidePrefix . '\1.html\2"', $content);
...@@ -146,9 +160,7 @@ abstract class GuideRenderer extends BaseGuideRenderer ...@@ -146,9 +160,7 @@ abstract class GuideRenderer extends BaseGuideRenderer
} }
/** /**
* Generate an url to a type in apidocs * @inheritdoc
* @param $typeName
* @return mixed
*/ */
public function generateApiUrl($typeName) public function generateApiUrl($typeName)
{ {
......
...@@ -54,11 +54,17 @@ class ApiRenderer extends \yii\apidoc\templates\html\ApiRenderer ...@@ -54,11 +54,17 @@ class ApiRenderer extends \yii\apidoc\templates\html\ApiRenderer
} }
} }
/**
* @inheritdoc
*/
public function generateApiUrl($typeName) public function generateApiUrl($typeName)
{ {
return strtolower(str_replace('\\', '-', $typeName)); return strtolower(str_replace('\\', '-', $typeName));
} }
/**
* @inheritdoc
*/
protected function generateFileName($typeName) protected function generateFileName($typeName)
{ {
return $this->generateApiUrl($typeName) . '.html'; return $this->generateApiUrl($typeName) . '.html';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment