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 ( 6fec7d...965ddd )
by Spencer
03:27
created

All::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Nubs\RandomNameGenerator;
3
4
use Cinam\Randomizer\Randomizer;
5
6
/**
7
 * A generator that uses all of the other generators randomly.
8
 */
9
class All implements Generator
10
{
11
    /** @type array The other generators to use. */
12
    protected $_generators;
13
14
    /** @type Cinam\Randomizer\Randomizer The random number generator. */
15
    protected $_randomizer;
16
17
    /**
18
     * Initializes the All Generator with the list of generators to choose from.
19
     *
20
     * @api
21
     * @param array $generators The random generators to use.
22
     * @param \Cinam\Randomizer\Randomizer $randomizer The random number generator.
23
     */
24
    public function __construct(array $generators, Randomizer $randomizer = null)
25
    {
26
        $this->_generators = $generators;
27
        $this->_randomizer = $randomizer;
0 ignored issues
show
Documentation Bug introduced by
It seems like $randomizer can also be of type object<Cinam\Randomizer\Randomizer>. However, the property $_randomizer is declared as type object<Nubs\RandomNameGe...\Randomizer\Randomizer>. 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...
28
    }
29
30
    /**
31
     * Constructs an All Generator using the default list of generators.
32
     *
33
     * @api
34
     * @param \Cinam\Randomizer\Randomizer $randomizer The random number generator.
35
     * @return \Nubs\RandomNameGenerator\All The constructed generator.
36
     */
37
    public static function create(Randomizer $randomizer = null)
38
    {
39
        return new self([new Alliteration($randomizer), new Vgng($randomizer)], $randomizer);
40
    }
41
42
    /**
43
     * Gets a randomly generated name using the configured generators.
44
     *
45
     * @api
46
     * @return string A random name.
47
     */
48
    public function getName()
49
    {
50
        return $this->_getRandomGenerator()->getName();
51
    }
52
53
    /**
54
     * Get a random generator from the list of generators.
55
     *
56
     * @return \Nubs\RandomNameGenerator\Generator A random generator.
57
     */
58
    protected function _getRandomGenerator()
59
    {
60
        return $this->_randomizer ? $this->_randomizer->getArrayValue($this->_generators) : $this->_generators[array_rand($this->_generators)];
61
    }
62
}
63