GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0c8f9f...37376a )
by Nicolas
02:44 queued 59s
created

MeasureConverterSpec   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 8
c 4
b 1
f 2
lcom 0
cbo 6
dl 10
loc 75
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 10 10 2
A it_allows_to_define_the_family() 0 4 1
A it_throws_an_exception_if_an_unknown_family_is_set() 0 8 1
A it_converts_a_value_from_a_base_unit_to_a_final_unit() 0 9 1
A it_converts_a_value_to_a_standard_unit() 0 8 1
A it_converts_a_standard_value_to_a_final_unit() 0 8 1
A it_throws_an_exception_if_the_unit_measure_does_not_exist() 0 19 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 spec\Akeneo\Bundle\MeasureBundle\Convert;
4
5
use Akeneo\Bundle\MeasureBundle\Exception\UnknownFamilyMeasureException;
6
use Akeneo\Bundle\MeasureBundle\Exception\UnknownMeasureException;
7
use Akeneo\Bundle\MeasureBundle\Family\WeightFamilyInterface;
8
use PhpSpec\ObjectBehavior;
9
use Prophecy\Argument;
10
use Symfony\Component\Yaml\Yaml;
11
12
class MeasureConverterSpec extends ObjectBehavior
13
{
14 View Code Duplication
    function let()
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...
15
    {
16
        $filename = realpath(dirname(__FILE__) .'/../Resources/config/measure-test.yml');
17
        if (!file_exists($filename)) {
18
            throw new \Exception(sprintf('Config file "%s" does not exist', $filename));
19
        }
20
21
        $config = Yaml::parse(file_get_contents($filename));
22
        $this->beConstructedWith($config);
23
    }
24
25
    function it_allows_to_define_the_family()
26
    {
27
        $this->setFamily('Length')->shouldReturnAnInstanceOf('Akeneo\Bundle\MeasureBundle\Convert\MeasureConverter');
28
    }
29
30
    function it_throws_an_exception_if_an_unknown_family_is_set()
31
    {
32
        $this
33
            ->shouldThrow(
34
                new UnknownFamilyMeasureException()
35
            )
36
            ->during('setFamily', array('foo'));
37
    }
38
39
    function it_converts_a_value_from_a_base_unit_to_a_final_unit()
40
    {
41
        $this->setFamily('Weight');
42
        $this->convert(
43
            WeightFamilyInterface::KILOGRAM,
44
            WeightFamilyInterface::MILLIGRAM,
45
            1
46
        )->shouldReturn((double) 1000000);
47
    }
48
49
    function it_converts_a_value_to_a_standard_unit()
50
    {
51
        $this->setFamily('Weight');
52
        $this->convertBaseToStandard(
53
            WeightFamilyInterface::MILLIGRAM,
54
            1000
55
        )->shouldReturn((double) 1);
56
    }
57
58
    function it_converts_a_standard_value_to_a_final_unit()
59
    {
60
        $this->setFamily('Weight');
61
        $this->convertStandardToResult(
62
            WeightFamilyInterface::KILOGRAM,
63
            10
64
        )->shouldReturn((double) 0.01);
65
    }
66
67
    function it_throws_an_exception_if_the_unit_measure_does_not_exist()
68
    {
69
        $this->setFamily('Weight');
70
        $this
71
            ->shouldThrow(
72
                new UnknownMeasureException(
73
                    'Could not find metric unit "foo" in family "Weight"'
74
                )
75
            )
76
            ->during('convertBaseToStandard', array('foo', Argument::any()));
77
78
        $this
79
            ->shouldThrow(
80
                new UnknownMeasureException(
81
                    'Could not find metric unit "foo" in family "Weight"'
82
                )
83
            )
84
            ->during('convertStandardToResult', array('foo', Argument::any()));
85
    }
86
}
87