Skip to content

Commit caded5e

Browse files
ianfortiergithub-actions[bot]
authored andcommitted
Fix styling
1 parent 015eb6b commit caded5e

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/LoomDownloader.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,30 @@
88
class LoomDownloader
99
{
1010
private $client;
11+
1112
private $outputDirectory;
1213

13-
public function __construct(string $outputDirectory = null)
14+
public function __construct(?string $outputDirectory = null)
1415
{
15-
$this->client = new Client();
16+
$this->client = new Client;
1617
$this->outputDirectory = $outputDirectory ?? sys_get_temp_dir();
1718
}
1819

1920
public function downloadVideo($url)
2021
{
2122
$id = $this->extractId($url);
2223
$downloadUrl = $this->fetchLoomDownloadUrl($id);
23-
24+
2425
return $this->fetchVideoContent($downloadUrl);
2526
}
2627

2728
public function saveVideo($url, $destination = null)
2829
{
2930
$id = $this->extractId($url);
3031
$downloadUrl = $this->fetchLoomDownloadUrl($id);
31-
32+
3233
if ($destination === null) {
33-
$destination = $this->outputDirectory . "/{$id}.mp4";
34+
$destination = $this->outputDirectory."/{$id}.mp4";
3435
}
3536

3637
$this->ensureDirectoryExists(dirname($destination));
@@ -43,43 +44,47 @@ protected function fetchLoomDownloadUrl($id)
4344
try {
4445
$response = $this->client->post("https://www.loom.com/api/campaigns/sessions/{$id}/transcoded-url");
4546
$body = json_decode($response->getBody(), true);
47+
4648
return $body['url'];
4749
} catch (GuzzleException $e) {
48-
throw new \Exception("Failed to fetch Loom download URL: " . $e->getMessage());
50+
throw new \Exception('Failed to fetch Loom download URL: '.$e->getMessage());
4951
}
5052
}
5153

5254
protected function fetchVideoContent($url)
5355
{
5456
try {
5557
$response = $this->client->get($url);
58+
5659
return $response->getBody()->getContents();
5760
} catch (GuzzleException $e) {
58-
throw new \Exception("Failed to download video: " . $e->getMessage());
61+
throw new \Exception('Failed to download video: '.$e->getMessage());
5962
}
6063
}
6164

6265
protected function saveVideoToFile($url, $destination)
6366
{
6467
try {
6568
$this->client->get($url, ['sink' => $destination]);
69+
6670
return $destination;
6771
} catch (GuzzleException $e) {
68-
throw new \Exception("Failed to save video: " . $e->getMessage());
72+
throw new \Exception('Failed to save video: '.$e->getMessage());
6973
}
7074
}
7175

7276
protected function extractId($url)
7377
{
7478
$url = explode('?', $url)[0];
7579
$parts = explode('/', $url);
80+
7681
return end($parts);
7782
}
7883

7984
protected function ensureDirectoryExists($directory)
8085
{
81-
if (!is_dir($directory)) {
86+
if (! is_dir($directory)) {
8287
mkdir($directory, 0777, true);
8388
}
8489
}
85-
}
90+
}

tests/LoomDownloaderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
use LoomDownloader\LoomDownloader;
43
use GuzzleHttp\Client;
4+
use GuzzleHttp\Exception\RequestException;
55
use GuzzleHttp\Handler\MockHandler;
66
use GuzzleHttp\HandlerStack;
77
use GuzzleHttp\Psr7\Response;
8-
use GuzzleHttp\Exception\RequestException;
8+
use LoomDownloader\LoomDownloader;
99

1010
beforeEach(function () {
11-
$this->mockHandler = new MockHandler();
11+
$this->mockHandler = new MockHandler;
1212
$handlerStack = HandlerStack::create($this->mockHandler);
1313
$this->mockClient = new Client(['handler' => $handlerStack]);
1414
});
@@ -19,7 +19,7 @@
1919
new Response(200, [], 'fake video content')
2020
);
2121

22-
$downloader = new LoomDownloader();
22+
$downloader = new LoomDownloader;
2323
$reflector = new ReflectionClass($downloader);
2424
$clientProperty = $reflector->getProperty('client');
2525
$clientProperty->setAccessible(true);
@@ -36,7 +36,7 @@
3636
new Response(200, [], 'fake video content')
3737
);
3838

39-
$downloader = new LoomDownloader();
39+
$downloader = new LoomDownloader;
4040
$reflector = new ReflectionClass($downloader);
4141
$clientProperty = $reflector->getProperty('client');
4242
$clientProperty->setAccessible(true);
@@ -56,7 +56,7 @@
5656
new RequestException('Error Communicating with Server', new \GuzzleHttp\Psr7\Request('GET', 'test'))
5757
);
5858

59-
$downloader = new LoomDownloader();
59+
$downloader = new LoomDownloader;
6060
$reflector = new ReflectionClass($downloader);
6161
$clientProperty = $reflector->getProperty('client');
6262
$clientProperty->setAccessible(true);
@@ -71,11 +71,11 @@
7171
new RequestException('Error Downloading Video', new \GuzzleHttp\Psr7\Request('GET', 'test'))
7272
);
7373

74-
$downloader = new LoomDownloader();
74+
$downloader = new LoomDownloader;
7575
$reflector = new ReflectionClass($downloader);
7676
$clientProperty = $reflector->getProperty('client');
7777
$clientProperty->setAccessible(true);
7878
$clientProperty->setValue($downloader, $this->mockClient);
7979

8080
$downloader->downloadVideo('https://www.loom.com/share/123abc');
81-
})->throws(\Exception::class, 'Failed to download video');
81+
})->throws(\Exception::class, 'Failed to download video');

0 commit comments

Comments
 (0)