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.

GroupDefinitionAwareRolloutTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 5
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testGroupDefinitionAware() 0 19 1
1
<?php
2
3
namespace Opensoft\RolloutBundle\Tests\Rollout;
4
5
use Opensoft\Rollout\RolloutUserInterface;
6
use Opensoft\Rollout\Storage\ArrayStorage;
7
use Opensoft\RolloutBundle\Rollout\GroupDefinitionAwareRollout;
8
9
/**
10
 * @author Richard Fullmer <[email protected]>
11
 */
12
class GroupDefinitionAwareRolloutTest extends \PHPUnit_Framework_TestCase
13
{
14
    public function testGroupDefinitionAware()
15
    {
16
        $group = $this->getMockBuilder('Opensoft\RolloutBundle\Rollout\GroupDefinitionInterface')->getMock();
17
        $group->expects($this->once())->method('getName')->will($this->returnValue('test_group'));
18
19
        $callback = function (RolloutUserInterface $user) {
20
            return $user->name == 'test_user';
0 ignored issues
show
Bug introduced by
Accessing name on the interface Opensoft\Rollout\RolloutUserInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
21
        };
22
23
        $group->expects($this->once())->method('getCallback')->will($this->returnValue($callback));
24
25
        $rollout = new GroupDefinitionAwareRollout(new ArrayStorage());
26
27
        $rollout->addGroupDefinition($group);
28
29
        $this->assertEquals(1, count($rollout->getGroupDefinitions()));
30
        $this->assertTrue($rollout->isActiveInGroup('test_group', new User('test_user')));
31
        $this->assertFalse($rollout->isActiveInGroup('test_group', new User('other_user')));
32
    }
33
}
34
35
class User implements RolloutUserInterface
36
{
37
    public $name;
38
39
    /**
40
     * @param string $name
41
     */
42
    public function __construct($name)
43
    {
44
        $this->name = $name;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getRolloutIdentifier()
51
    {
52
        return '';
53
    }
54
}
55