Skip to content

Commit 0dc623b

Browse files
committed
refacotr: update the exception style.
Signed-off-by: ytetsuro <phper.0o0@gmail.com>
1 parent df83c7e commit 0dc623b

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

system/HTTP/DownloadResponse.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
* @filesource
3737
*/
3838
use CodeIgniter\HTTP\Exceptions\HTTPException;
39-
use BadMethodCallException;
40-
use LogicException;
39+
use CodeIgniter\Exceptions\DownloadException;
4140
use CodeIgniter\Files\File;
4241
use Config\Mimes;
4342

@@ -107,7 +106,7 @@ public function setBinary(string $binary)
107106
{
108107
if ($this->file !== null)
109108
{
110-
throw new BadMethodCallException('When setting filepath can not set binary.');
109+
throw DownloadException::forCannotSetBinary();
111110
}
112111

113112
$this->binary = $binary;
@@ -122,7 +121,7 @@ public function setFilePath(string $filepath)
122121
{
123122
if ($this->binary !== null)
124123
{
125-
throw new BadMethodCallException('When setting binary can not set filepath.');
124+
throw DownloadException::forCannotSetFilePath($filepath);
126125
}
127126

128127
$this->file = new File($filepath, true);
@@ -368,8 +367,7 @@ public function noCache(): self
368367
*/
369368
public function setCache(array $options = [])
370369
{
371-
// @todo: Should I make exceptions?
372-
throw new BadMethodCallException('It does not supported caching for downloading.');
370+
throw DownloadException::forCannotSetCache();
373371
}
374372

375373
//--------------------------------------------------------------------
@@ -489,7 +487,7 @@ public function sendBody()
489487
return $this->sendBodyByFilePath();
490488
}
491489

492-
throw new LogicException('Not found download body source.');
490+
throw DownloadException::forNotFoundDownloadSource();
493491
}
494492

495493
/**

tests/system/HTTP/DownloadResponseTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
use CodeIgniter\Files\Exceptions\FileNotFoundException;
55
use DateTime;
66
use DateTimeZone;
7-
use BadMethodCallException;
8-
use InvalidArgumentException;
9-
use LogicException;
7+
use CodeIgniter\Exceptions\DownloadException;
108

119
class DownloadResponseTest extends \CIUnitTestCase
1210
{
@@ -119,15 +117,15 @@ public function testCantSetCache()
119117
{
120118
$response = new DownloadResponse('unit-test.txt', true);
121119

122-
$this->expectException(BadMethodCallException::class);
120+
$this->expectException(DownloadException::class);
123121
$response->setCache();
124122
}
125123

126124
public function testWhenFilepathIsSetBinaryCanNotBeSet()
127125
{
128126
$response = new DownloadResponse('unit-test.txt', true);
129127

130-
$this->expectException(BadMethodCallException::class);
128+
$this->expectException(DownloadException::class);
131129
$response->setFilePath(__FILE__);
132130
$response->setBinary('test');
133131
}
@@ -136,7 +134,7 @@ public function testWhenBinaryIsSetFilepathCanNotBeSet()
136134
{
137135
$response = new DownloadResponse('unit-test.txt', true);
138136

139-
$this->expectException(BadMethodCallException::class);
137+
$this->expectException(DownloadException::class);
140138
$response->setBinary('test');
141139
$response->setFilePath(__FILE__);
142140
}
@@ -248,7 +246,7 @@ public function testThrowExceptionWhenNoSetDownloadSource()
248246
{
249247
$response = new DownloadResponse('unit-test.php', false);
250248

251-
$this->expectException(LogicException::class);
249+
$this->expectException(DownloadException::class);
252250
$response->sendBody();
253251
}
254252
}

0 commit comments

Comments
 (0)