Skip to content

Commit e83bd56

Browse files
committed
more doc fixes
phpdoc doesn't seem to recognise types on array returns
1 parent e1fd2d7 commit e83bd56

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

examples/generate_phpdoc.rb

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ def enum?(name)
5656
return false
5757
end
5858

59-
# map Ruby type names to PHP type names
59+
# map Ruby type names to PHP argument type names
6060
$to_php_map = {
6161
"Vips::Image" => "Image",
6262
"Image" => "Image",
6363
"Array<Integer>" => "integer[]|integer",
6464
"Array<Double>" => "float[]|float",
65-
"Array<Image>" => "Image[]",
65+
"Array<Image>" => "Image[]|image",
6666
"Integer" => "integer",
6767
"gint" => "integer",
6868
"guint64" => "integer",
@@ -77,8 +77,29 @@ def enum?(name)
7777
"gpointer" => "string",
7878
}
7979

80-
def type_to_php(type)
81-
return $to_php_map[type] if $to_php_map.include?(type)
80+
# php result type names are different, annoyingly, and very restricted
81+
$to_php_result_map = {
82+
"Vips::Image" => "Image",
83+
"Image" => "Image",
84+
"Array<Integer>" => "array",
85+
"Array<Double>" => "array",
86+
"Array<Image>" => "array",
87+
"Integer" => "integer",
88+
"gint" => "integer",
89+
"guint64" => "integer",
90+
"Double" => "float",
91+
"gdouble" => "float",
92+
"Float" => "float",
93+
"String" => "string",
94+
"Boolean" => "bool",
95+
"gboolean" => "bool",
96+
"Vips::Blob" => "string",
97+
"gchararray" => "string",
98+
"gpointer" => "string",
99+
}
100+
101+
def type_to_php(map, type)
102+
return map[type] if map.include?(type)
82103
return "string" if enum? type
83104

84105
# no mapping found
@@ -88,7 +109,11 @@ def type_to_php(type)
88109

89110
class Vips::Argument
90111
def to_php
91-
type_to_php type
112+
type_to_php $to_php_map, type
113+
end
114+
115+
def to_php_result
116+
type_to_php $to_php_result_map, type
92117
end
93118
end
94119

@@ -151,7 +176,7 @@ def generate_operation(file, op)
151176
if required_output.length == 0
152177
file << "void "
153178
elsif required_output.length == 1
154-
file << "#{required_output[0].to_php} "
179+
file << "#{required_output[0].to_php_result} "
155180
else
156181
# we generate a Returns: block for this case, see below
157182
file << "array "
@@ -272,7 +297,7 @@ def generate_class(file, gtype)
272297
Vips::Image.properties.each do |name|
273298
php_name = name.tr "-", "_"
274299
p = Vips::Image.property name
275-
file << " * @property #{type_to_php p.value_type.name} "
300+
file << " * @property #{type_to_php $to_php_map, p.value_type.name} "
276301
file << "$#{php_name} #{p.blurb}\n"
277302
if enum? p.value_type.name
278303
php_name = p.value_type.name.tap{|s| s.slice!("Vips")}

src/ImageAutodoc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
* @method Image complex2(Image $right, string $cmplx, array $options = []) Complex binary operations on two images.
5858
* @see OperationComplex2 for possible values for $cmplx
5959
* @method Image complexform(Image $right, array $options = []) Form a complex image from two real images.
60-
* @method static Image sum(Image[] $in, array $options = []) Sum an array of images.
60+
* @method static Image sum(Image[]|image $in, array $options = []) Sum an array of images.
6161
* @method Image invert(array $options = []) Invert an image.
6262
* @method Image linear(float[]|float $a, float[]|float $b, array $options = []) Calculate (a * in + b).
6363
* @method Image math(string $math, array $options = []) Apply a math operation to an image.
@@ -98,7 +98,7 @@
9898
* 'rows' => @type Image First non-zero pixel in row.
9999
* ];
100100
* @method Image measure(integer $h, integer $v, array $options = []) Measure a set of patches on a colour chart.
101-
* @method float[]|float getpoint(integer $x, integer $y, array $options = []) Read a point from an image.
101+
* @method array getpoint(integer $x, integer $y, array $options = []) Read a point from an image.
102102
* @method Image copy(array $options = []) Copy an image.
103103
* @method Image tilecache(array $options = []) Cache an image as a set of tiles.
104104
* @method Image linecache(array $options = []) Cache an image as a set of lines.
@@ -110,7 +110,7 @@
110110
* @method Image insert(Image $sub, integer $x, integer $y, array $options = []) Insert image @sub into @main at @x, @y.
111111
* @method Image join(Image $in2, string $direction, array $options = []) Join a pair of images.
112112
* @see Direction for possible values for $direction
113-
* @method static Image arrayjoin(Image[] $in, array $options = []) Join an array of images.
113+
* @method static Image arrayjoin(Image[]|image $in, array $options = []) Join an array of images.
114114
* @method Image smartcrop(integer $width, integer $height, array $options = []) Extract an area from an image.
115115
* @method Image extract_band(integer $band, array $options = []) Extract band from an image.
116116
* @method Image bandjoin_const(float[]|float $c, array $options = []) Append a constant band to an image.

0 commit comments

Comments
 (0)