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

Don't namespaces primitive arrays #359

Merged
merged 1 commit into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/docblock/elements/VarElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ public function asDom(\TheSeer\fDOM\fDOMDocument $ctx) {
$node = parent::asDom($ctx);
$type = $node->getAttribute('type');

$types = explode('|', $type);

if (count($types) > 1) {
$node->setAttribute('type', 'mixed');

foreach ($types as $oneType) {
$this->typeResolver($node, $oneType);
}

return $node;
}

if (\strpos($type, '[]')) {
$type = \mb_substr($type, 0, -2);
$node->setAttribute('type', 'array');
Expand All @@ -40,4 +52,28 @@ public function asDom(\TheSeer\fDOM\fDOMDocument $ctx) {

return $node;
}

protected function typeResolver(\TheSeer\fDOM\fDOMElement $node, string $type) {
$isArray = false;
if (substr($type, -2, 2) === '[]') {
$isArray = true;
$type = substr($type, 0, -2);
}
$nodeType = $node->appendElementNS(self::XMLNS, 'type');
$nodeType->setAttribute('full', $type);
$nodeType->setAttribute('array', $isArray?'true':'false');

if (\in_array($type, $this->types, true)) {
$nodeType->setAttribute('name', $type);
$nodeType->setAttribute('namespace', '');
return;
}

$parts = \explode('\\', $type);
$local = \array_pop($parts);
$namespace = \implode('\\', $parts);

$nodeType->setAttribute('namespace', $namespace);
$nodeType->setAttribute('name', $local);
}
}
20 changes: 20 additions & 0 deletions src/docblock/parser/GenericParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ protected function buildObject($classname, array $buffer) {
}

protected function lookupType($type) {
$types = explode('|', $type);

foreach ($types as &$oneType) {
$isArray = false;
if (substr($oneType, -2, 2) === '[]') {
$isArray = true;
$oneType = substr($oneType, 0, -2);
}

$oneType = $this->lookupOneType($oneType);

if ($isArray) {
$oneType .= '[]';
}
}

return implode('|', $types);
}

protected function lookupOneType($type) {
if ($type === 'self' || $type === 'static') {
return $this->aliasMap['::unit'];
}
Expand Down
26 changes: 26 additions & 0 deletions templates/html/components.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@
<xsl:variable name="ctx" select="pdx:docblock/pdx:var/pdx:type" />
<xsl:copy-of select="pdxf:link($ctx, '', $ctx/@full)" />
</xsl:when>
<xsl:when test="pdx:docblock/pdx:var/@type = 'array'">
<xsl:variable name="ctx" select="pdx:docblock/pdx:var/pdx:type" />
<xsl:choose>
<xsl:when test="pdx:docblock/pdx:var/@of = 'object'">
<xsl:copy-of select="pdxf:link($ctx, '', $ctx/@full)" />
</xsl:when>
<xsl:otherwise><xsl:value-of select="pdx:docblock/pdx:var/@of" /></xsl:otherwise>
</xsl:choose>[]
</xsl:when>
<xsl:when test="pdx:docblock/pdx:var/@type = 'mixed' and count(pdx:docblock/pdx:var/pdx:type) > 0">
<xsl:for-each select="pdx:docblock/pdx:var/pdx:type">
<xsl:call-template name="mixedvartype" />
</xsl:for-each>
</xsl:when>
<xsl:otherwise><xsl:value-of select="pdx:docblock/pdx:var/@type" /></xsl:otherwise>
</xsl:choose>
</xsl:if>
Expand All @@ -316,6 +330,18 @@

<!-- ######################################################################################################### -->

<xsl:template name="mixedvartype">
<span class="multiple">
<xsl:choose>
<xsl:when test="@name = @full"><xsl:value-of select="@name" /></xsl:when>
<xsl:otherwise><xsl:copy-of select="pdxf:link(., '', @full)" /></xsl:otherwise>
</xsl:choose>
<xsl:if test="@array = 'true'">[]</xsl:if>
</span>
</xsl:template>

<!-- ######################################################################################################### -->

<xsl:template name="methods">
<div class="styled">
<xsl:if test="$unit/pdx:method[@visibility='private']">
Expand Down
6 changes: 6 additions & 0 deletions templates/html/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ ul.styled {
ul.members li {
margin-bottom: 0.5em;
}
ul.members li .multiple:after {
content: "|";
}
ul.members li .multiple:last-child:after {
content: '';
}

.styled h4 {
padding:0;
Expand Down
46 changes: 46 additions & 0 deletions tests/data/issue234/src/ArrayCases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace MyNamespace;

class ArrayCases
{
/**
* @var int[]
*/
public $arrayOfInt;

/**
* @var boolean[]
*/
public $arrayOfBoolean;

/**
* @var int
*/
public $int;

/**
* @var boolean
*/
public $boolean;

/**
* @var int[]|string[]|SomeClass[]
*/
public $multipleArray;

/**
* @var int|string|SomeClass
*/
public $multiple;

/**
* @var SomeClass[]
*/
public $arrayOfObject;

/**
* @var SomeClass
*/
public $object;
}
15 changes: 15 additions & 0 deletions tests/data/issue234/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpdox xmlns="http://xml.phpdox.net/config">
<project name="Example" source="${basedir}/src" workdir="${basedir}/xml">
<collector backend="parser" />

<generator output="${basedir}/xml">

<build engine="html" enabled="true" output="html">
<template dir="${phpDox.home}/templates/html" />
<file extension="html" />
</build>

</generator>
</project>
</phpdox>