FileValidatorTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 77.78 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 42
loc 54
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMockFileUpload() 0 7 1
A testValid() 21 21 1
A testUnsupportedFileType() 21 21 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of the IrishDan\ResponsiveImageBundle package.
4
 *
5
 * (c) Daniel Byrne <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source
8
 * code.
9
 */
10
11
namespace IrishDan\ResponsiveImageBundle\Tests\File;
12
13
use IrishDan\ResponsiveImageBundle\File\FileValidator;
14
use Symfony\Component\HttpFoundation\File\UploadedFile;
15
16
class FileValidatorTest extends \PHPUnit_Framework_TestCase
17
{
18
    protected function getMockFileUpload()
19
    {
20
        // Mock the repository so it returns the mock of the Image repository.
21
        return $this->getMockBuilder(UploadedFile::class)
22
                    ->disableOriginalConstructor()
23
                    ->getMock();
24
    }
25
26 View Code Duplication
    public function testValid()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        $uploadedFile = $this->getMockFileUpload();
29
        $uploadedFile->expects($this->once())
30
                     ->method('getClientOriginalExtension')
31
                     ->will(
32
                         $this->returnValue('jpg')
33
                     );
34
        $uploadedFile->expects($this->once())
35
                     ->method('guessExtension')
36
                     ->will(
37
                         $this->returnValue('jpg')
38
                     );
39
40
        // Test the validator.
41
        $validator = new FileValidator();
42
43
        $valid = $validator->validate($uploadedFile);
44
45
        $this->assertTrue($valid);
46
    }
47
48 View Code Duplication
    public function testUnsupportedFileType()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        $uploadedFile = $this->getMockFileUpload();
51
        $uploadedFile->expects($this->once())
52
                     ->method('getClientOriginalExtension')
53
                     ->will(
54
                         $this->returnValue('doc')
55
                     );
56
        $uploadedFile->expects($this->once())
57
                     ->method('guessExtension')
58
                     ->will(
59
                         $this->returnValue('doc')
60
                     );
61
62
        // Test the validator.
63
        $validator = new FileValidator();
64
65
        $valid = $validator->validate($uploadedFile);
66
67
        $this->assertFalse($valid);
68
    }
69
}
70