@@ -28,11 +28,11 @@ final class Queue
2828 */
2929 public function __construct ($ client , string $ name )
3030 {
31- if ($ client instanceof Client ) {
32- $ client = new ClientAdapter ($ client );
33- } elseif (!$ client instanceof \Tarantool ) {
31+ if ($ client instanceof \Tarantool ) {
32+ $ client = new TarantoolAdapter ($ client );
33+ } elseif (!$ client instanceof Client ) {
3434 throw new \InvalidArgumentException (\sprintf (
35- '%s() expects parameter 1 to be Tarantool or %s , %s given. ' ,
35+ '%s() expects parameter 1 to be %s or Tarantool , %s given. ' ,
3636 __METHOD__ , Client::class, \is_object ($ client ) ? \get_class ($ client ) : \gettype ($ client )
3737 ));
3838 }
@@ -48,68 +48,63 @@ public function getName() : string
4848
4949 public function put ($ data , array $ options = []) : Task
5050 {
51- $ args = $ options ? [$ data , $ options ] : [$ data ];
52- $ result = $ this ->client ->call ("queue.tube. $ this ->name :put " , $ args );
53-
54- return Task::createFromTuple ($ result [0 ]);
51+ return Task::createFromTuple (
52+ $ this ->client ->call ("queue.tube. $ this ->name :put " , $ data , $ options )[0 ]
53+ );
5554 }
5655
5756 public function take (float $ timeout = null ) : ?Task
5857 {
59- $ args = null === $ timeout ? [] : [$ timeout ];
60- $ result = $ this ->client ->call ("queue.tube. $ this ->name :take " , $ args );
58+ $ result = $ this ->client ->call ("queue.tube. $ this ->name :take " , $ timeout );
6159
6260 return empty ($ result [0 ]) ? null : Task::createFromTuple ($ result [0 ]);
6361 }
6462
6563 public function touch (int $ taskId , float $ increment ) : ?Task
6664 {
67- $ result = $ this ->client ->call ("queue.tube. $ this ->name :touch " , [ $ taskId , $ increment] );
65+ $ result = $ this ->client ->call ("queue.tube. $ this ->name :touch " , $ taskId , $ increment );
6866
6967 return empty ($ result [0 ]) ? null : Task::createFromTuple ($ result [0 ]);
7068 }
7169
7270 public function ack (int $ taskId ) : Task
7371 {
74- $ result = $ this -> client -> call ( " queue.tube. $ this -> name :ack " , [ $ taskId ]);
75-
76- return Task:: createFromTuple ( $ result [ 0 ] );
72+ return Task:: createFromTuple (
73+ $ this -> client -> call ( " queue.tube. $ this -> name :ack " , $ taskId )[ 0 ]
74+ );
7775 }
7876
7977 public function release (int $ taskId , array $ options = []) : Task
8078 {
81- $ args = $ options ? [$ taskId , $ options ] : [$ taskId ];
82- $ result = $ this ->client ->call ("queue.tube. $ this ->name :release " , $ args );
83-
84- return Task::createFromTuple ($ result [0 ]);
79+ return Task::createFromTuple (
80+ $ this ->client ->call ("queue.tube. $ this ->name :release " , $ taskId , $ options )[0 ]
81+ );
8582 }
8683
8784 public function peek (int $ taskId ) : Task
8885 {
89- $ result = $ this -> client -> call ( " queue.tube. $ this -> name :peek " , [ $ taskId ]);
90-
91- return Task:: createFromTuple ( $ result [ 0 ] );
86+ return Task:: createFromTuple (
87+ $ this -> client -> call ( " queue.tube. $ this -> name :peek " , $ taskId )[ 0 ]
88+ );
9289 }
9390
9491 public function bury (int $ taskId ) : Task
9592 {
96- $ result = $ this -> client -> call ( " queue.tube. $ this -> name :bury " , [ $ taskId ]);
97-
98- return Task:: createFromTuple ( $ result [ 0 ] );
93+ return Task:: createFromTuple (
94+ $ this -> client -> call ( " queue.tube. $ this -> name :bury " , $ taskId )[ 0 ]
95+ );
9996 }
10097
10198 public function kick (int $ count ) : int
10299 {
103- $ result = $ this ->client ->call ("queue.tube. $ this ->name :kick " , [$ count ]);
104-
105- return $ result [0 ][0 ];
100+ return $ this ->client ->call ("queue.tube. $ this ->name :kick " , $ count )[0 ];
106101 }
107102
108103 public function delete (int $ taskId ) : Task
109104 {
110- $ result = $ this -> client -> call ( " queue.tube. $ this -> name :delete " , [ $ taskId ]);
111-
112- return Task:: createFromTuple ( $ result [ 0 ] );
105+ return Task:: createFromTuple (
106+ $ this -> client -> call ( " queue.tube. $ this -> name :delete " , $ taskId )[ 0 ]
107+ );
113108 }
114109
115110 public function truncate () : void
@@ -126,25 +121,24 @@ public function truncate() : void
126121 */
127122 public function stats (string $ path = null )
128123 {
129- $ result = $ this ->client ->call ('queue.stats ' , [ $ this ->name ] );
124+ [ $ stats ] = $ this ->client ->call ('queue.stats ' , $ this ->name );
130125
131126 if (null === $ path ) {
132- return $ result [ 0 ][ 0 ] ;
127+ return $ stats ;
133128 }
134129
135- $ result = $ result [0 ][0 ];
136130 foreach (\explode ('. ' , $ path ) as $ key ) {
137- if (!isset ($ result [$ key ])) {
131+ if (!isset ($ stats [$ key ])) {
138132 throw new \InvalidArgumentException (\sprintf ('Invalid path "%s". ' , $ path ));
139133 }
140- $ result = $ result [$ key ];
134+ $ stats = $ stats [$ key ];
141135 }
142136
143- return $ result ;
137+ return $ stats ;
144138 }
145139
146140 public function call (string $ methodName , ...$ args ) : array
147141 {
148- return $ this ->client ->call ("queue.tube. $ this ->name : $ methodName " , $ args );
142+ return $ this ->client ->call ("queue.tube. $ this ->name : $ methodName " , ... $ args );
149143 }
150144}
0 commit comments