Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#637)
by Samuel
03:47
created

Fibonacci   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 3
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Respect\Validation\Rules;
13
14
/**
15
 * @author Samuel Heinzmann <[email protected]>
16
 */
17
class Fibonacci extends AbstractRule
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 24
    public function validate($input)
23
    {
24 24
        $fib[0] = 0;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$fib was never initialized. Although not strictly required by PHP, it is generally a good practice to add $fib = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
25 24
        $fib[1] = 1;
26 24
        $n = 1;
27 24
        while ($input > $fib[$n]) {
28 14
            $n++;
29 14
            $fib[$n] = $fib[$n - 1] + $fib[$n - 2];
30 14
        }
31
32 24
        return $fib[$n] === (int)$input && is_numeric($input);
33
    }
34
}