Skip to content

Commit 0feb2c8

Browse files
committed
clean up doc blocks and minor code smell
1 parent 3b5207a commit 0feb2c8

File tree

6 files changed

+111
-95
lines changed

6 files changed

+111
-95
lines changed

src/FileInfo.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ protected function cleanPath($path)
288288
* the prefix will be stripped. It is recommended to give prefixes with a trailing slash.
289289
*
290290
* @param int|string $strip
291-
* @return FileInfo
292291
*/
293292
public function strip($strip)
294293
{

src/Tar.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO)
4848
*
4949
* @param string $file
5050
* @throws ArchiveIOException
51+
* @throws ArchiveIllegalCompressionException
5152
*/
5253
public function open($file)
5354
{
@@ -82,6 +83,7 @@ public function open($file)
8283
* Reopen the file with open() again if you want to do additional operations
8384
*
8485
* @throws ArchiveIOException
86+
* @throws ArchiveCorruptedException
8587
* @returns FileInfo[]
8688
*/
8789
public function contents()
@@ -123,11 +125,12 @@ public function contents()
123125
* The archive is closed afer reading the contents, because rewinding is not possible in bzip2 streams.
124126
* Reopen the file with open() again if you want to do additional operations
125127
*
126-
* @param string $outdir the target directory for extracting
127-
* @param int|string $strip either the number of path components or a fixed prefix to strip
128-
* @param string $exclude a regular expression of files to exclude
129-
* @param string $include a regular expression of files to include
128+
* @param string $outdir the target directory for extracting
129+
* @param int|string $strip either the number of path components or a fixed prefix to strip
130+
* @param string $exclude a regular expression of files to exclude
131+
* @param string $include a regular expression of files to include
130132
* @throws ArchiveIOException
133+
* @throws ArchiveCorruptedException
131134
* @return FileInfo[]
132135
*/
133136
public function extract($outdir, $strip = '', $exclude = '', $include = '')
@@ -204,6 +207,7 @@ public function extract($outdir, $strip = '', $exclude = '', $include = '')
204207
*
205208
* @param string $file
206209
* @throws ArchiveIOException
210+
* @throws ArchiveIllegalCompressionException
207211
*/
208212
public function create($file = '')
209213
{
@@ -240,6 +244,7 @@ public function create($file = '')
240244
* @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original
241245
* @throws ArchiveCorruptedException when the file changes while reading it, the archive will be corrupt and should be deleted
242246
* @throws ArchiveIOException there was trouble reading the given file, it was not added
247+
* @throws FileInfoException trouble reading file info, it was not added
243248
*/
244249
public function addFile($file, $fileinfo = '')
245250
{
@@ -325,6 +330,7 @@ public function addData($fileinfo, $data)
325330
* consists of two 512 blocks of zero bytes"
326331
*
327332
* @link http://www.gnu.org/software/tar/manual/html_chapter/tar_8.html#SEC134
333+
* @throws ArchiveIOException
328334
*/
329335
public function close()
330336
{
@@ -360,6 +366,7 @@ public function close()
360366
* Returns the created in-memory archive data
361367
*
362368
* This implicitly calls close() on the Archive
369+
* @throws ArchiveIOException
363370
*/
364371
public function getArchive()
365372
{
@@ -386,6 +393,7 @@ public function getArchive()
386393
*
387394
* @param string $file
388395
* @throws ArchiveIOException
396+
* @throws ArchiveIllegalCompressionException
389397
*/
390398
public function save($file)
391399
{
@@ -465,9 +473,10 @@ protected function skipbytes($bytes)
465473
}
466474

467475
/**
468-
* Write the given file metat data as header
476+
* Write the given file meta data as header
469477
*
470478
* @param FileInfo $fileinfo
479+
* @throws ArchiveIOException
471480
*/
472481
protected function writeFileHeader(FileInfo $fileinfo)
473482
{
@@ -486,12 +495,13 @@ protected function writeFileHeader(FileInfo $fileinfo)
486495
* Write a file header to the stream
487496
*
488497
* @param string $name
489-
* @param int $uid
490-
* @param int $gid
491-
* @param int $perm
492-
* @param int $size
493-
* @param int $mtime
498+
* @param int $uid
499+
* @param int $gid
500+
* @param int $perm
501+
* @param int $size
502+
* @param int $mtime
494503
* @param string $typeflag Set to '5' for directories
504+
* @throws ArchiveIOException
495505
*/
496506
protected function writeRawFileHeader($name, $uid, $gid, $perm, $size, $mtime, $typeflag = '')
497507
{
@@ -678,4 +688,5 @@ public function filetype($file)
678688

679689
return Archive::COMPRESS_NONE;
680690
}
691+
681692
}

src/Zip.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,10 @@ public function create($file = '')
280280
/**
281281
* Add a file to the current archive using an existing file in the filesystem
282282
*
283-
* @param string $file path to the original file
283+
* @param string $file path to the original file
284284
* @param string|FileInfo $fileinfo either the name to use in archive (string) or a FileInfo oject with all meta data, empty to take from original
285285
* @throws ArchiveIOException
286+
* @throws FileInfoException
286287
*/
287288
public function addFile($file, $fileinfo = '')
288289
{
@@ -370,6 +371,7 @@ public function addData($fileinfo, $data)
370371
*
371372
* After a call to this function no more data can be added to the archive, for
372373
* read access no reading is allowed anymore
374+
* @throws ArchiveIOException
373375
*/
374376
public function close()
375377
{
@@ -413,6 +415,7 @@ public function close()
413415
* Returns the created in-memory archive data
414416
*
415417
* This implicitly calls close() on the Archive
418+
* @throws ArchiveIOException
416419
*/
417420
public function getArchive()
418421
{

tests/FileInfoTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<?php
1+
<?php /** @noinspection PhpUnhandledExceptionInspection */
22

33
namespace splitbrain\PHPArchive;
44

5-
use splitbrain\PHPArchive\FileInfo;
65
use PHPUnit\Framework\TestCase;
76

87
class FileInfoTest extends TestCase
@@ -101,10 +100,10 @@ public function testFromPath()
101100
}
102101

103102
/**
104-
* @expectedException splitbrain\PHPArchive\FileInfoException
103+
* @expectedException \splitbrain\PHPArchive\FileInfoException
105104
*/
106105
public function testFromPathWithFileNotExisted()
107106
{
108-
$fileinfo = FileInfo::fromPath('invalid_file_path');
107+
FileInfo::fromPath('invalid_file_path');
109108
}
110109
}

tests/TarTestCase.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testExtBz2IsInstalled()
6363
}
6464

6565
/**
66-
* @expectedException splitbrain\PHPArchive\ArchiveIOException
66+
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
6767
*/
6868
public function testTarFileIsNotExisted()
6969
{
@@ -162,6 +162,7 @@ public function testTarcontent()
162162
$file = "$dir/test.$ext";
163163

164164
$tar->open($file);
165+
/** @var FileInfo[] $content */
165166
$content = $tar->contents();
166167

167168
$this->assertCount(4, $content, "Contents of $file");
@@ -595,7 +596,8 @@ public function testGzipIsValid()
595596
try {
596597
$phar = new \PharData($archive);
597598
$phar->extractTo($extract);
598-
} catch (\Exception $e) {};
599+
} catch(\Exception $e) {
600+
};
599601

600602
$this->assertFileExists("$extract/Tar.php");
601603
$this->assertFileExists("$extract/Zip.php");
@@ -608,7 +610,7 @@ public function testGzipIsValid()
608610
}
609611

610612
/**
611-
* @expectedException splitbrain\PHPArchive\ArchiveIOException
613+
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
612614
*/
613615
public function testContentsWithInvalidArchiveStream()
614616
{
@@ -617,7 +619,7 @@ public function testContentsWithInvalidArchiveStream()
617619
}
618620

619621
/**
620-
* @expectedException splitbrain\PHPArchive\ArchiveIOException
622+
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
621623
*/
622624
public function testExtractWithInvalidOutDir()
623625
{
@@ -631,7 +633,7 @@ public function testExtractWithInvalidOutDir()
631633
}
632634

633635
/**
634-
* @expectedException splitbrain\PHPArchive\ArchiveIOException
636+
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
635637
*/
636638
public function testExtractWithArchiveStreamIsClosed()
637639
{
@@ -646,7 +648,7 @@ public function testExtractWithArchiveStreamIsClosed()
646648
}
647649

648650
/**
649-
* @expectedException splitbrain\PHPArchive\ArchiveIOException
651+
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
650652
*/
651653
public function testCreateWithInvalidFile()
652654
{
@@ -658,7 +660,7 @@ public function testCreateWithInvalidFile()
658660
}
659661

660662
/**
661-
* @expectedException splitbrain\PHPArchive\ArchiveIOException
663+
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
662664
*/
663665
public function testAddFileWithArchiveStreamIsClosed()
664666
{
@@ -671,7 +673,7 @@ public function testAddFileWithArchiveStreamIsClosed()
671673
}
672674

673675
/**
674-
* @expectedException splitbrain\PHPArchive\ArchiveIOException
676+
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
675677
*/
676678
public function testAddFileWithInvalidFile()
677679
{
@@ -683,7 +685,7 @@ public function testAddFileWithInvalidFile()
683685
}
684686

685687
/**
686-
* @expectedException splitbrain\PHPArchive\ArchiveIOException
688+
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
687689
*/
688690
public function testAddDataWithArchiveStreamIsClosed()
689691
{
@@ -703,7 +705,8 @@ public function testCloseHasBeenClosed()
703705
$tar->create($archive);
704706
$tar->close();
705707

706-
$this->assertNull($tar->close());
708+
$tar->close();
709+
$this->assertTrue(true); // succeed if no exception, yet
707710
}
708711

709712
/**
@@ -729,11 +732,12 @@ public function testSaveWithCompressionAuto()
729732
$tar->create();
730733
$tar->addFile("$dir/zero.txt", 'zero.txt');
731734

732-
$this->assertNull($tar->save(vfsStream::url('home_root_path/archive_file')));
735+
$tar->save(vfsStream::url('home_root_path/archive_file'));
736+
$this->assertTrue(true); // succeed if no exception, yet
733737
}
734738

735-
/**
736-
* @expectedException splitbrain\PHPArchive\ArchiveIOException
739+
/**
740+
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
737741
*/
738742
public function testSaveWithInvalidDestinationFile()
739743
{
@@ -743,7 +747,8 @@ public function testSaveWithInvalidDestinationFile()
743747
$tar->create();
744748
$tar->addFile("$dir/zero.txt", 'zero.txt');
745749

746-
$this->assertNull($tar->save(vfsStream::url('archive_file')));
750+
$tar->save(vfsStream::url('archive_file'));
751+
$this->assertTrue(true); // succeed if no exception, yet
747752
}
748753

749754
/**

0 commit comments

Comments
 (0)