Skip to content

Commit 0ca5692

Browse files
committed
add invalid argument exception
1 parent 875a7c2 commit 0ca5692

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

src/Api/Rooms.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Polidog\Chatwork\Entity\Factory\RoomFactory;
1414
use Polidog\Chatwork\Entity\Factory\TaskFactory;
1515
use Polidog\Chatwork\Entity\Room;
16+
use Polidog\Chatwork\Exception\InvalidArgumentException;
1617

1718
class Rooms
1819
{
@@ -104,10 +105,15 @@ public function update(Room $room)
104105
* グループチャットを退席/削除する.
105106
*
106107
* @param Room $room
107-
* @param string $actionType
108+
* @param string $actionType leave or delete
109+
* @throws InvalidArgumentException
108110
*/
109111
public function remove(Room $room, $actionType)
110112
{
113+
if ($actionType !== 'leave' && $actionType !== 'delete') {
114+
throw new InvalidArgumentException('ActionType is only leave or delete');
115+
}
116+
111117
$this->client->delete(
112118
"rooms/{$room->roomId}",
113119
[

src/Api/Rooms/Tasks.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,20 @@ public function detail($id)
7070
}
7171

7272
/**
73-
* @TODO api見直し
74-
*
75-
* @param CollectionInterface $collection
73+
* @param string $body
74+
* @param array $toIds
75+
* @param \DateTime|null $limit
76+
* @return int[] task ids
7677
*/
77-
public function create(CollectionInterface $collection)
78+
public function create(string $body, array $toIds, \DateTime $limit = null) : array
7879
{
79-
$toIds = [];
80-
foreach ($collection as $entity) {
81-
$toIds[] = $entity->account->accountId;
82-
}
83-
84-
$task = clone $collection->get(0);
85-
$results = $this->client->post(
80+
return $this->client->post(
8681
"rooms/{$this->roomId}/tasks",
8782
[
88-
'body' => $task->body,
83+
'body' => $body,
8984
'to_ids' => implode(',', $toIds),
90-
'limit' => $task->limitTime,
85+
'limit' => $limit instanceof \DateTime ? $limit->getTimestamp() : null,
9186
]
9287
);
93-
94-
foreach ($results['task_ids'] as $key => $id) {
95-
$collection->get($key)->taskId = $id;
96-
}
9788
}
9889
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Polidog\Chatwork\Exception;
4+
5+
6+
class InvalidArgumentException extends \InvalidArgumentException implements ChatworkApiException
7+
{
8+
9+
}

0 commit comments

Comments
 (0)