LocalFileHeaderTest::testImmutability()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 75
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 63
nc 1
nop 0
dl 0
loc 75
rs 9
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace morgue\zip;
4
5
use PHPUnit\Framework\TestCase;
6
7
final class LocalFileHeaderTest extends TestCase
8
{
9
    public function testImmutability()
10
    {
11
        $old = new LocalFileHeader(0,0,0,0,0,0,0,0);
12
        $number = 12345;
13
14
        $new = $old->setVersionNeededToExtract($number);
15
        $this->assertNotSame($old, $new);
16
        $this->assertNotSame($old->getVersionNeededToExtract(), $new->getVersionNeededToExtract());
17
        $this->assertSame($number, $new->getVersionNeededToExtract());
18
        $old = $new;
19
        $number += 123;
20
21
        $new = $old->setGeneralPurposeBitFlags($number);
22
        $this->assertNotSame($old, $new);
23
        $this->assertNotSame($old->getGeneralPurposeBitFlags(), $new->getGeneralPurposeBitFlags());
24
        $this->assertSame($number, $new->getGeneralPurposeBitFlags());
25
        $old = $new;
26
        $number += 123;
27
28
        $new = $old->setCompressionMethod($number);
29
        $this->assertNotSame($old, $new);
30
        $this->assertNotSame($old->getCompressionMethod(), $new->getCompressionMethod());
31
        $this->assertSame($number, $new->getCompressionMethod());
32
        $old = $new;
33
        $number += 123;
34
35
        $new = $old->setLastModificationFileDate($number);
36
        $this->assertNotSame($old, $new);
37
        $this->assertNotSame($old->getLastModificationFileDate(), $new->getLastModificationFileDate());
38
        $this->assertSame($number, $new->getLastModificationFileDate());
39
        $old = $new;
40
        $number += 123;
41
42
        $new = $old->setLastModificationFileTime($number);
43
        $this->assertNotSame($old, $new);
44
        $this->assertNotSame($old->getLastModificationFileTime(), $new->getLastModificationFileTime());
45
        $this->assertSame($number, $new->getLastModificationFileTime());
46
        $old = $new;
47
        $number += 123;
48
49
        $new = $old->setCrc32($number);
50
        $this->assertNotSame($old, $new);
51
        $this->assertNotSame($old->getCrc32(), $new->getCrc32());
52
        $this->assertSame($number, $new->getCrc32());
53
        $old = $new;
54
        $number += 123;
55
56
        $new = $old->setCompressedSize($number);
57
        $this->assertNotSame($old, $new);
58
        $this->assertNotSame($old->getCompressedSize(), $new->getCompressedSize());
59
        $this->assertSame($number, $new->getCompressedSize());
60
        $old = $new;
61
        $number += 123;
62
63
        $new = $old->setUncompressedSize($number);
64
        $this->assertNotSame($old, $new);
65
        $this->assertNotSame($old->getUncompressedSize(), $new->getUncompressedSize());
66
        $this->assertSame($number, $new->getUncompressedSize());
67
        $old = $new;
68
69
        $fileName = "new name";
70
        $new = $old->setFileName($fileName);
71
        $this->assertNotSame($old, $new);
72
        $this->assertNotSame($old->getFileName(), $new->getFileName());
73
        $this->assertSame($fileName, $new->getFileName());
74
        $this->assertSame(\strlen($fileName), $new->getFileNameLength());
75
        $old = $new;
76
77
        $extraField = "abcdefghij";
78
        $new = $old->setExtraField($extraField);
79
        $this->assertNotSame($old, $new);
80
        $this->assertNotSame($old->getExtraField(), $new->getextraField());
81
        $this->assertSame($extraField, $new->getExtraField());
82
        $this->assertSame(\strlen($extraField), $new->getExtraFieldLength());
83
    }
84
}
85