| Conditions | 3 |
| Paths | 2 |
| Total Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 41 | public function testPackExtract($archiveType) |
||
| 42 | { |
||
| 43 | if ((version_compare(PHP_VERSION, '7.4.0') >= 0) && (getenv('TRAVIS'))) { |
||
| 44 | $this->markTestSkipped('Zip libraries apparently not available on Travis CI with PHP 7.4 image.'); |
||
| 45 | } |
||
| 46 | |||
| 47 | // Archive directory and then extract it again with Archive and Extract tasks |
||
| 48 | $this->fixtures->createAndCdToSandbox(); |
||
| 49 | |||
| 50 | // Assert fixture was created correctly |
||
| 51 | $this->assertDirectoryExists('some/deeply/nested'); |
||
| 52 | $this->assertFileExists('some/deeply/nested/structu.re'); |
||
| 53 | $this->assertFileExists('some/deeply/existing_file'); |
||
| 54 | |||
| 55 | // First, take everything from the folder 'some/deeply' and make |
||
| 56 | // an archive for it located in 'deep' |
||
| 57 | $result = $this->taskPack("deeply.$archiveType") |
||
|
|
|||
| 58 | ->add(['deep' => 'some/deeply']) |
||
| 59 | ->run(); |
||
| 60 | $this->assertTrue($result->wasSuccessful()); |
||
| 61 | $this->assertFileExists("deeply.$archiveType"); |
||
| 62 | // We are next going to extract the archive we created, this time |
||
| 63 | // putting it into a folder called "extracted-$archiveType" (different |
||
| 64 | // for each archive type we test). We rely on the default behavior |
||
| 65 | // of our extractor to remove the top-level directory in the archive |
||
| 66 | // ("deeply"). |
||
| 67 | $result = $this->taskExtract("deeply.$archiveType") |
||
| 68 | ->to("extracted-$archiveType") |
||
| 69 | ->preserveTopDirectory(false) // this is the default |
||
| 70 | ->run(); |
||
| 71 | $this->assertTrue($result->wasSuccessful()); |
||
| 72 | $this->assertDirectoryExists("extracted-$archiveType"); |
||
| 73 | $this->assertDirectoryExists("extracted-$archiveType/nested"); |
||
| 74 | $this->assertFileExists("extracted-$archiveType/nested/structu.re"); |
||
| 75 | // Next, we'll extract the same archive again, this time preserving |
||
| 76 | // the top-level folder. |
||
| 77 | $this->taskExtract("deeply.$archiveType") |
||
| 78 | ->to("preserved-$archiveType") |
||
| 79 | ->preserveTopDirectory() |
||
| 80 | ->run(); |
||
| 81 | $this->assertDirectoryExists("preserved-$archiveType"); |
||
| 82 | $this->assertDirectoryExists("preserved-$archiveType/deep/nested"); |
||
| 83 | $this->assertFileExists("preserved-$archiveType/deep/nested/structu.re"); |
||
| 84 | // Make another archive, this time composed of fanciful locations |
||
| 85 | $result = $this->taskPack("composed.$archiveType") |
||
| 86 | ->add(['a/b/existing_file' => 'some/deeply/existing_file']) |
||
| 87 | ->add(['x/y/z/structu.re' => 'some/deeply/nested/structu.re']) |
||
| 88 | ->run(); |
||
| 89 | $this->assertTrue($result->wasSuccessful()); |
||
| 90 | $this->assertFileExists("composed.$archiveType"); |
||
| 91 | // Extract our composed archive, and see if the resulting file |
||
| 92 | // structure matches expectations. |
||
| 93 | $result = $this->taskExtract("composed.$archiveType") |
||
| 94 | ->to("decomposed-$archiveType") |
||
| 95 | ->preserveTopDirectory() |
||
| 96 | ->run(); |
||
| 97 | $this->assertTrue($result->wasSuccessful()); |
||
| 98 | $this->assertDirectoryExists("decomposed-$archiveType"); |
||
| 99 | $this->assertDirectoryExists("decomposed-$archiveType/x/y/z"); |
||
| 100 | $this->assertFileExists("decomposed-$archiveType/x/y/z/structu.re"); |
||
| 101 | $this->assertDirectoryExists("decomposed-$archiveType/a/b"); |
||
| 102 | $this->assertFileExists("decomposed-$archiveType/a/b/existing_file"); |
||
| 103 | |||
| 104 | } |
||
| 105 | } |
||
| 106 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: