Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 6fdf53c

Browse files
committed
Implemented PHP::Method::Call.
1 parent 5a13869 commit 6fdf53c

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

lib/php.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module PHP
1212
autoload :Interface, 'php/syntax/interface'
1313
autoload :Literal, 'php/syntax/literal'
1414
autoload :Loop, 'php/syntax/loop'
15+
autoload :Method, 'php/syntax/method'
1516
autoload :Namespace, 'php/syntax/namespace'
1617
autoload :Node, 'php/syntax/node'
1718
autoload :Operator, 'php/syntax/operator'

lib/php/generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def process_call(exp) # FIXME
213213
if op = Operator.for(method)
214214
op.new(process(receiver), *process(arglist))
215215
else
216-
raise NotImplementedError.new(exp.inspect) # TODO: Method::Call.new(receiver, method, *arglist)
216+
Method::Call.new(process(receiver), method, *process(arglist))
217217
end
218218
end
219219
end

lib/php/syntax/method.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module PHP
2+
##
3+
# @see http://www.php.net/manual/en/language.oop5.php
4+
class Method < Expression
5+
##
6+
# @see http://www.php.net/manual/en/language.oop5.php
7+
class Call < Expression
8+
##
9+
# @return [Expression]
10+
attr_accessor :receiver
11+
12+
##
13+
# @return [Symbol]
14+
attr_accessor :method
15+
16+
##
17+
# @return [Array<Expression>]
18+
attr_accessor :arguments
19+
20+
##
21+
# @param [Expression] receiver
22+
# @param [Symbol, #to_s] method
23+
# @param [Array<Expression>] arguments
24+
def initialize(receiver, method, *arguments)
25+
@receiver = receiver
26+
@method = Identifier.new(method).to_sym
27+
@arguments = arguments
28+
end
29+
30+
##
31+
# Returns the PHP representation of this method call.
32+
#
33+
# @return [String]
34+
def to_php
35+
"#{receiver}->#{method}(#{arguments.join(', ')})"
36+
end
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)