Test Failed
Pull Request — master (#2)
by Pol
03:30
created

Pi   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
cbo 3
dl 0
loc 46
ccs 0
cts 21
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 23 3
A get() 0 4 1
1
<?php
2
3
namespace drupol\Yaroc\Examples;
4
5
use drupol\Yaroc\Plugin\Method\GenerateDecimalFractions;
6
7
/**
8
 * Class Pi.
9
 */
10
class Pi extends BaseExample
11
{
12
    /**
13
     * @var float
14
     */
15
    protected $estimation;
16
17
    /**
18
     * @param int $n
19
     *
20
     * @throws \Http\Client\Exception
21
     *
22
     * @return $this
23
     */
24
    public function run($n = 1000)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $n. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Coding Style Naming introduced by
The variable $GenerateDecimalFractions is not named in camelCase.

This check marks variable names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
25
    {
26
        $parameters = ['n' => $n * 2, 'decimalPlaces' => 6];
27
28
        $GenerateDecimalFractions = (new GenerateDecimalFractions($this->getHttpClient()))
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $GenerateDecimalFractions exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
29
            ->withParameters($parameters);
30
31
        $numbers = $this->getRandomOrgAPI()->getData($GenerateDecimalFractions);
32
33
        $inside = 0;
34
        for ($i = 0; $i < $n; $i++) {
35
            $x = $numbers[$i];
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $x. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
36
            $y = $numbers[$i+1];
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $y. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
37
38
            if (sqrt($x*$x + $y*$y) <= 1) {
39
                $inside++;
40
            }
41
        }
42
43
        $this->estimation = 4 * $inside/$n;
0 ignored issues
show
Documentation Bug introduced by
The property $estimation was declared of type double, but 4 * $inside / $n is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
44
45
        return $this;
46
    }
47
48
    /**
49
     * @return float
50
     */
51
    public function get()
52
    {
53
        return $this->estimation;
54
    }
55
}
56