Completed
Push — master ( c9812e...73d93a )
by Ryuichi
02:42
created

InputStreamReaderProvider   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 102
Duplicated Lines 34.31 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 0
cbo 2
dl 35
loc 102
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A readCharProvider() 0 13 1
A readLineProvider() 7 7 1
A closeProvider() 7 7 1
A skipProvider() 0 17 1
A overSkipAndReadProvider() 0 9 1
A frontSkipProvider() 0 7 1
A overFrontSkipProvider() 0 9 1
A resetProvider() 7 7 1
A markAndResetProvider() 7 7 1
A invalidLengthProvider() 7 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
namespace WebStream\IO\Test\Providers;
3
4
use WebStream\IO\FileInputStream;
5
use WebStream\IO\StringInputStream;
6
7
/**
8
 * InputStreamReaderProvider
9
 * @author Ryuichi TANAKA.
10
 * @since 2016/08/18
11
 * @version 0.7
12
 */
13
trait InputStreamReaderProvider
14
{
15
    public function readCharProvider()
16
    {
17
        return [
18
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test1.txt"), "a", 1],
19
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test1.txt"), "a\n", 100], // over eof
20
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test2.txt"), "あ", 3],
21
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test2.txt"), "あ\n", 100], // over eof
22
            [new StringInputStream("a"), "a", 1],
23
            [new StringInputStream("a"), "a", 100], // over eof
24
            [new StringInputStream("あ"), "あ", 3],
25
            [new StringInputStream("あ"), "あ", 100] // over eof
26
        ];
27
    }
28
29 View Code Duplication
    public function readLineProvider()
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...
30
    {
31
        return [
32
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test3.txt"), "test1", "test2"],
33
            [new StringInputStream("test1\ntest2\n"), "test1", "test2"]
34
        ];
35
    }
36
37 View Code Duplication
    public function closeProvider()
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...
38
    {
39
        return [
40
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test1.txt")],
41
            [new StringInputStream("a\n")]
42
        ];
43
    }
44
45
    public function skipProvider()
46
    {
47
        return [
48
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test4.txt"), "a", 0],
49
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test4.txt"), "b", 1],
50
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test4.txt"), "d", 3],
51
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test4.txt"), "f", 5],
52
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test4.txt"), "\n", 9],
53
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test4.txt"), "", 10],
54
            [new StringInputStream("abcdefghi"), "a", 0],
55
            [new StringInputStream("abcdefghi"), "b", 1],
56
            [new StringInputStream("abcdefghi"), "d", 3],
57
            [new StringInputStream("abcdefghi"), "f", 5],
58
            [new StringInputStream("abcdefghi"), "", 9],
59
            [new StringInputStream("abcdefghi"), "", 10]
60
        ];
61
    }
62
63
    public function overSkipAndReadProvider()
64
    {
65
        return [
66
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test5.txt"), 4],
67
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test6.txt"), 100],
68
            [new StringInputStream("abc\n"), 4],
69
            [new StringInputStream("abcde\nあいうえお"), 100]
70
        ];
71
    }
72
73
    public function frontSkipProvider()
74
    {
75
        return [
76
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test8.txt"), 3, -1, "c"],
77
            [new StringInputStream("abcde\n"), 3, -1, "c"]
78
        ];
79
    }
80
81
    public function overFrontSkipProvider()
82
    {
83
        return [
84
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test1.txt"), -1],
85
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test1.txt"), -100],
86
            [new StringInputStream("a\n"), -1],
87
            [new StringInputStream("a\n"), -100]
88
        ];
89
    }
90
91 View Code Duplication
    public function resetProvider()
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...
92
    {
93
        return [
94
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test1.txt"), 1, "a"],
95
            [new StringInputStream("a\n"), 1, "a"]
96
        ];
97
    }
98
99 View Code Duplication
    public function markAndResetProvider()
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...
100
    {
101
        return [
102
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test7.txt"), 3, "d"],
103
            [new StringInputStream("abcde\n"), 3, "d"]
104
        ];
105
    }
106
107 View Code Duplication
    public function invalidLengthProvider()
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...
108
    {
109
        return [
110
            [new FileInputStream(dirname(__FILE__)  . "/../Fixtures/inputstreamreader-test1.txt"), "a"],
111
            [new StringInputStream("a\n"), "a"]
112
        ];
113
    }
114
}
115