Skip to content

Commit f1ef62f

Browse files
committed
DocGen Updates so ReturnTypes are now covered.
1 parent 474fd8e commit f1ef62f

5 files changed

Lines changed: 38 additions & 14 deletions

File tree

docgen/export.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
echo "There are " . count($gen->uniqueTypes) . " unique data types \n\n";
4747
print_r($gen->uniqueTypes);
4848

49-
// $gen->extend('Phaser.Sprite');
50-
// $sprite = $gen->get('Phaser.Sprite');
51-
// $sprite->export('output/');
49+
$gen->extend('Phaser.Sprite');
50+
$sprite = $gen->get('Phaser.Sprite');
51+
$sprite->export('output/');
5252

5353

5454
// echo $sprite;

docgen/output/Phaser.Sprite.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docgen/src/Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function __construct($processor, $block)
8787

8888
if ($block->getTypeBoolean('@return'))
8989
{
90-
$this->returns = new ReturnType($block->getLine('@return'));
90+
$this->returns = new ReturnType($this->processor, $block->getLine('@return'));
9191
}
9292

9393
}

docgen/src/Processor.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ public function parseTypes($output, $pixi, $name)
221221

222222
$types = explode('|', $output);
223223

224+
if (!is_array($types))
225+
{
226+
$types = array($output);
227+
}
228+
224229
// @param {number[]|string[]} frames - An array of numbers or strings indicating which frames to play in which order.
225230
// @param {(number[]|...number)} points - An array of 2d vectors that form the convex or concave polygon.
226231
// Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...],
@@ -331,21 +336,33 @@ public function parseTypes($output, $pixi, $name)
331336
// Valid DOM types?
332337
if (!in_array($type, $this->domTypes) && !in_array($type, $this->dataTypes))
333338
{
334-
// Not a DOM type, shall we add PIXI to the front?
335-
if ($pixi)
339+
if ($pixi === null)
336340
{
337-
if (substr($type, 0, 5) !== 'PIXI.')
341+
// It's a ReturnType but we don't know which sort
342+
if (substr($type, 0, 7) !== 'Phaser.' && substr($type, 0, 5) !== 'PIXI.' && substr($type, 0, 3) !== 'p2.')
338343
{
344+
// Going to assume PIXI here as Phaser has the return types properly namespaced
339345
$types[$key] = "PIXI.$type";
340346
}
341347
}
342348
else
343349
{
344-
if (substr($type, 0, 7) !== 'Phaser.' && substr($type, 0, 5) !== 'PIXI.' && substr($type, 0, 3) !== 'p2.')
350+
// Not a DOM type, shall we add PIXI to the front?
351+
if ($pixi)
352+
{
353+
if (substr($type, 0, 5) !== 'PIXI.')
354+
{
355+
$types[$key] = "PIXI.$type";
356+
}
357+
}
358+
else
345359
{
346-
$types[$key] = "wtf.$type";
347-
echo($name . '=');
348-
var_dump($type);
360+
if (substr($type, 0, 7) !== 'Phaser.' && substr($type, 0, 5) !== 'PIXI.' && substr($type, 0, 3) !== 'p2.')
361+
{
362+
$types[$key] = "wtf.$type";
363+
echo($name . '=');
364+
var_dump($type);
365+
}
349366
}
350367
}
351368
}

docgen/src/ReturnType.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
<?php
22
class ReturnType
33
{
4+
public $processor;
45
public $types = []; // an array containing all possible types it can be: string, number, etc
56
public $help = [];
67

7-
public function __construct($line)
8+
public function __construct($processor, $line)
89
{
10+
$this->processor = $processor;
11+
912
if (preg_match("/.*@return\s?{(\S*)} ?(.*)/", $line, $output))
1013
{
11-
$this->types = explode('|', $output[1]);
14+
// $this->types = explode('|', $output[1]);
15+
16+
// Don't know if this is a Pixi or a Phaser return type
17+
$this->types = $this->processor->parseTypes($output[1], null, '');
18+
1219
$this->help = $output[2];
1320
}
1421
}

0 commit comments

Comments
 (0)