Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup #187

Merged
merged 13 commits into from
Jan 14, 2025
2 changes: 1 addition & 1 deletion phpdotnet/phd/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function autoload($name)
}

/**
* @var array<string> Absolute pathnames to package directories
* @param array<string> $dirs Absolute pathnames to package directories
*/
public static function setPackageDirs(array $dirs): void {
self::$package_dirs = $dirs;
Expand Down
10 changes: 5 additions & 5 deletions phpdotnet/phd/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ class Config
public string $outputFilename = '';
/** @var resource */
public $phpErrorOutput = \STDERR;
public string $phpErrorColor = '01;31'; // Red
public string|false $phpErrorColor = '01;31'; // Red
/** @var resource */
public $userErrorOutput = \STDERR;
public string $userErrorColor = '01;33'; // Yellow
public string|false $userErrorColor = '01;33'; // Yellow
/** @var resource */
public $phdInfoOutput = \STDOUT;
public string $phdInfoColor = '01;32'; // Green
public string|false $phdInfoColor = '01;32'; // Green
/** @var resource */
public $phdWarningOutput = \STDOUT;
public string $phdWarningColor = '01;35'; // Magenta
public string|false $phdWarningColor = '01;35'; // Magenta
public string $highlighter = 'phpdotnet\\phd\\Highlighter';
/** @var array<string> */
public array $package =['Generic'];
Expand Down Expand Up @@ -68,7 +68,7 @@ public function __construct() {
/**
* Sets one or more configuration options from an array
*
* @param array<string, mixed>
* @param array<string, mixed> $configOptions
*/
public function init(array $configOptions): void {
foreach ($configOptions as $option => $value) {
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ abstract public function CDATA($value);
* @param integer $type Format of description, Format::SDESC or
* Format::LDESC
*
* @return string Relative or absolute URI to access $for
* @return string|null|void Relative or absolute URI to access $for
*/
abstract public function createLink(
$for, &$desc = null, $type = Format::SDESC
Expand Down Expand Up @@ -122,7 +122,7 @@ abstract public function appendData($data);
* Value is either Render::OPEN or Render::CLOSE
*
* @param integer $event Event flag (see Render class)
* @param mixed $val Additional value flag. Depends
* @param mixed $value Additional value flag. Depends
* on $event type
*
* @return void
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Format/Abstract/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function add($type, $option = null) {
$this->lineJump();
break;
case self::DRAW_LINE:
$this->traceLine($option);
$this->traceLine();
break;
case self::LINE_JUMP:
if ($option)
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Highlighter
*
* @param string $format Output format (pdf, xhtml, troff, ...)
*
* @return PhDHighlighter Highlighter object
* @return Highlighter Highlighter object
*/
public static function factory($format)
{
Expand Down Expand Up @@ -75,7 +75,7 @@ public function highlight($text, $role, $format)
} catch (\ParseException $e) {
trigger_error(vsprintf("Parse error while highlighting PHP code: %s\nText: %s", [(string) $e, $text]), E_USER_WARNING);

return '<pre class="'. ($role ? $role . 'code' : 'programlisting') .'">'
return '<pre class="'. $role . 'code">'
. htmlspecialchars($text, ENT_QUOTES, 'UTF-8')
. "</pre>\n";
}
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Highlighter/GeSHi.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Highlighter_GeSHi extends Highlighter
*
* @param string $format Output format (pdf, xhtml, troff, ...)
*
* @return PhDHighlighter Highlighter object
* @return Highlighter Highlighter object
*/
public static function factory($format)
{
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Highlighter/GeSHi11x.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Highlighter_GeSHi11x extends Highlighter
*
* @param string $format Output format (pdf, xhtml, troff, ...)
*
* @return PhDHighlighter Highlighter object
* @return Highlighter Highlighter object
*/
public static function factory($format)
{
Expand Down Expand Up @@ -122,7 +122,7 @@ public function highlight($text, $role, $format)
*
* @param string $role Source code role to use (php, xml, html, ...)
*
* @return string Language name for GeSHi or null if not found.
* @return ?string Language name for GeSHi or null if not found.
*/
protected function getGeSHiLanguage($role)
{
Expand Down
6 changes: 3 additions & 3 deletions phpdotnet/phd/Options/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function option_outputfilename(string $k, mixed $v): array
}

/**
* @return array<string, string>
* @return array<string, array<string>>
*/
public function option_p(string $k, mixed $v): array
{
Expand Down Expand Up @@ -288,15 +288,15 @@ public function option_package(string $k, mixed $v): array
}

/**
* @return array<string, string>
* @return array<string, true>
*/
public function option_q(string $k, mixed $v): array
{
return $this->option_quit($k, $v);
}

/**
* @return array<string, string>
* @return array<string, true>
*/
public function option_quit(string $k, mixed $v): array
{
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/TocFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function close()
* Value is either Render::OPEN or Render::CLOSE
*
* @param integer $event Event flag (see Render class)
* @param mixed $val Additional value flag. Depends
* @param mixed $value Additional value flag. Depends
* on $event type
*
* @return void
Expand Down Expand Up @@ -490,7 +490,7 @@ public function CDATA($value)
* to overwrite this method to return full absolute URIs,
* or modify $targetBaseUri.
*
* @param string $id Chunk ID
* @param string $for Chunk ID
* @param string &$desc Description of link, to be filled if neccessary.
* Not used here.
* @param integer $type Format of description, Format::SDESC or
Expand Down
16 changes: 7 additions & 9 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML {
'constructorsynopsis' => 'format_methodsynopsis',
'destructorsynopsis' => 'format_methodsynopsis',
'emphasis' => 'format_emphasis',
'enumname' => 'span',
'entry' => array (
/* DEFAULT */ 'format_entry',
'row' => array(
Expand Down Expand Up @@ -137,7 +136,6 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML {
'literal' => 'format_literal',
'literallayout' => 'pre',
'link' => 'format_link',
'xref' => 'format_xref',
'manvolnum' => 'format_manvolnum',
'inlinemediaobject' => 'format_mediaobject',
'mediaobject' => 'format_mediaobject',
Expand Down Expand Up @@ -759,7 +757,7 @@ public function format_literal($open, $name, $attrs)
public function format_literal_text($value, $tag) {
switch ($this->getRole()) {
case 'infdec':
$value = (float)$value;
$value = (string) (float)$value;
$p = strpos($value, '.');
$str = substr($value, 0, $p + 1);
$str .= '<span style="text-decoration: overline;">';
Expand Down Expand Up @@ -840,7 +838,7 @@ public function format_container_chunk_top($open, $name, $attrs, $props) {
$this->CURRENT_CHUNK = $id;
$this->notify(Render::CHUNK, Render::CLOSE);
$toc = "";
if (!in_array($id, $this->TOC_WRITTEN ?? [])) {
if (!in_array($id, $this->TOC_WRITTEN)) {
$toc = $this->createTOC($id, $name, $props);
}

Expand Down Expand Up @@ -877,7 +875,7 @@ public function format_container_chunk_below($open, $name, $attrs, $props) {
}

$toc = '<ol>';
if (!in_array($id, $this->TOC_WRITTEN ?? [])) {
if (!in_array($id, $this->TOC_WRITTEN)) {
$toc = $this->createTOC($id, $name, $props);
}
$toc .= "</ol>\n";
Expand Down Expand Up @@ -2005,8 +2003,8 @@ public function format_table($open, $name, $attrs, $props) {
if (isset($this->cchunk["tablefootnotes"]) && $this->cchunk["tablefootnotes"]) {
$opts = array(Reader::XMLNS_DOCBOOK => array());

$str = $this->format_tbody(true, "footnote", $opts, $props);
$str .= $this->format_row(true, "footnote", $opts, $props);
$str = $this->format_tbody(true, "footnote", $opts);
$str .= $this->format_row(true, "footnote", $opts);
$str .= $this->format_entry(true, "footnote", $opts, $props+array("colspan" => $this->getColCount()));

foreach ($this->cchunk["tablefootnotes"] as $k => $noteid) {
Expand All @@ -2017,8 +2015,8 @@ public function format_table($open, $name, $attrs, $props) {

}
$str .= $this->format_entry(false, "footnote", $opts, $props);
$str .= $this->format_row(false, "footnote", $opts, $props);
$str .= $this->format_tbody(false, "footnote", $opts, $props);
$str .= $this->format_row(false, "footnote", $opts);
$str .= $this->format_tbody(false, "footnote", $opts);

$this->cchunk["tablefootnotes"] = $this->dchunk["tablefootnotes"];
}
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/IDE/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct($dir)
* Loads a function file and returns a Package_IDE_API_Function.
*
* @param string $filename File of the function.
* @return Package_IDE_API_Function Object representing the function.
* @return ?Package_IDE_API_Function Object representing the function.
*/
private function loadFunction($filename)
{
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/IDE/API/Function.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Package_IDE_API_Function
/**
* Creates a new instance of Package_IDE_API_Function.
*
* @param SimpleXMLElement $xmlElement A new SimpleXMLElement
* @param \SimpleXMLElement $xmlElement A new SimpleXMLElement
* of the function file.
*/
public function __construct(\SimpleXMLElement $xmlElement)
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/IDE/API/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Package_IDE_API_Param
/**
* Creates a new instance.
*
* @param SimpleXMLElement $xmlElement
* @param \SimpleXMLElement $xmlElement
*/
public function __construct(\SimpleXMLElement $xmlElement)
{
Expand Down
5 changes: 4 additions & 1 deletion phpdotnet/phd/Package/IDE/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ function writeChunk() {
public function renderHTML() {
static $format = null;
if ($format == null) {
$format = new Package_Generic_ChunkedXHTML($this->config);
$format = new Package_Generic_ChunkedXHTML(
$this->config,
$this->outputHandler
);
}
return $format->parse(trim(ReaderKeeper::getReader()->readInnerXML()));
}
Expand Down
5 changes: 3 additions & 2 deletions phpdotnet/phd/Package/IDE/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php
use phpdotnet\phd as PhD;

define('__INSTALLDIR__', '@php_dir@' == '@'.'php_dir@' ? dirname(dirname(dirname(dirname(__DIR__)))) : '@php_dir@');
require dirname(__DIR__, 2) . 'constants.php';
define('DS', DIRECTORY_SEPARATOR);

require __INSTALLDIR__ . DS . 'phpdotnet' . DS . 'phd' . DS . 'Autoloader.php';
Expand All @@ -11,7 +11,8 @@
spl_autoload_register(array("phpdotnet\\phd\\Autoloader", "autoload"));

//FIXME Remove this call to Config
PhD\Config::init(array());
$config = new PhD\Config;
$config->init(array());

function usage()
{
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/PEAR/CHM.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ protected function appendChm($name, $ref, $hasChild) {
if ($hasChild) fwrite($this->hhcStream, "{$this->offset(2)}<ul>\n");
fwrite($this->hhkStream, " <li><object type=\"text/sitemap\">\n" .
" <param name=\"Local\" value=\"{$ref}\">\n" .
" <param name=\"Name\" value=\"" . htmlentities(self::cleanIndexName($name, ENT_COMPAT, "UTF-8")) . "\">\n" .
" <param name=\"Name\" value=\"" . htmlentities(self::cleanIndexName($name), ENT_COMPAT, "UTF-8") . "\">\n" .
" </object>\n");
} elseif ($this->flags & Render::CLOSE) {
if ($hasChild) {
Expand Down
5 changes: 2 additions & 3 deletions phpdotnet/phd/Package/PEAR/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ abstract class Package_PEAR_XHTML extends Package_Generic_XHTML {
'phd:toc' => 'format_phd_toc',
'phpdoc:exception' => 'format_exception_chunk',
'releaseinfo' => 'format_div',
'replaceable' => 'span',
'refname' => 'format_refname',
'refnamediv' => 'format_suppressed_tags',
'refpurpose' => 'format_refpurpose',
Expand Down Expand Up @@ -678,8 +677,8 @@ public function format_phd_pearapi_text($value, $tag)
* Highlighting an such is done in format_programlisting_text()
*
*
* @param string $value Value of the text to format.
* @param string $tag Tag name
* @param string $open Whether we should open or close this element
* @param string $name Tag name
* @param array $attrs Array of attributes
*
* @return string Generated programlisting html
Expand Down
1 change: 1 addition & 0 deletions phpdotnet/phd/Package/PHP/EnhancedCHM.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function footer($id) {
if ($noteUser) {
$noteUser = '<strong class="user">' . htmlspecialchars($noteUser) . '</strong>';
}
$noteTimestamp = $noteTimestamp === "" ? null : (int) $noteTimestamp;
$noteDate = '<a href="#' . $noteId . '" class="date">' . date("d-M-Y h:i", $noteTimestamp) . '</a>';
$anchor = '<a name="' . $noteId . '""></a>';

Expand Down
3 changes: 1 addition & 2 deletions phpdotnet/phd/Package/PHP/Manpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
class Package_PHP_Manpage extends Package_Generic_Manpage {

protected $elementmap = array(
'phpdoc:varentry' => 'format_chunk',
'phpdoc:classref' => 'format_chunk',
'phpdoc:exception' => 'format_chunk',
'phpdoc:exceptionref' => 'format_chunk',
Expand Down Expand Up @@ -64,7 +63,7 @@ public function update($event, $value = null) {
}
break;
default:
return parent::update($event, $value);
parent::update($event, $value);
break;
}
}
Expand Down
5 changes: 2 additions & 3 deletions phpdotnet/phd/Package/PHP/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@ public function format_type_methodparam_text($type, $tagname) {

public function format_type_text($type, $tagname) {
$t = strtr($this->normalizeFQN($type), ["_" => "-", "\\" => "-"]);
$fragment = "";

switch($t) {
case "void":
Expand Down Expand Up @@ -717,10 +716,10 @@ public function format_type_text($type, $tagname) {

$classNames = ($type === "?") ? ($tagname . ' null') : ($tagname . ' ' . ltrim($type, "\\"));
if ($href && $this->chunked) {
return '<a href="' .$href. $this->getExt().($fragment ? "#$fragment" : ""). '" class="' . $classNames . '">' .$type. '</a>';
return '<a href="' .$href. $this->getExt(). '" class="' . $classNames . '">' .$type. '</a>';
}
if ($href) {
return '<a href="#' .($fragment ? $fragment : $href). '" class="' . $classNames . '">' .$type. '</a>';
return '<a href="#' .$href. '" class="' . $classNames . '">' .$type. '</a>';
}
return '<span class="' . $classNames . '">' .$type. '</span>';
}
Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/ReaderKeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function getReader()
/**
* Removes the reader from the top of the stack.
*
* @return void
* @return mixed
*/
public static function popReader()
{
Expand Down
Loading