@@ -41,16 +41,32 @@ public function comments()
4141 * @param string $repo The repository identifier.
4242 * @param array $params Additional parameters
4343 * @return MessageInterface
44+ *
45+ * @throws \InvalidArgumentException
4446 */
4547 public function all ($ account , $ repo , $ params = array ())
4648 {
49+ $ states = array ('OPEN ' , 'MERGED ' , 'DECLINED ' );
4750 $ params = array_merge (
4851 array (
4952 'state ' => 'OPEN '
5053 ),
5154 $ params
5255 );
5356
57+ if (!is_array ($ params ['state ' ])) {
58+ $ params ['state ' ] = array ($ params ['state ' ]);
59+ }
60+
61+ array_walk (
62+ $ params ['state ' ],
63+ function ($ state ) use ($ states ) {
64+ if (!in_array ($ state , $ states )) {
65+ throw new \InvalidArgumentException (sprintf ('Unknown `state` %s ' , $ state ));
66+ }
67+ }
68+ );
69+
5470 return $ this ->getClient ()->setApiVersion ('2.0 ' )->get (
5571 sprintf ('repositories/%s/%s/pullrequests ' , $ account , $ repo ),
5672 $ params
@@ -66,6 +82,7 @@ public function all($account, $repo, $params = array())
6682 * @param array $params Additional parameters
6783 * @return MessageInterface
6884 *
85+ * @throws \InvalidArgumentException
6986 * @see https://confluence.atlassian.com/x/XAZAGQ
7087 */
7188 public function create ($ account , $ repo , $ params = array ())
@@ -85,6 +102,14 @@ public function create($account, $repo, $params = array())
85102 ));
86103 }
87104
105+ if (empty ($ params ['title ' ])) {
106+ throw new \InvalidArgumentException ('Pull request \'s title must be specified. ' );
107+ }
108+
109+ if (empty ($ params ['source ' ]['branch ' ]['name ' ])) {
110+ throw new \InvalidArgumentException ('Pull request \'s source branch name must be specified. ' );
111+ }
112+
88113 return $ this ->getClient ()->setApiVersion ('2.0 ' )->post (
89114 sprintf ('repositories/%s/%s/pullrequests ' , $ account , $ repo ),
90115 $ params ,
@@ -101,6 +126,8 @@ public function create($account, $repo, $params = array())
101126 * @param int $id ID of the pull request that will be updated
102127 * @param array $params Additional parameters
103128 * @return MessageInterface
129+ *
130+ * @throws \InvalidArgumentException
104131 */
105132 public function update ($ account , $ repo , $ id , $ params = array ())
106133 {
@@ -119,6 +146,14 @@ public function update($account, $repo, $id, $params = array())
119146 ));
120147 }
121148
149+ if (empty ($ params ['title ' ])) {
150+ throw new \InvalidArgumentException ('Pull request \'s title must be specified. ' );
151+ }
152+
153+ if (empty ($ params ['destination ' ]['branch ' ]['name ' ])) {
154+ throw new \InvalidArgumentException ('Pull request \'s destination branch name must be specified. ' );
155+ }
156+
122157 return $ this ->getClient ()->setApiVersion ('2.0 ' )->put (
123158 sprintf ('repositories/%s/%s/pullrequests/%d ' , $ account , $ repo , $ id ),
124159 $ params ,
0 commit comments