ArrayWeReduceTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testArrayWeMapExercise() 13 13 1
A testFunctionRequirements() 6 6 1
A testConfigure() 12 12 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
4
namespace PhpSchool\CallableFunctionsTest\Exercise;
5
6
use PhpSchool\CallableFunctions\Exercise\ArrayWeReduce;
7
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
8
use PhpSchool\PhpWorkshop\Solution\SolutionInterface;
9
use PhpSchool\PhpWorkshop\ExerciseDispatcher;
10
use PhpSchool\PhpWorkshop\Check\FunctionRequirementsCheck;
11
use PHPUnit_Framework_TestCase;
12
13
/**
14
 * Class ArrayWeReduceTest
15
 * @package PhpSchool\LearnYouPhpTest\Exercise
16
 */
17 View Code Duplication
class ArrayWeReduceTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
18
{
19
    public function testArrayWeMapExercise()
20
    {
21
        $e = new ArrayWeReduce();
22
        $this->assertEquals('Array we reduce!', $e->getName());
23
        $this->assertEquals('Exercice with array reduce', $e->getDescription());
24
        $this->assertEquals(ExerciseType::CLI, $e->getType());
25
26
        $this->assertEquals([1, 2, 3], $e->getArgs());
27
28
        $this->assertInstanceOf(SolutionInterface::class, $e->getSolution());
29
        $this->assertFileExists(realpath($e->getProblem()));
30
        $this->assertNull($e->tearDown());
31
    }
32
33
    public function testFunctionRequirements()
34
    {
35
        $e = new ArrayWeReduce();
36
        $this->assertEquals(['array_reduce'], $e->getRequiredFunctions());
37
        $this->assertEquals([], $e->getBannedFunctions());
38
    }
39
40
    public function testConfigure()
41
    {
42
        $dispatcher = $this->getMockBuilder(ExerciseDispatcher::class)
43
            ->disableOriginalConstructor()
44
            ->getMock();
45
        $dispatcher
46
            ->expects($this->once())
47
            ->method('requireCheck')
48
            ->with(FunctionRequirementsCheck::class);
49
        $e = new ArrayWeReduce();
50
        $e->configure($dispatcher);
51
    }
52
}
53