Completed
Push — master ( 685463...a3ac99 )
by Benedikt
13:47
created

CompetitionTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 123
Duplicated Lines 21.95 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetLocalIdentifier() 0 6 1
A testInit() 0 9 1
A testLevel() 0 4 1
A testPhasesAndChildren() 0 13 1
A testTeams() 0 10 1
B testTournamentAndParent() 27 27 1
A competition() 0 4 1

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
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 10/1/17
7
 * Time: 1:11 PM
8
 */
9
10
namespace Tfboe\FmLib\Tests\Unit\Entity\Traits;
11
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use PHPUnit\Framework\MockObject\MockObject;
15
use Tfboe\FmLib\Entity\Team;
16
use Tfboe\FmLib\Entity\TournamentInterface;
17
use Tfboe\FmLib\Entity\Traits\Competition;
18
use Tfboe\FmLib\Entity\Traits\Phase;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Tfboe\FmLib\Tests\Unit\Entity\Traits\Phase.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
19
use Tfboe\FmLib\Helpers\Level;
20
use Tfboe\FmLib\TestHelpers\UnitTestCase;
21
22
/**
23
 * Class TournamentTest
24
 * @package Tfboe\FmLib\Tests\Unit\Entity
25
 */
26
class CompetitionTest extends UnitTestCase
27
{
28
//<editor-fold desc="Public Methods">
29
  /**
30
   * @covers \Tfboe\FmLib\Entity\Traits\Competition::getLocalIdentifier
31
   * @uses   \Tfboe\FmLib\Entity\Helpers\NameEntity::getName
32
   * @uses   \Tfboe\FmLib\Entity\Helpers\NameEntity::setName
33
   */
34
  public function testGetLocalIdentifier()
35
  {
36
    $entity = $this->competition();
37
    $entity->setName("Name");
0 ignored issues
show
Bug introduced by
The method setName does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
38
    self::assertEquals($entity->getName(), $entity->getLocalIdentifier());
0 ignored issues
show
Bug introduced by
The method getName does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method getLocalIdentifier does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
39
  }
40
41
  /**
42
   * @covers \Tfboe\FmLib\Entity\Traits\Competition::init
43
   * @uses   \Tfboe\FmLib\Entity\Traits\Competition::getPhases
44
   * @uses   \Tfboe\FmLib\Entity\Traits\Competition::getTeams
45
   */
46
  public function testInit()
47
  {
48
    $competition = $this->competition();
49
    $competition->init();
0 ignored issues
show
Bug introduced by
The method init does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
50
    self::assertInstanceOf(Collection::class, $competition->getTeams());
0 ignored issues
show
Bug introduced by
The method getTeams does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
51
    self::assertInstanceOf(Collection::class, $competition->getPhases());
0 ignored issues
show
Bug introduced by
The method getPhases does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
52
    self::assertEquals(0, $competition->getTeams()->count());
53
    self::assertEquals(0, $competition->getPhases()->count());
54
  }
55
56
  /**
57
   * @covers \Tfboe\FmLib\Entity\Traits\Competition::getLevel()
58
   */
59
  public function testLevel()
60
  {
61
    self::assertEquals(Level::COMPETITION, $this->competition()->getLevel());
0 ignored issues
show
Bug introduced by
The method getLevel does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
62
  }
63
64
  /**
65
   * @covers \Tfboe\FmLib\Entity\Traits\Competition::getPhases
66
   * @covers \Tfboe\FmLib\Entity\Traits\Competition::getChildren
67
   * @uses   \Tfboe\FmLib\Entity\Traits\Phase
68
   * @uses   \Tfboe\FmLib\Entity\Traits\Competition::init
69
   * @uses   \Tfboe\FmLib\Entity\Traits\Competition::init
70
   */
71
  public function testPhasesAndChildren()
72
  {
73
    $competition = $this->competition();
74
    $competition->init();
0 ignored issues
show
Bug introduced by
The method init does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
75
    /** @var Phase $phase */
76
    $phase = $this->getMockForTrait(Phase::class);
77
    $phase->setPhaseNumber(1);
78
    self::assertEquals($competition->getPhases(), $competition->getChildren());
0 ignored issues
show
Bug introduced by
The method getPhases does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method getChildren does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
79
    $competition->getPhases()->set($phase->getPhaseNumber(), $phase);
80
    self::assertEquals(1, $competition->getPhases()->count());
81
    self::assertEquals($phase, $competition->getPhases()[1]);
82
    self::assertEquals($competition->getPhases(), $competition->getChildren());
83
  }
84
85
  /**
86
   * @covers \Tfboe\FmLib\Entity\Traits\Competition::getTeams
87
   * @uses   \Tfboe\FmLib\Entity\Traits\Competition::init
88
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
89
   * @uses   \Tfboe\FmLib\Entity\Team
90
   */
91
  public function testTeams()
92
  {
93
    $competition = $this->competition();
94
    $competition->init();
0 ignored issues
show
Bug introduced by
The method init does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
95
    $team = new Team();
96
    $team->setStartNumber(1);
97
    $competition->getTeams()->set($team->getStartNumber(), $team);
0 ignored issues
show
Bug introduced by
The method getTeams does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
98
    self::assertEquals(1, $competition->getTeams()->count());
99
    self::assertEquals($team, $competition->getTeams()[1]);
100
  }
101
102
  /**
103
   * @covers \Tfboe\FmLib\Entity\Traits\Competition::setTournament()
104
   * @covers \Tfboe\FmLib\Entity\Traits\Competition::getTournament()
105
   * @covers \Tfboe\FmLib\Entity\Traits\Competition::getParent()
106
   * @uses   \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct
107
   * @uses   \Tfboe\FmLib\Entity\Helpers\NameEntity::getName
108
   * @uses   \Tfboe\FmLib\Entity\Helpers\NameEntity::setName
109
   */
110 View Code Duplication
  public function testTournamentAndParent()
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...
111
  {
112
    $competition = $this->competition();
113
    $tournament = $this->createMock(TournamentInterface::class);
114
    $competitions = new ArrayCollection();
115
    $tournament->method('getCompetitions')->willReturn($competitions);
116
    $competition->setName('test competition');
0 ignored issues
show
Bug introduced by
The method setName does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
117
118
    /** @var TournamentInterface $tournament */
119
    $competition->setTournament($tournament);
0 ignored issues
show
Bug introduced by
The method setTournament does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
120
    self::assertEquals($tournament, $competition->getTournament());
0 ignored issues
show
Bug introduced by
The method getTournament does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
121
    self::assertEquals($competition->getTournament(), $competition->getParent());
0 ignored issues
show
Bug introduced by
The method getParent does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
122
    self::assertEquals(1, $competition->getTournament()->getCompetitions()->count());
123
    self::assertEquals($competition, $competition->getTournament()->getCompetitions()[$competition->getName()]);
0 ignored issues
show
Bug introduced by
The method getName does only exist in Tfboe\FmLib\Entity\Traits\Competition, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
124
125
    $tournament2 = $this->createMock(TournamentInterface::class);
126
    $competitions2 = new ArrayCollection();
127
    $tournament2->method('getCompetitions')->willReturn($competitions2);
128
    /** @var TournamentInterface $tournament2 */
129
    $competition->setTournament($tournament2);
130
131
    self::assertEquals($tournament2, $competition->getTournament());
132
    self::assertEquals($competition->getTournament(), $competition->getParent());
133
    self::assertEquals(1, $competition->getTournament()->getCompetitions()->count());
134
    self::assertEquals(0, $tournament->getCompetitions()->count());
135
    self::assertEquals($competition, $competition->getTournament()->getCompetitions()[$competition->getName()]);
136
  }
137
//</editor-fold desc="Public Methods">
138
139
//<editor-fold desc="Private Methods">
140
  /**
141
   * @return Competition|MockObject a new competition
142
   */
143
  private function competition(): MockObject
144
  {
145
    return $this->getMockForTrait(Competition::class);
146
  }
147
//</editor-fold desc="Private Methods">
148
}