Completed
Push — develop ( e2b887...c09155 )
by
unknown
12:13
created

OrganizationEntityProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createEntityWithRandomData() 0 23 3
A createNewRelations() 0 10 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
namespace OrganizationsTest\Entity\Provider;
11
12
use Organizations\Entity\Organization;
13
14
class OrganizationEntityProvider
0 ignored issues
show
Coding Style introduced by
OrganizationEntityProvider does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
15
{
16
    /**
17
     * @param array $params
18
     *
19
     * @return Organization
20
     */
21
    public static function createEntityWithRandomData(array $params = array())
22
    {
23
        $params = static::createNewRelations($params);
0 ignored issues
show
Bug introduced by
Since createNewRelations() 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 createNewRelations() 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...
24
25
        $withId = true;
26
        $entityId = bin2hex(substr(uniqid(), 1));
27
        // define here another variables
28
29
        extract($params);
30
31
        $organizationEntity = new Organization();
32
        // here set another variables
33
34
        if (!empty($organizationName)) {
35
            $organizationEntity->setOrganizationName($organizationName);
36
        }
37
38
        if ($withId) {
39
            $organizationEntity->setId($entityId);
40
        }
41
42
        return $organizationEntity;
43
    }
44
45
    private static function createNewRelations(array $params = array())
46
    {
47
        extract($params);
48
49
        if (!empty($createOrganizationName)) {
50
            $organizationName = OrganizationNameEntityProvider::createEntityWithRandomData((array)$createOrganizationName);
51
        }
52
53
        return array_merge($params, compact('organizationName'));
54
    }
55
}