Improved documentation comments
[kohana-userguide.git] / classes / Kohana / Kodoc / Method / Param.php
bloba29c0e28165b027a92db0ea960e6d853f5c51bcd
1 <?php defined('SYSPATH') or die('No direct script access.');
2 /**
3 * Class method parameter documentation generator.
5 * @package Kohana/Userguide
6 * @category Base
7 * @author Kohana Team
8 * @copyright (c) 2008-2013 Kohana Team
9 * @license http://kohanaframework.org/license
11 class Kohana_Kodoc_Method_Param extends Kodoc {
13 /**
14 * @var object ReflectionParameter for this property
16 public $param;
18 /**
19 * @var string name of this var
21 public $name;
23 /**
24 * @var string variable type, retrieved from the comment
26 public $type;
28 /**
29 * @var string default value of this param
31 public $default;
33 /**
34 * @var string description of this parameter
36 public $description;
38 /**
39 * @var boolean is the parameter passed by reference?
41 public $reference = FALSE;
43 /**
44 * @var boolean is the parameter optional?
46 public $optional = FALSE;
48 public function __construct($method, $param)
50 $this->param = new ReflectionParameter($method, $param);
52 $this->name = $this->param->name;
54 if ($this->param->isDefaultValueAvailable())
56 $this->default = Debug::dump($this->param->getDefaultValue());
59 if ($this->param->isPassedByReference())
61 $this->reference = TRUE;
64 if ($this->param->isOptional())
66 $this->optional = TRUE;
70 public function __toString()
72 $display = '';
74 if ($this->type)
76 $display .= '<small>'.$this->type.'</small> ';
79 if ($this->reference)
81 $display .= '<small><abbr title="passed by reference">&</abbr></small> ';
84 if ($this->description)
86 $display .= '<span class="param" title="'.preg_replace('/\s+/', ' ', $this->description).'">$'.$this->name.'</span> ';
88 else
90 $display .= '$'.$this->name.' ';
93 if ($this->default)
95 $display .= '<small>= '.$this->default.'</small> ';
98 return $display;
101 } // End Kodoc_Method_Param