LocalStorageTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 8
loc 36
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 8 8 1
A testRead() 0 6 1
A testGetFileSize() 0 7 1
A testGetFiles() 0 7 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
namespace Partnermarketing\FileSystemBundle\Tests\Unit\Adapter;
4
5
use Partnermarketing\FileSystemBundle\Adapter\LocalStorage;
6
use Partnermarketing\FileSystemBundle\Factory\FileSystemFactory;
7
8
class LocalStorageTest extends \PHPUnit_Framework_TestCase
9
{
10
    private $adapter;
11
12 View Code Duplication
    protected function setUp()
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...
13
    {
14
        $this->config = [
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
            'local_storage' => ['path' => __DIR__, 'url' => 'http://files.test/'],
16
            'amazon_s3' => ['key' => '', 'secret' => '', 'region' => '', 'bucket' => ''],
17
        ];
18
        $this->adapter = (new FileSystemFactory('local_storage', $this->config, '/tmp'))->build();
19
    }
20
21
    public function testRead()
22
    {
23
        $content = $this->adapter->read('test.txt');
24
25
        $this->assertEquals("hello,\n\nthis is a file.\n", $content);
26
    }
27
28
    public function testGetFileSize()
29
    {
30
        $actualSize = $this->adapter->getFileSize('test.txt');
31
        $expectedSize = strlen("hello,\n\nthis is a file.\n");
32
33
        $this->assertEquals($expectedSize, $actualSize);
34
    }
35
36
    public function testGetFiles()
37
    {
38
        $result = $this->adapter->getFiles();
39
40
        $this->assertCount(3, $result);
41
        $this->assertContains('sub-dir/test2.txt', $result);
42
    }
43
}
44