diff --git a/app/Services/ArchiveProcessingService.php b/app/Services/ArchiveProcessingService.php index 2ccbe9a5b..b44c7e2b7 100644 --- a/app/Services/ArchiveProcessingService.php +++ b/app/Services/ArchiveProcessingService.php @@ -6,9 +6,7 @@ use dariusiii\rarinfo\ArchiveInfo; class ArchiveProcessingService { - public function __construct(private readonly ArchiveInfo $archiveInfo) - { - } + public function __construct(private readonly ArchiveInfo $archiveInfo) {} /** * Analyze compressed data (RAR/ZIP/etc.). @@ -25,6 +23,7 @@ class ArchiveProcessingService } $summary = $this->archiveInfo->getSummary(true); $isEncrypted = ! empty($this->archiveInfo->isEncrypted) || (isset($summary['is_encrypted']) && (int) $summary['is_encrypted'] !== 0); + return ['ok' => true, 'error' => null, 'summary' => $summary, 'is_encrypted' => $isEncrypted]; } @@ -52,4 +51,3 @@ class ArchiveProcessingService return $this->archiveInfo->extractFile($name, $destPath); } } - diff --git a/app/Services/MediaProcessingService.php b/app/Services/MediaProcessingService.php index 40abc66d0..3030b2527 100644 --- a/app/Services/MediaProcessingService.php +++ b/app/Services/MediaProcessingService.php @@ -4,15 +4,11 @@ namespace App\Services; use App\Models\Category; use App\Models\Release; -use App\Services\TempWorkspaceService; use Blacklight\Categorize; use Blacklight\ElasticSearchSiteSearch; use Blacklight\ManticoreSearch; -use Blacklight\NameFixer; use Blacklight\ReleaseExtra; use Blacklight\ReleaseImage; -use Blacklight\Releases; -use Blacklight\utility\Utility; use FFMpeg\Coordinate\Dimension; use FFMpeg\Coordinate\TimeCode; use FFMpeg\FFMpeg; @@ -35,8 +31,7 @@ class MediaProcessingService private readonly ManticoreSearch $manticore, private readonly ElasticSearchSiteSearch $elasticsearch, private readonly Categorize $categorize, - ) { - } + ) {} public function getVideoTime(string $videoLocation): string { @@ -66,6 +61,7 @@ class MediaProcessingService $numbers[2]--; $numbers[3] = '99'; } + return '00:00:'.str_pad((string) $numbers[2], 2, '0', STR_PAD_LEFT).'.'.str_pad((string) $numbers[3], 2, '0', STR_PAD_LEFT); } @@ -81,6 +77,7 @@ class MediaProcessingService $hund = 99; } } + return '00:00:'.str_pad((string) $sec, 2, '0', STR_PAD_LEFT).'.'.str_pad((string) $hund, 2, '0', STR_PAD_LEFT); } @@ -94,6 +91,7 @@ class MediaProcessingService $whole = (int) floor($seconds); $hund = (int) round(($seconds - $whole) * 100); $hund = min($hund, 99); + return '00:00:'.str_pad((string) $whole, 2, '0', STR_PAD_LEFT).'.'.str_pad((string) $hund, 2, '0', STR_PAD_LEFT); } @@ -112,6 +110,7 @@ class MediaProcessingService if ($saved) { Release::query()->where('guid', $guid)->update(['jpgstatus' => 1]); } + return $saved; } @@ -150,6 +149,7 @@ class MediaProcessingService if ($saved === 1) { return true; } + return false; } @@ -221,6 +221,7 @@ class MediaProcessingService } @chmod($newFile, 0764); Release::query()->where('guid', $guid)->update(['videostatus' => 1]); + return true; } @@ -233,9 +234,11 @@ class MediaProcessingService $xmlArray = $this->mediaInfo->getInfo($fileLocation, true); \App\Models\MediaInfo::addData($releaseId, $xmlArray); $this->releaseExtra->addFromXml($releaseId, $xmlArray); + return true; } catch (\Throwable $e) { Log::debug($e->getMessage()); + return false; } } @@ -324,4 +327,3 @@ class MediaProcessingService return ['info' => $retVal, 'sample' => $audVal]; } } - diff --git a/app/Services/TempWorkspaceService.php b/app/Services/TempWorkspaceService.php index 07991aaad..90b0a28f5 100644 --- a/app/Services/TempWorkspaceService.php +++ b/app/Services/TempWorkspaceService.php @@ -14,7 +14,7 @@ class TempWorkspaceService public function ensureMainTempPath(string $basePath, string $guidChar = '', string $groupID = ''): string { // Normalize separator at end - if (! Str::endsWith($basePath, ['/','\\'])) { + if (! Str::endsWith($basePath, ['/', '\\'])) { $basePath .= '/'; } @@ -47,6 +47,7 @@ class TempWorkspaceService } } } + return $tmpPath; } @@ -103,6 +104,7 @@ class TempWorkspaceService $filtered[] = $matches; } } + return $filtered; } diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 02c837534..db52b29a5 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -20,4 +20,3 @@ trait CreatesApplication return $app; } } - diff --git a/tests/Unit/ArchiveProcessingServiceTest.php b/tests/Unit/ArchiveProcessingServiceTest.php index d3647405c..2d1df0622 100644 --- a/tests/Unit/ArchiveProcessingServiceTest.php +++ b/tests/Unit/ArchiveProcessingServiceTest.php @@ -10,14 +10,14 @@ use PHPUnit\Framework\TestCase; class ArchiveProcessingServiceTest extends TestCase { - public function tearDown(): void + protected function tearDown(): void { Mockery::close(); parent::tearDown(); } #[WithoutErrorHandler] - public function testAnalyzeOkNotEncrypted(): void + public function test_analyze_ok_not_encrypted(): void { $ai = Mockery::mock(ArchiveInfo::class); $ai->shouldReceive('setData')->once()->andReturn(true); @@ -33,7 +33,7 @@ class ArchiveProcessingServiceTest extends TestCase } #[WithoutErrorHandler] - public function testAnalyzeEncryptedViaSummaryFlag(): void + public function test_analyze_encrypted_via_summary_flag(): void { $ai = Mockery::mock(ArchiveInfo::class); $ai->shouldReceive('setData')->once()->andReturn(true); @@ -48,7 +48,7 @@ class ArchiveProcessingServiceTest extends TestCase } #[WithoutErrorHandler] - public function testAnalyzeErrorWhenSetDataFails(): void + public function test_analyze_error_when_set_data_fails(): void { $ai = Mockery::mock(ArchiveInfo::class); $ai->shouldReceive('setData')->once()->andReturn(false); @@ -62,7 +62,7 @@ class ArchiveProcessingServiceTest extends TestCase } #[WithoutErrorHandler] - public function testGettersProxyToArchiveInfo(): void + public function test_getters_proxy_to_archive_info(): void { $ai = Mockery::mock(ArchiveInfo::class); $ai->shouldReceive('getArchiveFileList')->once()->andReturn([['name' => 'file.txt']]); diff --git a/tests/Unit/MediaProcessingServiceTest.php b/tests/Unit/MediaProcessingServiceTest.php index 8c69c3fad..061be61dd 100644 --- a/tests/Unit/MediaProcessingServiceTest.php +++ b/tests/Unit/MediaProcessingServiceTest.php @@ -28,8 +28,8 @@ class MediaProcessingServiceTest extends TestCase { parent::setUp(); // Minimal Facade container for File facade - $container = new Container(); - $container->instance('files', new Filesystem()); + $container = new Container; + $container->instance('files', new Filesystem); Facade::setFacadeApplication($container); $this->tmpDir = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'mps_'.uniqid().DIRECTORY_SEPARATOR; @@ -63,16 +63,19 @@ class MediaProcessingServiceTest extends TestCase $manticore ??= Mockery::mock(ManticoreSearch::class); $elastic ??= Mockery::mock(ElasticSearchSiteSearch::class); $categorize ??= Mockery::mock(Categorize::class); + return new MediaProcessingService($ffmpeg, $ffprobe, $mediaInfo, $releaseImage, $releaseExtra, $manticore, $elastic, $categorize); } #[WithoutErrorHandler] - public function testGetVideoTimeParsesDurationString(): void + public function test_get_video_time_parses_duration_string(): void { $ffprobe = Mockery::mock(FFProbe::class); $ffprobe->shouldReceive('isValid')->once()->andReturn(true); - $format = new class { - public function get($key) { + $format = new class + { + public function get($key) + { return 'time=00:05.10 bitrate=800k'; } }; @@ -83,24 +86,37 @@ class MediaProcessingServiceTest extends TestCase } #[WithoutErrorHandler] - public function testCreateSampleImageReturnsTrueWhenSaved(): void + public function test_create_sample_image_returns_true_when_saved(): void { $videoFile = $this->tmpDir.'video.avi'; File::put($videoFile, 'fake'); $ffprobe = Mockery::mock(FFProbe::class); $ffprobe->shouldReceive('isValid')->andReturn(true); - $format = new class { - public function get($key) { return 'time=00:03.10 bitrate=800k'; } + $format = new class + { + public function get($key) + { + return 'time=00:03.10 bitrate=800k'; + } }; $ffprobe->shouldReceive('format')->andReturn($format); - $frameMock = new class { - public function save($path) { \file_put_contents($path, 'x'); } + $frameMock = new class + { + public function save($path) + { + \file_put_contents($path, 'x'); + } }; - $openMock = new class($frameMock) { + $openMock = new class($frameMock) + { public function __construct(private $frame) {} - public function frame($tc) { return $this->frame; } + + public function frame($tc) + { + return $this->frame; + } }; $ffmpeg = Mockery::mock(FFMpeg::class); $ffmpeg->shouldReceive('open')->andReturn($openMock); @@ -115,17 +131,17 @@ class MediaProcessingServiceTest extends TestCase } #[WithoutErrorHandler] - public function testAddVideoMediaInfoFalseIfFileMissing(): void + public function test_add_video_media_info_false_if_file_missing(): void { $svc = $this->makeService(); $this->assertFalse($svc->addVideoMediaInfo(1, $this->tmpDir.'nope.avi')); } #[WithoutErrorHandler] - public function testAddAudioInfoAndSampleReturnsTrueWhenDisabled(): void + public function test_add_audio_info_and_sample_returns_true_when_disabled(): void { $svc = $this->makeService(); - $release = new ReleaseModel(); + $release = new ReleaseModel; $release->id = 1; $release->guid = 'g'; $release->predb_id = 0; diff --git a/tests/Unit/TempWorkspaceServiceTest.php b/tests/Unit/TempWorkspaceServiceTest.php index 2862aede7..023f8994f 100644 --- a/tests/Unit/TempWorkspaceServiceTest.php +++ b/tests/Unit/TempWorkspaceServiceTest.php @@ -13,17 +13,18 @@ use PHPUnit\Framework\TestCase; class TempWorkspaceServiceTest extends TestCase { private string $base; + private TempWorkspaceService $svc; protected function setUp(): void { parent::setUp(); // Minimal Facade container for File facade - $container = new Container(); - $container->instance('files', new Filesystem()); + $container = new Container; + $container->instance('files', new Filesystem); Facade::setFacadeApplication($container); - $this->svc = new TempWorkspaceService(); + $this->svc = new TempWorkspaceService; // Unique base path under system temp $this->base = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'twsvc_'.uniqid(); File::makeDirectory($this->base, 0777, true, true); @@ -39,7 +40,7 @@ class TempWorkspaceServiceTest extends TestCase } #[WithoutErrorHandler] - public function testEnsureMainTempPathCreatesAndNamespacesByGuidChar(): void + public function test_ensure_main_temp_path_creates_and_namespaces_by_guid_char(): void { $resolved = $this->svc->ensureMainTempPath($this->base, 'z', ''); $this->assertStringEndsWith('/z/', str_replace('\\', '/', $resolved)); @@ -47,7 +48,7 @@ class TempWorkspaceServiceTest extends TestCase } #[WithoutErrorHandler] - public function testCreateReleaseTempFolderCreatesPerReleaseDir(): void + public function test_create_release_temp_folder_creates_per_release_dir(): void { $main = $this->svc->ensureMainTempPath($this->base, '', 'group42'); $tmp = $this->svc->createReleaseTempFolder($main, 'guid-123'); @@ -56,7 +57,7 @@ class TempWorkspaceServiceTest extends TestCase } #[WithoutErrorHandler] - public function testListFilesWithAndWithoutPattern(): void + public function test_list_files_with_and_without_pattern(): void { $main = $this->svc->ensureMainTempPath($this->base, '', 'grp'); $release = $this->svc->createReleaseTempFolder($main, 'g1'); @@ -68,7 +69,7 @@ class TempWorkspaceServiceTest extends TestCase $all = $this->svc->listFiles($release); $this->assertNotEmpty($all); - $this->assertTrue(collect($all)->every(fn($f) => method_exists($f, 'getPathname'))); + $this->assertTrue(collect($all)->every(fn ($f) => method_exists($f, 'getPathname'))); $matches = $this->svc->listFiles($release, '/.*\.txt$/i'); $this->assertNotEmpty($matches); @@ -81,7 +82,7 @@ class TempWorkspaceServiceTest extends TestCase } #[WithoutErrorHandler] - public function testClearDirectoryPreserveRoot(): void + public function test_clear_directory_preserve_root(): void { $main = $this->svc->ensureMainTempPath($this->base, '', 'grp2'); File::put($main.'x.bin', 'data'); @@ -96,7 +97,7 @@ class TempWorkspaceServiceTest extends TestCase } #[WithoutErrorHandler] - public function testClearDirectoryDeleteRoot(): void + public function test_clear_directory_delete_root(): void { $main = $this->svc->ensureMainTempPath($this->base, '', 'grp3'); File::put($main.'x.bin', 'data');