Completed
Push — master ( 84309c...24e320 )
by Vincenzo
02:46
created

OrmModelsTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 43.08 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testPlayerOrmGetSet() 14 14 1
A testCoachOrmGetSet() 14 14 1
A testTeamOrm() 0 18 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
4
/**
5
 * Class OrmModelsTest
6
 */
7
class OrmModelsTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
10
11
	/**
12
	 * @group OrmModels
13
	 * @group PlayerOrm
14
	 */
15 View Code Duplication
	public function testPlayerOrmGetSet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
	{
17
		$rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
18
		$playerM = $rndFiller->getPlayer();
19
		$arrayPl = $playerM->toArray();
20
		echo "\n";
21
		print_r($arrayPl);
22
		echo "trying orm";
23
		$playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl);
24
		print_r($playerO->toArray());
25
26
		$newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray());
27
		print_r($newPlayer->toArray());
28
	}
29
30
	/**
31
	 * @group OrmModels
32
	 * @group CoachOrm
33
	 */
34 View Code Duplication
	public function testCoachOrmGetSet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
	{
36
		$rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
37
		$coach = $rndFiller->getCoach();
38
		$arrayPl = $coach->toArray();
39
		echo "\n";
40
		print_r($arrayPl);
41
		echo "trying orm";
42
		$coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl);
43
		print_r($coachO->toArray());
44
45
		$newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray());
46
		print_r($newCoach->toArray());
47
	}
48
49
	/**
50
	 * @group OrmModels
51
	 * @group TeamOrm
52
	 */
53
	public function testTeamOrm()
54
	{
55
		$rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
56
		$team = $rndFiller->getTeam($rndFiller->getLocale());
57
		$teamArray = $team->toArray();
58
		echo "\n";
59
		print_r($teamArray);
60
		echo "orm\n";
61
		$teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray);
62
		foreach ($teamArray['roster'] as $player) {
63
			$player['team_id'] = $teamO->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Lib\DsManager\Models\Orm\Team>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
64
			$playerO = \App\Lib\DsManager\Models\Orm\Player::create($player);
0 ignored issues
show
Unused Code introduced by
$playerO is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
65
		}
66
		$teamArray['coach']['team_id'] = $teamO->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Lib\DsManager\Models\Orm\Team>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
67
		\App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']);
68
69
		print_r(\App\Lib\DsManager\Models\Orm\Team::with('roster')->with('coach')->where('id', '=', $teamO->id)->get()->toArray());
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Lib\DsManager\Models\Orm\Team>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
70
	}
71
}
72