@@ -13,8 +13,9 @@ use phper::{
1313 classes:: {
1414 ClassEntity , ClassEntry , InterfaceEntity , Visibility , array_access_class, iterator_class,
1515 } ,
16- functions:: Argument ,
16+ functions:: { Argument , ReturnType } ,
1717 modules:: Module ,
18+ types:: { ArgumentTypeHint , ReturnTypeHint } ,
1819 values:: ZVal ,
1920} ;
2021use std:: { collections:: HashMap , convert:: Infallible } ;
@@ -86,28 +87,39 @@ fn integrate_foo(module: &mut Module) {
8687 class. implements ( array_access_class) ;
8788
8889 // Implement Iterator interface.
89- class. add_method ( "current" , Visibility :: Public , |this, _arguments| {
90- let state = this. as_state ( ) ;
91- Ok :: < _ , phper:: Error > ( format ! ( "Current: {}" , state. position) )
92- } ) ;
93- class. add_method ( "key" , Visibility :: Public , |this, _arguments| {
94- let state = this. as_state ( ) ;
95- Ok :: < _ , phper:: Error > ( state. position as i64 )
96- } ) ;
97- class. add_method ( "next" , Visibility :: Public , |this, _arguments| {
98- let state = this. as_mut_state ( ) ;
99- state. position += 1 ;
100- Ok :: < _ , Infallible > ( ( ) )
101- } ) ;
102- class. add_method ( "rewind" , Visibility :: Public , |this, _arguments| {
103- let state = this. as_mut_state ( ) ;
104- state. position = 0 ;
105- Ok :: < _ , Infallible > ( ( ) )
106- } ) ;
107- class. add_method ( "valid" , Visibility :: Public , |this, _arguments| {
108- let state = this. as_state ( ) ;
109- Ok :: < _ , Infallible > ( state. position < 3 )
110- } ) ;
90+ class
91+ . add_method ( "current" , Visibility :: Public , |this, _arguments| {
92+ let state = this. as_state ( ) ;
93+ Ok :: < _ , phper:: Error > ( format ! ( "Current: {}" , state. position) )
94+ } )
95+ . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Mixed ) ) ;
96+
97+ class
98+ . add_method ( "key" , Visibility :: Public , |this, _arguments| {
99+ let state = this. as_state ( ) ;
100+ Ok :: < _ , phper:: Error > ( state. position as i64 )
101+ } ) . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Mixed ) ) ;
102+
103+ class
104+ . add_method ( "next" , Visibility :: Public , |this, _arguments| {
105+ let state = this. as_mut_state ( ) ;
106+ state. position += 1 ;
107+ Ok :: < _ , Infallible > ( ( ) )
108+ } ) . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Void ) ) ;
109+
110+ class
111+ . add_method ( "rewind" , Visibility :: Public , |this, _arguments| {
112+ let state = this. as_mut_state ( ) ;
113+ state. position = 0 ;
114+ Ok :: < _ , Infallible > ( ( ) )
115+ } ) . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Void ) ) ;
116+
117+ class
118+ . add_method ( "valid" , Visibility :: Public , |this, _arguments| {
119+ let state = this. as_state ( ) ;
120+ Ok :: < _ , Infallible > ( state. position < 3 )
121+ } )
122+ . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Bool ) ) ;
111123
112124 // Implement ArrayAccess interface.
113125 class
@@ -116,7 +128,8 @@ fn integrate_foo(module: &mut Module) {
116128 let state = this. as_state ( ) ;
117129 Ok :: < _ , phper:: Error > ( state. array . contains_key ( & offset) )
118130 } )
119- . argument ( Argument :: by_val ( "offset" ) ) ;
131+ . argument ( Argument :: by_val ( "offset" ) . with_type_hint ( ArgumentTypeHint :: Mixed ) )
132+ . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Bool ) ) ;
120133
121134 class
122135 . add_method ( "offsetGet" , Visibility :: Public , |this, arguments| {
@@ -125,7 +138,8 @@ fn integrate_foo(module: &mut Module) {
125138 let val = state. array . get_mut ( & offset) . map ( |val| val. ref_clone ( ) ) ;
126139 Ok :: < _ , phper:: Error > ( val)
127140 } )
128- . argument ( Argument :: by_val ( "offset" ) ) ;
141+ . argument ( Argument :: by_val ( "offset" ) . with_type_hint ( ArgumentTypeHint :: Mixed ) )
142+ . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Mixed ) ) ;
129143
130144 class
131145 . add_method ( "offsetSet" , Visibility :: Public , |this, arguments| {
@@ -135,7 +149,11 @@ fn integrate_foo(module: &mut Module) {
135149 state. array . insert ( offset, value) ;
136150 Ok :: < _ , phper:: Error > ( ( ) )
137151 } )
138- . arguments ( [ Argument :: by_val ( "offset" ) , Argument :: by_val ( "value" ) ] ) ;
152+ . arguments ( [
153+ Argument :: by_val ( "offset" ) . with_type_hint ( ArgumentTypeHint :: Mixed ) ,
154+ Argument :: by_val ( "value" ) . with_type_hint ( ArgumentTypeHint :: Mixed ) ,
155+ ] )
156+ . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Void ) ) ;
139157
140158 class
141159 . add_method ( "offsetUnset" , Visibility :: Public , |this, arguments| {
@@ -144,7 +162,8 @@ fn integrate_foo(module: &mut Module) {
144162 state. array . remove ( & offset) ;
145163 Ok :: < _ , phper:: Error > ( ( ) )
146164 } )
147- . argument ( Argument :: by_val ( "offset" ) ) ;
165+ . argument ( Argument :: by_val ( "offset" ) . with_type_hint ( ArgumentTypeHint :: Mixed ) )
166+ . return_type ( ReturnType :: by_val ( ReturnTypeHint :: Void ) ) ;
148167
149168 module. add_class ( class) ;
150169}
0 commit comments