ActorFixtures::getAgent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 2
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\DataFixtures;
13
14
use Xabbuh\XApi\Model\Account;
15
use Xabbuh\XApi\Model\Agent;
16
use Xabbuh\XApi\Model\Group;
17
18
/**
19
 * Actor fixtures.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
class ActorFixtures
24
{
25
    /**
26
     * Loads an agent.
27
     *
28
     * @return Agent
29
     */
30
    public static function getAgent()
31
    {
32
        $agent = new Agent('mailto:[email protected]', null, null, null, 'Christian');
33
34
        return $agent;
35
    }
36
37
    /**
38
     * Loads a group.
39
     *
40
     * @return Group
41
     */
42
    public static function getGroup()
43
    {
44
        $account = new Account('GroupAccount', 'http://example.com/homePage');
45
46
        return static::createGroup('Example Group', $account);
0 ignored issues
show
Bug introduced by
Since createGroup() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of createGroup() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
47
    }
48
49
    /**
50
     * Loads a group that has no members.
51
     *
52
     * @return Group
53
     */
54
    public static function getGroupWithoutMembers()
55
    {
56
        $account = new Account('GroupAccount', 'http://example.com/homePage');
57
58
        return new Group(null, null, null, $account, 'Example Group');
59
    }
60
61
    /**
62
     * Loads an anonymous group.
63
     *
64
     * @return Group
65
     */
66
    public static function getAnonymousGroup()
67
    {
68
        return static::createGroup('Anonymous Group');
0 ignored issues
show
Bug introduced by
Since createGroup() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of createGroup() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
69
    }
70
71
    private static function createGroup($name, Account $account = null)
72
    {
73
        $memberAccount = new Account('Member of a group', 'http://example.com/account');
74
        $agent1 = new Agent('mailto:[email protected]', null, null, $memberAccount, 'Andrew Downes');
75
        $agent2 = new Agent(null, null, 'aaron.openid.example.org', null, 'Aaron Silvers');
76
        $group = new Group(null, null, null, $account, $name, array($agent1, $agent2));
77
78
        return $group;
79
    }
80
}
81