Skip to content

Commit 72ab37f

Browse files
committed
refactor: phpstan code cleanup
1 parent 06f6ef9 commit 72ab37f

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/Transcoder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* @author nystudio107
4040
* @package Transcode
4141
* @since 1.0.0
42+
* @method Settings getSettings()
4243
*/
4344
class Transcoder extends Plugin
4445
{

src/controllers/DefaultController.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
use craft\errors\AssetDisallowedExtensionException;
1515
use craft\helpers\Path as PathHelper;
1616
use craft\web\Controller;
17-
use craft\web\Response;
1817
use nystudio107\transcoder\Transcoder;
1918
use yii\base\ExitException;
2019
use yii\web\BadRequestHttpException;
21-
20+
use yii\web\Response;
2221
use function count;
2322
use function is_array;
2423

@@ -32,11 +31,6 @@ class DefaultController extends Controller
3231
// Protected Properties
3332
// =========================================================================
3433

35-
/**
36-
* @var bool|array Allows anonymous access to this controller's actions.
37-
* The actions must be in 'kebab-case'
38-
* @access protected
39-
*/
4034
protected array|bool|int $allowAnonymous = [
4135
'download-file',
4236
'progress',

src/services/Transcode.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public function getVideoUrl(string|Asset $filePath, array $videoOptions, bool $g
113113
$filePath = $this->getAssetPath($filePath);
114114

115115
if (!empty($filePath)) {
116-
$destVideoPath = $settings['transcoderPaths']['video'] . $subfolder ?? $settings['transcoderPaths']['default'];
116+
$destVideoPath = $settings['transcoderPaths']['video'] ?? $settings['transcoderPaths']['default'];
117+
$destVideoPath .= $subfolder;
117118
$destVideoPath = App::parseEnv($destVideoPath);
118119
$videoOptions = $this->coalesceOptions('defaultVideoOptions', $videoOptions);
119120

@@ -207,7 +208,8 @@ public function getVideoUrl(string|Asset $filePath, array $videoOptions, bool $g
207208

208209
// If the video file already exists and hasn't been modified, return it. Otherwise, start it transcoding
209210
if (file_exists($destVideoPath) && (@filemtime($destVideoPath) >= @filemtime($filePath))) {
210-
$url = $settings['transcoderUrls']['video'] . $subfolder ?? $settings['transcoderUrls']['default'];
211+
$url = $settings['transcoderUrls']['video'] ?? $settings['transcoderUrls']['default'];
212+
$url .= $subfolder;
211213
$result = App::parseEnv($url) . $destVideoFile;
212214
// skip encoding
213215
} elseif (!$generate) {
@@ -251,7 +253,8 @@ public function getVideoThumbnailUrl(Asset|string $filePath, array $thumbnailOpt
251253
$filePath = $this->getAssetPath($filePath);
252254

253255
if (!empty($filePath)) {
254-
$destThumbnailPath = $settings['transcoderPaths']['thumbnail'] . $subfolder ?? $settings['transcoderPaths']['default'];
256+
$destThumbnailPath = $settings['transcoderPaths']['thumbnail'] ?? $settings['transcoderPaths']['default'];
257+
$destThumbnailPath .= $subfolder;
255258
$destThumbnailPath = App::parseEnv($destThumbnailPath);
256259

257260
$thumbnailOptions = $this->coalesceOptions('defaultThumbnailOptions', $thumbnailOptions);
@@ -309,7 +312,8 @@ public function getVideoThumbnailUrl(Asset|string $filePath, array $thumbnailOpt
309312
if ($asPath) {
310313
$result = $destThumbnailPath;
311314
} else {
312-
$url = $settings['transcoderUrls']['thumbnail'] . $subfolder ?? $settings['transcoderUrls']['default'];
315+
$url = $settings['transcoderUrls']['thumbnail'] ?? $settings['transcoderUrls']['default'];
316+
$url .= $subfolder;
313317
$result = App::parseEnv($url) . $destThumbnailFile;
314318
}
315319
}
@@ -341,7 +345,8 @@ public function getAudioUrl(Asset|string $filePath, array $audioOptions): string
341345
$filePath = $this->getAssetPath($filePath);
342346

343347
if (!empty($filePath)) {
344-
$destAudioPath = $settings['transcoderPaths']['audio'] . $subfolder ?? $settings['transcoderPaths']['default'];
348+
$destAudioPath = $settings['transcoderPaths']['audio'] ?? $settings['transcoderPaths']['default'];
349+
$destAudioPath .= $subfolder;
345350
$destAudioPath = App::parseEnv($destAudioPath);
346351

347352
$audioOptions = $this->coalesceOptions('defaultAudioOptions', $audioOptions);
@@ -436,15 +441,17 @@ public function getAudioUrl(Asset|string $filePath, array $audioOptions): string
436441

437442
// If the audio file already exists and hasn't been modified, return it. Otherwise, start it transcoding
438443
if (file_exists($destAudioPath) && (@filemtime($destAudioPath) >= @filemtime($filePath))) {
439-
$url = $settings['transcoderUrls']['audio'] . $subfolder ?? $settings['transcoderUrls']['default'];
444+
$url = $settings['transcoderUrls']['audio'] ?? $settings['transcoderUrls']['default'];
445+
$url .= $subfolder;
440446
$result = App::parseEnv($url) . $destAudioFile;
441447
} else {
442448
// Kick off the transcoding
443449
$pid = $this->executeShellCommand($ffmpegCmd);
444450

445451
if ($synchronous) {
446452
Craft::info($ffmpegCmd, __METHOD__);
447-
$url = $settings['transcoderUrls']['audio'] . $subfolder ?? $settings['transcoderUrls']['default'];
453+
$url = $settings['transcoderUrls']['audio'] ?? $settings['transcoderUrls']['default'];
454+
$url .= $subfolder;
448455
$result = App::parseEnv($url) . $destAudioFile;
449456
} else {
450457
Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__);
@@ -646,7 +653,8 @@ public function getGifUrl(Asset|string $filePath, array $gifOptions): string|fal
646653

647654
if (!empty($filePath)) {
648655
// Dest path
649-
$destVideoPath = $settings['transcoderPaths']['gif'] . $subfolder ?? $settings['transcoderPaths']['default'];
656+
$destVideoPath = $settings['transcoderPaths']['gif'] ?? $settings['transcoderPaths']['default'];
657+
$destVideoPath .= $subfolder;
650658
$destVideoPath = App::parseEnv($destVideoPath);
651659

652660
// Options
@@ -702,7 +710,8 @@ public function getGifUrl(Asset|string $filePath, array $gifOptions): string|fal
702710

703711
// If the video file already exists and hasn't been modified, return it. Otherwise, start it transcoding
704712
if (file_exists($destVideoPath) && (@filemtime($destVideoPath) >= @filemtime($filePath))) {
705-
$url = $settings['transcoderUrls']['gif'] . $subfolder ?? $settings['transcoderUrls']['default'];
713+
$url = $settings['transcoderUrls']['gif'] ?? $settings['transcoderUrls']['default'];
714+
$url .= $subfolder;
706715
$result = App::parseEnv($url) . $destVideoFile;
707716
} else {
708717
// Kick off the transcoding

0 commit comments

Comments
 (0)