Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
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 | // Archive directory and then extract it again with Archive and Extract tasks |
||
44 | $this->fixtures->createAndCdToSandbox(); |
||
45 | |||
46 | // Assert fixture was created correctly |
||
47 | $this->assertDirectoryExists('some/deeply/nested'); |
||
48 | $this->assertFileExists('some/deeply/nested/structu.re'); |
||
49 | $this->assertFileExists('some/deeply/existing_file'); |
||
50 | |||
51 | // First, take everything from the folder 'some/deeply' and make |
||
52 | // an archive for it located in 'deep' |
||
53 | $this->taskPack("deeply.$archiveType") |
||
|
|||
54 | ->add(['deep' => 'some/deeply']) |
||
55 | ->run(); |
||
56 | $this->assertFileExists("deeply.$archiveType"); |
||
57 | // We are next going to extract the archive we created, this time |
||
58 | // putting it into a folder called "extracted-$archiveType" (different |
||
59 | // for each archive type we test). We rely on the default behavior |
||
60 | // of our extractor to remove the top-level directory in the archive |
||
61 | // ("deeply"). |
||
62 | $this->taskExtract("deeply.$archiveType") |
||
63 | ->to("extracted-$archiveType") |
||
64 | ->preserveTopDirectory(false) // this is the default |
||
65 | ->run(); |
||
66 | $this->assertDirectoryExists("extracted-$archiveType"); |
||
67 | $this->assertDirectoryExists("extracted-$archiveType/nested"); |
||
68 | $this->assertFileExists("extracted-$archiveType/nested/structu.re"); |
||
69 | // Next, we'll extract the same archive again, this time preserving |
||
70 | // the top-level folder. |
||
71 | $this->taskExtract("deeply.$archiveType") |
||
72 | ->to("preserved-$archiveType") |
||
73 | ->preserveTopDirectory() |
||
74 | ->run(); |
||
75 | $this->assertDirectoryExists("preserved-$archiveType"); |
||
76 | $this->assertDirectoryExists("preserved-$archiveType/deep/nested"); |
||
77 | $this->assertFileExists("preserved-$archiveType/deep/nested/structu.re"); |
||
78 | // Make another archive, this time composed of fanciful locations |
||
79 | $this->taskPack("composed.$archiveType") |
||
80 | ->add(['a/b/existing_file' => 'some/deeply/existing_file']) |
||
81 | ->add(['x/y/z/structu.re' => 'some/deeply/nested/structu.re']) |
||
82 | ->run(); |
||
83 | $this->assertFileExists("composed.$archiveType"); |
||
84 | // Extract our composed archive, and see if the resulting file |
||
85 | // structure matches expectations. |
||
86 | $this->taskExtract("composed.$archiveType") |
||
87 | ->to("decomposed-$archiveType") |
||
88 | ->preserveTopDirectory() |
||
89 | ->run(); |
||
90 | $this->assertDirectoryExists("decomposed-$archiveType"); |
||
91 | $this->assertDirectoryExists("decomposed-$archiveType/x/y/z"); |
||
92 | $this->assertFileExists("decomposed-$archiveType/x/y/z/structu.re"); |
||
93 | $this->assertDirectoryExists("decomposed-$archiveType/a/b"); |
||
94 | $this->assertFileExists("decomposed-$archiveType/a/b/existing_file"); |
||
95 | |||
96 | } |
||
97 | } |
||
98 |
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: