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 | class CollectionTest extends PHPUnit_Framework_TestCase |
||
|
|
|||
| 3 | { |
||
| 4 | public function testConstruct() |
||
| 5 | { |
||
| 6 | $arr = array(1,2,3); |
||
| 7 | $collection = new \Suricate\Collection($arr); |
||
| 8 | $this->assertEquals($arr, $collection->getItems()); |
||
| 9 | } |
||
| 10 | |||
| 11 | public function testIsEmpty() |
||
| 12 | { |
||
| 13 | $arr = array(); |
||
| 14 | $collection = new \Suricate\Collection($arr); |
||
| 15 | $this->assertEquals(true, $collection->isEmpty()); |
||
| 16 | } |
||
| 17 | |||
| 18 | public function testUnique() |
||
| 19 | { |
||
| 20 | $arr = array(1, 2, 1, 3); |
||
| 21 | $collection = new \Suricate\Collection($arr); |
||
| 22 | $this->assertEquals([0 => 1, 1 => 2, 3 => 3], $collection->unique()->getItems()); |
||
| 23 | } |
||
| 24 | |||
| 25 | public function testCount() |
||
| 26 | { |
||
| 27 | $arr = array(1, 2, 3); |
||
| 28 | $collection = new \Suricate\Collection($arr); |
||
| 29 | $this->assertEquals(3, $collection->count()); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function testFirst() |
||
| 33 | { |
||
| 34 | $arr = array(4, 5, 6); |
||
| 35 | $collection = new \Suricate\Collection($arr); |
||
| 36 | $this->assertEquals(4, $collection->first()); |
||
| 37 | } |
||
| 38 | |||
| 39 | public function testLast() |
||
| 40 | { |
||
| 41 | $arr = array(1, 2, 3); |
||
| 42 | $collection = new \Suricate\Collection($arr); |
||
| 43 | $this->assertEquals(3, $collection->last()); |
||
| 44 | |||
| 45 | |||
| 46 | $collection = new \Suricate\Collection(); |
||
| 47 | $this->assertEquals(null, $collection->last()); |
||
| 48 | } |
||
| 49 | |||
| 50 | public function testSum() |
||
| 51 | { |
||
| 52 | $arr = array(1, 2, 3); |
||
| 53 | $collection = new \Suricate\Collection($arr); |
||
| 54 | $this->assertEquals(6, $collection->sum()); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function testHas() |
||
| 58 | { |
||
| 59 | $arr = array('a' => 1, 'b' => 2, 'c' => 3); |
||
| 60 | $collection = new \Suricate\Collection($arr); |
||
| 61 | $this->assertEquals(true, $collection->has('b')); |
||
| 62 | $this->assertEquals(false, $collection->has('d')); |
||
| 63 | } |
||
| 64 | |||
| 65 | public function testKeys() |
||
| 66 | { |
||
| 67 | $arr = array('a' => 1, 'b' => 2, 'c' => 3); |
||
| 68 | $collection = new \Suricate\Collection($arr); |
||
| 69 | $this->assertEquals(['a', 'b', 'c'], $collection->keys()); |
||
| 70 | } |
||
| 71 | |||
| 72 | public function testPrepend() |
||
| 73 | { |
||
| 74 | $arr = [4, 5, 6]; |
||
| 75 | $collection = new \Suricate\Collection($arr); |
||
| 76 | $collection->prepend(99); |
||
| 77 | $this->assertEquals([99, 4, 5, 6], $collection->getItems()); |
||
| 78 | } |
||
| 79 | |||
| 80 | public function testPut() |
||
| 81 | { |
||
| 82 | $arr = array('a' => 1, 'b' => 2, 'c' => 3); |
||
| 83 | $collection = new \Suricate\Collection($arr); |
||
| 84 | $collection->put('z', 99); |
||
| 85 | $this->assertEquals(['a' => 1, 'b' => 2, 'c' => 3, 'z' => 99], $collection->getItems()); |
||
| 86 | } |
||
| 87 | |||
| 88 | public function testShift() |
||
| 89 | { |
||
| 90 | $arr = array('a' => 1, 'b' => 2, 'c' => 3); |
||
| 91 | $collection = new \Suricate\Collection($arr); |
||
| 92 | $shifted = $collection->shift(); |
||
| 93 | $this->assertEquals(1, $shifted); |
||
| 94 | $this->assertEquals(['b' => 2, 'c' => 3], $collection->getItems()); |
||
| 95 | } |
||
| 96 | |||
| 97 | public function testPop() |
||
| 98 | { |
||
| 99 | $arr = array('a' => 1, 'b' => 2, 'c' => 3); |
||
| 100 | $collection = new \Suricate\Collection($arr); |
||
| 101 | $popped = $collection->pop(); |
||
| 102 | $this->assertEquals(3, $popped); |
||
| 103 | $this->assertEquals(['a' => 1, 'b' => 2], $collection->getItems()); |
||
| 104 | } |
||
| 105 | |||
| 106 | public function testReverse() |
||
| 107 | { |
||
| 108 | $arr = array('a' => 1, 'b' => 2, 'c' => 3); |
||
| 109 | $collection = new \Suricate\Collection($arr); |
||
| 110 | $reversed = $collection->reverse(); |
||
| 111 | $this->assertEquals(['c' => 3, 'b' => 2, 'a' => 1], $reversed->getItems()); |
||
| 112 | } |
||
| 113 | |||
| 114 | public function testReduce() |
||
| 139 | } |
||
| 140 | |||
| 141 | public function testSlice() |
||
| 142 | { |
||
| 143 | // Basic slice |
||
| 144 | $arr = ['a' => 1, 'b' => 2, 'c' => 3]; |
||
| 145 | $collection = new \Suricate\Collection($arr); |
||
| 146 | $sliced = $collection->slice(1, 2); |
||
| 147 | |||
| 148 | $this->assertEquals(['b' => 2, 'c' => 3], $sliced->getItems()); |
||
| 149 | |||
| 150 | // Slice with numeric keys |
||
| 151 | $arr = [1, 2, 3]; |
||
| 152 | $collection = new \Suricate\Collection($arr); |
||
| 153 | $sliced = $collection->slice(1, 2); |
||
| 154 | |||
| 155 | $this->assertEquals([2, 3], $sliced->getItems()); |
||
| 156 | |||
| 157 | // Slice preserve keys |
||
| 158 | $arr = [1, 2, 3]; |
||
| 159 | $collection = new \Suricate\Collection($arr); |
||
| 160 | $sliced = $collection->slice(1, 2, true); |
||
| 161 | |||
| 162 | $this->assertEquals([1 => 2, 2 => 3], $sliced->getItems()); |
||
| 163 | } |
||
| 164 | |||
| 165 | public function testTake() |
||
| 171 | } |
||
| 172 | |||
| 173 | public function testFilter() |
||
| 182 | ); |
||
| 183 | } |
||
| 184 | |||
| 185 | public function testPush() |
||
| 190 | } |
||
| 191 | } |
||
| 192 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths