Badge   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A doCount() 0 9 2
A getCount() 0 4 1
1
<?php
2
3
namespace Alpixel\Bundle\AdminMenuBundle\Menu;
4
5
class Badge
6
{
7
    protected $count = 0;
8
9
    public function __construct($service, $repositoryName, $repositoryMethod, $parameters = [])
10
    {
11
        $this->count = 0;
12
        $this->doCount($service, $repositoryName, $repositoryMethod, $parameters);
13
    }
14
15
    protected function doCount($service, $repositoryName, $repositoryMethod, $parameters)
16
    {
17
        $repository = $service->getRepository($repositoryName);
18
        $count = call_user_func([$repository, $repositoryMethod], $parameters);
19
        if (!is_numeric($count)) {
20
            throw new \Exception('Badge result is not a valid numeric value');
21
        }
22
        $this->count = $count;
0 ignored issues
show
Documentation Bug introduced by
It seems like $count can also be of type double or string. However, the property $count is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
23
    }
24
25
    public function getCount()
26
    {
27
        return $this->count;
28
    }
29
}
30