From 2cea7cde1adcabe03f3c9463a9fda23dd0908b55 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 03:18:12 +0000 Subject: [PATCH] =?UTF-8?q?Refatora=C3=A7=C3=A3o:=20remove=20m=C3=A9todo?= =?UTF-8?q?=20redundante=20`testWithDetails`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O método `testWithDetails()` foi removido da classe `SevenZip` pois era funcionalmente idêntico ao método `verify()`, que é a forma correta e recomendada de validar a integridade de um arquivo (`7z t`). Com a remoção, evitamos duplicação de lógica e confusão na API. Foi feita também a atualização da documentação no `README.md` incluindo o método `verify()` na listagem da API (em ordem alfabética) e a marcação do item correspondente aos testes na lista de TODO. Co-authored-by: insign <1113045+insign@users.noreply.github.com> --- README.md | 18 +++++++++++++++++- src/SevenZip.php | 30 +----------------------------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index c435f2d..59c31b6 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ if ($sevenZip->checkSupport(['zip', 'tar', '7z'])) { - [x] Auto untar on extraction - [x] Filter files by patterns - [x] Encrypt and decrypt -- [ ] Test files using 7z test command +- [x] Test files using 7z test command - [x] Detect supported formats by the OS - [x] Add built-in binaries for mac and linux - [x] ~~Use docker for PHPUnit tests~~ not needed with built-in binaries @@ -883,6 +883,22 @@ Configures maximum compression settings based on the specified format. **Returns**: The current instance for method chaining. +### `verify(): string` + +Tests the integrity of an archive. + +**Returns**: The output of the 7-Zip command. + +**Throws** + +- `InvalidArgumentException`: If the archive path (source) is not set. + +**Example** + +```php +$sevenZip->source('/path/to/archive.7z')->verify(); +``` + ## License This package is open-sourced software licensed under the [MIT license](./LICENSE.md). diff --git a/src/SevenZip.php b/src/SevenZip.php index 0a734f0..44b0bd2 100644 --- a/src/SevenZip.php +++ b/src/SevenZip.php @@ -1157,41 +1157,13 @@ public function rename(array $renames): string public function test(): bool { try { - $this->testWithDetails(); + $this->verify(); return true; } catch (\RuntimeException $e) { return false; } } - /** - * Test the integrity of an archive with detailed output. - * - * @return string The output of the test command. - * @throws \InvalidArgumentException If the source path is not set. - * @throws \RuntimeException If the archive is corrupted or invalid. - */ - public function testWithDetails(): string - { - if (!$this->getSourcePath()) { - throw new \InvalidArgumentException('Archive path (source) must be set'); - } - - if ($this->getPassword()) { - $this->addFlag('p', $this->getPassword(), glued: true); - } - - $command = [ - $this->getSevenZipPath(), - 't', - ...$this->flagrize($this->getAlwaysFlags()), - ...$this->flagrize($this->getCustomFlags()), - $this->getSourcePath(), - ]; - - return $this->runCommand($command); - } - /** * Format flags and values into an array of strings suitable for passing to 7-Zip commands. *