Completed
Branch master (0dfbed)
by Benedikt
07:50
created
src/TestHelpers/AuthenticatedTestCase.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -46,39 +46,39 @@
 block discarded – undo
46 46
    */
47 47
   protected function jsonAuth(string $method, string $uri, array $data = [], array $headers = [])
48 48
   {
49
-    $headers['Authorization'] = 'Bearer ' . $this->token;
50
-    return $this->json($method, $uri, $data, $headers);
49
+	$headers['Authorization'] = 'Bearer ' . $this->token;
50
+	return $this->json($method, $uri, $data, $headers);
51 51
   }
52 52
 
53 53
   protected function workOnDatabaseDestroy()
54 54
   {
55
-    $this->clearUsers();
56
-    parent::workOnDatabaseDestroy();
55
+	$this->clearUsers();
56
+	parent::workOnDatabaseDestroy();
57 57
   }
58 58
 
59 59
   protected function workOnDatabaseSetUp()
60 60
   {
61
-    $this->clearUsers();
62
-    parent::workOnDatabaseSetUp();
63
-    $password = $this->newPassword();
64
-    $this->user = entity(User::class)->create(['originalPassword' => $password]);
65
-    /** @noinspection PhpUnhandledExceptionInspection */
66
-    $this->token = Auth::attempt(['email' => $this->user->getEmail(), 'password' => $password]);
67
-    $this->refreshApplication();
68
-    /** @noinspection PhpUndefinedMethodInspection */
69
-    $this->user = EntityManager::find(User::class, $this->user->getId());
61
+	$this->clearUsers();
62
+	parent::workOnDatabaseSetUp();
63
+	$password = $this->newPassword();
64
+	$this->user = entity(User::class)->create(['originalPassword' => $password]);
65
+	/** @noinspection PhpUnhandledExceptionInspection */
66
+	$this->token = Auth::attempt(['email' => $this->user->getEmail(), 'password' => $password]);
67
+	$this->refreshApplication();
68
+	/** @noinspection PhpUndefinedMethodInspection */
69
+	$this->user = EntityManager::find(User::class, $this->user->getId());
70 70
   }
71 71
 //</editor-fold desc="Protected Methods">
72 72
 
73 73
 //<editor-fold desc="Private Methods">
74 74
   private function clearUsers()
75 75
   {
76
-    /** @var Connection $connection */
77
-    /** @noinspection PhpUndefinedMethodInspection */
78
-    $connection = EntityManager::getConnection();
79
-    $sql = sprintf('SET FOREIGN_KEY_CHECKS=0;TRUNCATE TABLE %s;SET FOREIGN_KEY_CHECKS=1;', "users");
80
-    /** @noinspection PhpUnhandledExceptionInspection */
81
-    $connection->query($sql);
76
+	/** @var Connection $connection */
77
+	/** @noinspection PhpUndefinedMethodInspection */
78
+	$connection = EntityManager::getConnection();
79
+	$sql = sprintf('SET FOREIGN_KEY_CHECKS=0;TRUNCATE TABLE %s;SET FOREIGN_KEY_CHECKS=1;', "users");
80
+	/** @noinspection PhpUnhandledExceptionInspection */
81
+	$connection->query($sql);
82 82
   }
83 83
 //</editor-fold desc="Private Methods">
84 84
 }
85 85
\ No newline at end of file
Please login to merge, or discard this patch.
src/TestHelpers/DatabaseTestCase.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
    */
42 42
   public function __construct($name = null, array $data = [], $dataName = '', $clear = false)
43 43
   {
44
-    parent::__construct($name, $data, $dataName);
45
-    srand(3); //always use the same faker values to get reproducibility
46
-    $this->faker = Factory::create();
47
-    $this->clear = $clear;
44
+	parent::__construct($name, $data, $dataName);
45
+	srand(3); //always use the same faker values to get reproducibility
46
+	$this->faker = Factory::create();
47
+	$this->clear = $clear;
48 48
   }
49 49
 //</editor-fold desc="Constructor">
50 50
 
@@ -56,16 +56,16 @@  discard block
 block discarded – undo
56 56
    */
57 57
   protected function clearDatabase()
58 58
   {
59
-    /** @var \Doctrine\DBAL\Connection $connection */
60
-    /** @noinspection PhpUndefinedMethodInspection */
61
-    $connection = EntityManager::getConnection();
62
-    $connection->query(sprintf('SET FOREIGN_KEY_CHECKS = 0;'));
63
-    $tables = $connection->getSchemaManager()->listTables();
64
-    foreach ($tables as $table) {
65
-      $sql = sprintf('TRUNCATE TABLE %s', $table->getName());
66
-      $connection->query($sql);
67
-    }
68
-    $connection->query(sprintf('SET FOREIGN_KEY_CHECKS = 1;'));
59
+	/** @var \Doctrine\DBAL\Connection $connection */
60
+	/** @noinspection PhpUndefinedMethodInspection */
61
+	$connection = EntityManager::getConnection();
62
+	$connection->query(sprintf('SET FOREIGN_KEY_CHECKS = 0;'));
63
+	$tables = $connection->getSchemaManager()->listTables();
64
+	foreach ($tables as $table) {
65
+	  $sql = sprintf('TRUNCATE TABLE %s', $table->getName());
66
+	  $connection->query($sql);
67
+	}
68
+	$connection->query(sprintf('SET FOREIGN_KEY_CHECKS = 1;'));
69 69
   }
70 70
 
71 71
   /**
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
    */
76 76
   protected function createPlayers(int $number = 1): array
77 77
   {
78
-    $result = [];
79
-    for ($i = 0; $i < $number; $i++) {
80
-      $result[] = entity(Player::class)->create();
81
-    }
82
-    return $result;
78
+	$result = [];
79
+	for ($i = 0; $i < $number; $i++) {
80
+	  $result[] = entity(Player::class)->create();
81
+	}
82
+	return $result;
83 83
   }
84 84
 
85 85
   /**
@@ -90,16 +90,16 @@  discard block
 block discarded – undo
90 90
    */
91 91
   protected function createTeams(int $number, $playerPerTeam = 1): array
92 92
   {
93
-    $result = [];
94
-    for ($i = 0; $i < $number; $i++) {
95
-      /** @var Team $team */
96
-      $team = entity(Team::class)->create(['startNumber' => $i + 1, 'rank' => $number - $i]);
97
-      foreach ($this->createPlayers($playerPerTeam) as $player) {
98
-        $team->getPlayers()->add($player);
99
-      }
100
-      $result[] = $team;
101
-    }
102
-    return $result;
93
+	$result = [];
94
+	for ($i = 0; $i < $number; $i++) {
95
+	  /** @var Team $team */
96
+	  $team = entity(Team::class)->create(['startNumber' => $i + 1, 'rank' => $number - $i]);
97
+	  foreach ($this->createPlayers($playerPerTeam) as $player) {
98
+		$team->getPlayers()->add($player);
99
+	  }
100
+	  $result[] = $team;
101
+	}
102
+	return $result;
103 103
   }
104 104
 
105 105
   /**
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
    */
109 109
   protected function createUser()
110 110
   {
111
-    $password = $this->newPassword();
112
-    /** @var User $user */
113
-    $user = entity(User::class)->create(['originalPassword' => $password]);
114
-    return [
115
-      'password' => $password,
116
-      'user' => $user
117
-    ];
111
+	$password = $this->newPassword();
112
+	/** @var User $user */
113
+	$user = entity(User::class)->create(['originalPassword' => $password]);
114
+	return [
115
+	  'password' => $password,
116
+	  'user' => $user
117
+	];
118 118
   }
119 119
 
120 120
   /**
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
    */
124 124
   protected function newPassword()
125 125
   {
126
-    return $this->faker->password(8, 30);
126
+	return $this->faker->password(8, 30);
127 127
   }
128 128
 
129 129
   /**
@@ -134,28 +134,28 @@  discard block
 block discarded – undo
134 134
    */
135 135
   protected function setUpTraits()
136 136
   {
137
-    srand(3); //always use the same faker values to get reproducibility
138
-    $clear = $this->clear;
139
-    parent::setUpTraits();
140
-    if ($clear) {
141
-      $this->clearDatabase();
142
-      $this->workOnDatabaseSetUp();
143
-    } else {
144
-      $this->workOnDatabaseSetUp();
145
-      /** @noinspection PhpUndefinedMethodInspection */
146
-      EntityManager::beginTransaction();
147
-    }
148
-
149
-    $this->beforeApplicationDestroyed(function () use ($clear) {
150
-      if ($clear) {
151
-        $this->workOnDatabaseDestroy();
152
-        $this->clearDatabase();
153
-      } else {
154
-        /** @noinspection PhpUndefinedMethodInspection */
155
-        EntityManager::rollback();
156
-        $this->workOnDatabaseDestroy();
157
-      }
158
-    });
137
+	srand(3); //always use the same faker values to get reproducibility
138
+	$clear = $this->clear;
139
+	parent::setUpTraits();
140
+	if ($clear) {
141
+	  $this->clearDatabase();
142
+	  $this->workOnDatabaseSetUp();
143
+	} else {
144
+	  $this->workOnDatabaseSetUp();
145
+	  /** @noinspection PhpUndefinedMethodInspection */
146
+	  EntityManager::beginTransaction();
147
+	}
148
+
149
+	$this->beforeApplicationDestroyed(function () use ($clear) {
150
+	  if ($clear) {
151
+		$this->workOnDatabaseDestroy();
152
+		$this->clearDatabase();
153
+	  } else {
154
+		/** @noinspection PhpUndefinedMethodInspection */
155
+		EntityManager::rollback();
156
+		$this->workOnDatabaseDestroy();
157
+	  }
158
+	});
159 159
   }
160 160
 
161 161
   protected function workOnDatabaseDestroy()
Please login to merge, or discard this patch.
src/TestHelpers/ReflectionMethods.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
    */
27 27
   protected static function callProtectedMethod($object, string $method, array $args = [])
28 28
   {
29
-    // ReflectionException => get_class is a valid class
30
-    /** @noinspection PhpUnhandledExceptionInspection */
31
-    return self::getMethod(get_class($object), $method)->invokeArgs($object, $args);
29
+	// ReflectionException => get_class is a valid class
30
+	/** @noinspection PhpUnhandledExceptionInspection */
31
+	return self::getMethod(get_class($object), $method)->invokeArgs($object, $args);
32 32
   }
33 33
 
34 34
   /**
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
    */
41 41
   protected static function getMethod(string $class, string $name): \ReflectionMethod
42 42
   {
43
-    $class = new \ReflectionClass($class);
44
-    $method = $class->getMethod($name);
45
-    $method->setAccessible(true);
46
-    return $method;
43
+	$class = new \ReflectionClass($class);
44
+	$method = $class->getMethod($name);
45
+	$method->setAccessible(true);
46
+	return $method;
47 47
   }
48 48
 
49 49
   /**
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
    */
56 56
   protected static function getProperty(string $class, string $name): \ReflectionProperty
57 57
   {
58
-    $class = new \ReflectionClass($class);
59
-    /** @noinspection PhpStatementHasEmptyBodyInspection */
60
-    while (!$class->hasProperty($name) && ($class = $class->getParentClass()) !== null) {
61
-    }
62
-    $property = $class->getProperty($name);
63
-    $property->setAccessible(true);
64
-    return $property;
58
+	$class = new \ReflectionClass($class);
59
+	/** @noinspection PhpStatementHasEmptyBodyInspection */
60
+	while (!$class->hasProperty($name) && ($class = $class->getParentClass()) !== null) {
61
+	}
62
+	$property = $class->getProperty($name);
63
+	$property->setAccessible(true);
64
+	return $property;
65 65
   }
66 66
 //</editor-fold desc="Protected Methods">
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
src/TestHelpers/UnitTestCase.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
    */
35 35
   protected function createStub(string $class, array $methodResults): MockObject
36 36
   {
37
-    $entity = $this->createMock($class);
38
-    foreach ($methodResults as $method => $result) {
39
-      $entity->method($method)->willReturn($result);
40
-    }
41
-    return $entity;
37
+	$entity = $this->createMock($class);
38
+	foreach ($methodResults as $method => $result) {
39
+	  $entity->method($method)->willReturn($result);
40
+	}
41
+	return $entity;
42 42
   }
43 43
 
44 44
   /**
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
    */
51 51
   protected function createStubWithId(string $class, $entityId = "entity-id", $getterMethod = 'getId')
52 52
   {
53
-    return $this->createStub($class, [$getterMethod => $entityId]);
53
+	return $this->createStub($class, [$getterMethod => $entityId]);
54 54
   }
55 55
 
56 56
   /**
@@ -62,26 +62,26 @@  discard block
 block discarded – undo
62 62
    * @return MockObject the mocked entity manager
63 63
    */
64 64
   protected function getEntityManagerMockForQuery(array $result, ?string $expectedQuery = null,
65
-                                                  array $otherMockedMethods = [])
65
+												  array $otherMockedMethods = [])
66 66
   {
67
-    $entityManager = $this->getMockForAbstractClass(EntityManager::class, [], '',
68
-      false, true, true, array_merge($otherMockedMethods, ['createQueryBuilder']));
69
-    $queryBuilder = $this->getMockForAbstractClass(QueryBuilder::class, [$entityManager],
70
-      '', true, true, true, ['getQuery']);
71
-    $query = $this->createMock(AbstractQuery::class);
72
-    $query->expects(static::once())->method('getResult')->willReturn($result);
73
-    if ($expectedQuery !== null) {
74
-      $queryBuilder->expects(static::once())->method('getQuery')->willReturnCallback(
75
-        function () use ($queryBuilder, $query, $expectedQuery) {
76
-          /** @var QueryBuilder $queryBuilder */
77
-          self::assertEquals($expectedQuery, $queryBuilder->getDQL());
78
-          return $query;
79
-        });
80
-    } else {
81
-      $queryBuilder->expects(static::once())->method('getQuery')->willReturn($query);
82
-    }
83
-    $entityManager->expects(static::once())->method('createQueryBuilder')->willReturn($queryBuilder);
84
-    return $entityManager;
67
+	$entityManager = $this->getMockForAbstractClass(EntityManager::class, [], '',
68
+	  false, true, true, array_merge($otherMockedMethods, ['createQueryBuilder']));
69
+	$queryBuilder = $this->getMockForAbstractClass(QueryBuilder::class, [$entityManager],
70
+	  '', true, true, true, ['getQuery']);
71
+	$query = $this->createMock(AbstractQuery::class);
72
+	$query->expects(static::once())->method('getResult')->willReturn($result);
73
+	if ($expectedQuery !== null) {
74
+	  $queryBuilder->expects(static::once())->method('getQuery')->willReturnCallback(
75
+		function () use ($queryBuilder, $query, $expectedQuery) {
76
+		  /** @var QueryBuilder $queryBuilder */
77
+		  self::assertEquals($expectedQuery, $queryBuilder->getDQL());
78
+		  return $query;
79
+		});
80
+	} else {
81
+	  $queryBuilder->expects(static::once())->method('getQuery')->willReturn($query);
82
+	}
83
+	$entityManager->expects(static::once())->method('createQueryBuilder')->willReturn($queryBuilder);
84
+	return $entityManager;
85 85
   }
86 86
 
87 87
   /** @noinspection PhpDocMissingThrowsInspection */
@@ -94,16 +94,16 @@  discard block
 block discarded – undo
94 94
    * @return MockObject the mocked object
95 95
    */
96 96
   protected final function getMockWithMockedArguments(string $className, array $arguments = [],
97
-                                                      array $mockedMethods = []): MockObject
97
+													  array $mockedMethods = []): MockObject
98 98
   {
99
-    /** @noinspection PhpUnhandledExceptionInspection */
100
-    $reflection = new \ReflectionClass($className);
101
-    $params = $reflection->getConstructor()->getParameters();
102
-    $allArguments = $arguments;
103
-    for ($i = count($arguments); $i < count($params); $i++) {
104
-      $allArguments[] = $this->createMock($params[$i]->getClass()->name);
105
-    }
106
-    return $this->getMockForAbstractClass($className, $allArguments, '', true, true, true, $mockedMethods);
99
+	/** @noinspection PhpUnhandledExceptionInspection */
100
+	$reflection = new \ReflectionClass($className);
101
+	$params = $reflection->getConstructor()->getParameters();
102
+	$allArguments = $arguments;
103
+	for ($i = count($arguments); $i < count($params); $i++) {
104
+	  $allArguments[] = $this->createMock($params[$i]->getClass()->name);
105
+	}
106
+	return $this->getMockForAbstractClass($className, $allArguments, '', true, true, true, $mockedMethods);
107 107
   }
108 108
 
109 109
   /** @noinspection PhpDocMissingThrowsInspection */
@@ -116,19 +116,19 @@  discard block
 block discarded – undo
116 116
    */
117 117
   protected final function getObjectWithMockedArguments($className, array $arguments = [])
118 118
   {
119
-    /** @noinspection PhpUnhandledExceptionInspection */
120
-    $reflection = new \ReflectionClass($className);
121
-    $params = $reflection->getConstructor()->getParameters();
122
-    $allArguments = $arguments;
123
-    for ($i = count($arguments); $i < count($params); $i++) {
124
-      $allArguments[$i] = $this->createMock($params[$i]->getClass()->name);
125
-    }
126
-    return new $className(...$allArguments);
119
+	/** @noinspection PhpUnhandledExceptionInspection */
120
+	$reflection = new \ReflectionClass($className);
121
+	$params = $reflection->getConstructor()->getParameters();
122
+	$allArguments = $arguments;
123
+	for ($i = count($arguments); $i < count($params); $i++) {
124
+	  $allArguments[$i] = $this->createMock($params[$i]->getClass()->name);
125
+	}
126
+	return new $className(...$allArguments);
127 127
   }
128 128
 
129 129
   public function tearDown()
130 130
   {
131
-    parent::tearDown();
131
+	parent::tearDown();
132 132
   }
133 133
 //</editor-fold desc="Protected Methods">
134 134
 }
135 135
\ No newline at end of file
Please login to merge, or discard this patch.
src/TestHelpers/OnlyTestLogging.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
    */
26 26
   public function setTestingTrue()
27 27
   {
28
-    Logging::$testing = true;
28
+	Logging::$testing = true;
29 29
   }
30 30
 //</editor-fold desc="Public Methods">
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
src/Service/DynamicServiceLoadingService.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
    */
31 31
   public function __construct(Container $app)
32 32
   {
33
-    $this->app = $app;
33
+	$this->app = $app;
34 34
   }
35 35
 //</editor-fold desc="Constructor">
36 36
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
    */
41 41
   public function loadRankingSystemService(string $name): RankingSystemInterface
42 42
   {
43
-    return $this->app->make($this->getClassWithNamespace($name, 'Tfboe\FmLib\Service\RankingSystem'));
43
+	return $this->app->make($this->getClassWithNamespace($name, 'Tfboe\FmLib\Service\RankingSystem'));
44 44
   }
45 45
 //</editor-fold desc="Public Methods">
46 46
 
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
    */
54 54
   protected function getClassWithNamespace(string $class, string $namespace): string
55 55
   {
56
-    if (strpos($class, 'Interface') === false) {
57
-      $class .= 'Interface';
58
-    }
59
-    if (strpos($class, '\\') === false) {
60
-      return $namespace . '\\' . $class;
61
-    } else {
62
-      return $class;
63
-    }
56
+	if (strpos($class, 'Interface') === false) {
57
+	  $class .= 'Interface';
58
+	}
59
+	if (strpos($class, '\\') === false) {
60
+	  return $namespace . '\\' . $class;
61
+	} else {
62
+	  return $class;
63
+	}
64 64
   }
65 65
 //</editor-fold desc="Protected Methods">
66 66
 //<editor-fold desc="Private Methods">
Please login to merge, or discard this patch.
src/Service/RankingSystem/EloRanking.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
    */
47 47
   protected function getAdditionalFields(): array
48 48
   {
49
-    return ['playedGames' => 0, 'ratedGames' => 0, 'provisoryRanking' => 1200.0];
49
+	return ['playedGames' => 0, 'ratedGames' => 0, 'provisoryRanking' => 1200.0];
50 50
   }
51 51
 
52 52
   /**
@@ -54,51 +54,51 @@  discard block
 block discarded – undo
54 54
    */
55 55
   protected function getChanges(TournamentHierarchyEntity $entity, RankingSystemList $list): array
56 56
   {
57
-    /** @var Game $game */
58
-    $game = $entity;
59
-    $changes = [];
60
-
61
-    if (!$game->isPlayed() || $game->getResult() === Result::NOT_YET_FINISHED ||
62
-      $game->getResult() === Result::NULLED) {
63
-      //game gets not elo rated
64
-      $this->addNotRatedChanges($changes, $game->getPlayersA(), $entity, $list->getRankingSystem());
65
-      $this->addNotRatedChanges($changes, $game->getPlayersB(), $entity, $list->getRankingSystem());
66
-      return $changes;
67
-    }
68
-
69
-    $entriesA = $this->getEntriesOfPlayers($game->getPlayersA(), $list);
70
-    $entriesB = $this->getEntriesOfPlayers($game->getPlayersB(), $list);
71
-
72
-    $isAProvisory = $this->hasProvisoryEntry($entriesA);
73
-    $isBProvisory = $this->hasProvisoryEntry($entriesB);
74
-
75
-    $averageA = $this->getEloAverage($entriesA);
76
-    $averageB = $this->getEloAverage($entriesB);
77
-
78
-    $expectationA = 1 / (1 + 10 ** (($averageB - $averageA) / self::EXP_DIFF));
79
-    $expectationB = 1 - $expectationA;
80
-
81
-    $resultA = 0.0;
82
-
83
-    switch ($game->getResult()) {
84
-      case Result::TEAM_A_WINS:
85
-        $resultA = 1.0;
86
-        break;
87
-      case Result::DRAW:
88
-        $resultA = 0.5;
89
-        break;
90
-    }
91
-    $resultB = 1 - $resultA;
92
-
93
-    $expectationDiffA = $resultA - $expectationA;
94
-    $expectationDiffB = $resultB - $expectationB;
95
-
96
-
97
-    $this->computeChanges($changes, $entriesA, $resultA, $expectationDiffA, $game, $averageA, $averageB,
98
-      $isAProvisory, $isBProvisory);
99
-    $this->computeChanges($changes, $entriesB, $resultB, $expectationDiffB, $game, $averageB, $averageA,
100
-      $isBProvisory, $isAProvisory);
101
-    return $changes;
57
+	/** @var Game $game */
58
+	$game = $entity;
59
+	$changes = [];
60
+
61
+	if (!$game->isPlayed() || $game->getResult() === Result::NOT_YET_FINISHED ||
62
+	  $game->getResult() === Result::NULLED) {
63
+	  //game gets not elo rated
64
+	  $this->addNotRatedChanges($changes, $game->getPlayersA(), $entity, $list->getRankingSystem());
65
+	  $this->addNotRatedChanges($changes, $game->getPlayersB(), $entity, $list->getRankingSystem());
66
+	  return $changes;
67
+	}
68
+
69
+	$entriesA = $this->getEntriesOfPlayers($game->getPlayersA(), $list);
70
+	$entriesB = $this->getEntriesOfPlayers($game->getPlayersB(), $list);
71
+
72
+	$isAProvisory = $this->hasProvisoryEntry($entriesA);
73
+	$isBProvisory = $this->hasProvisoryEntry($entriesB);
74
+
75
+	$averageA = $this->getEloAverage($entriesA);
76
+	$averageB = $this->getEloAverage($entriesB);
77
+
78
+	$expectationA = 1 / (1 + 10 ** (($averageB - $averageA) / self::EXP_DIFF));
79
+	$expectationB = 1 - $expectationA;
80
+
81
+	$resultA = 0.0;
82
+
83
+	switch ($game->getResult()) {
84
+	  case Result::TEAM_A_WINS:
85
+		$resultA = 1.0;
86
+		break;
87
+	  case Result::DRAW:
88
+		$resultA = 0.5;
89
+		break;
90
+	}
91
+	$resultB = 1 - $resultA;
92
+
93
+	$expectationDiffA = $resultA - $expectationA;
94
+	$expectationDiffB = $resultB - $expectationB;
95
+
96
+
97
+	$this->computeChanges($changes, $entriesA, $resultA, $expectationDiffA, $game, $averageA, $averageB,
98
+	  $isAProvisory, $isBProvisory);
99
+	$this->computeChanges($changes, $entriesB, $resultB, $expectationDiffB, $game, $averageB, $averageA,
100
+	  $isBProvisory, $isAProvisory);
101
+	return $changes;
102 102
   }
103 103
 
104 104
   /** @noinspection PhpMissingParentCallCommonInspection */
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
    */
108 108
   protected function startPoints(): float
109 109
   {
110
-    return 1200.0;
110
+	return 1200.0;
111 111
   }
112 112
 //</editor-fold desc="Protected Methods">
113 113
 
@@ -120,16 +120,16 @@  discard block
 block discarded – undo
120 120
    * @param \Tfboe\FmLib\Entity\RankingSystem $ranking
121 121
    */
122 122
   private function addNotRatedChanges(array &$changes, Collection $players, TournamentHierarchyEntity $entity,
123
-                                      RankingSystem $ranking)
123
+									  RankingSystem $ranking)
124 124
   {
125
-    foreach ($players as $player) {
126
-      $change = $this->getOrCreateChange($entity, $ranking, $player);
127
-      $change->setPointsChange(0.0);
128
-      $change->setPlayedGames(0);
129
-      $change->setRatedGames(0);
130
-      $change->setProvisoryRanking(0.0);
131
-      $changes[] = $change;
132
-    }
125
+	foreach ($players as $player) {
126
+	  $change = $this->getOrCreateChange($entity, $ranking, $player);
127
+	  $change->setPointsChange(0.0);
128
+	  $change->setPlayedGames(0);
129
+	  $change->setRatedGames(0);
130
+	  $change->setProvisoryRanking(0.0);
131
+	  $changes[] = $change;
132
+	}
133 133
   }
134 134
 
135 135
   /** @noinspection PhpTooManyParametersInspection */ //TODO refactor this method
@@ -145,56 +145,56 @@  discard block
 block discarded – undo
145 145
    * @param bool $opponentHasProvisory
146 146
    */
147 147
   private function computeChanges(array &$changes, array $entries, float $result, float $expectationDiff, Game $game,
148
-                                  float $teamAverage, float $opponentAverage, bool $teamHasProvisory,
149
-                                  bool $opponentHasProvisory)
148
+								  float $teamAverage, float $opponentAverage, bool $teamHasProvisory,
149
+								  bool $opponentHasProvisory)
150 150
   {
151
-    foreach ($entries as $entry) {
152
-      $change = $this->getOrCreateChange($game, $entry->getRankingSystemList()->getRankingSystem(),
153
-        $entry->getPlayer());
154
-      $change->setPlayedGames(1);
155
-      $factor = 2 * $result - 1;
156
-      if ($entry->getPlayedGames() < self::NUM_PROVISORY_GAMES) {
157
-        //provisory entry => recalculate
158
-        if (count($entries) > 1) {
159
-          $teamMatesAverage = ($teamAverage * count($entries) - $entry->getProvisoryRanking()) /
160
-            (count($entries) - 1);
161
-          if ($teamMatesAverage > $opponentAverage + self::MAX_DIFF_TO_OPPONENT_FOR_PROVISORY) {
162
-            $teamMatesAverage = $opponentAverage + self::MAX_DIFF_TO_OPPONENT_FOR_PROVISORY;
163
-          }
164
-          if ($teamMatesAverage < $opponentAverage - self::MAX_DIFF_TO_OPPONENT_FOR_PROVISORY) {
165
-            $teamMatesAverage = $opponentAverage - self::MAX_DIFF_TO_OPPONENT_FOR_PROVISORY;
166
-          }
167
-          $performance = $opponentAverage * (1 + self::PROVISORY_PARTNER_FACTOR) -
168
-            $teamMatesAverage * self::PROVISORY_PARTNER_FACTOR;
169
-        } else {
170
-          $performance = $opponentAverage;
171
-        }
172
-        if ($performance < self::START) {
173
-          $performance = self::START;
174
-        }
175
-        $performance += self::EXP_DIFF * $factor;
176
-        //old average performance = $entry->getProvisoryRating()
177
-        //=> new average performance = ($entry->getProvisoryRating() * $entry->getRatedGames() + $performance) /
178
-        //                             ($entry->getRatedGames() + 1)
179
-        //=> performance change = ($entry->getProvisoryRating() * $entry->getRatedGames() + $performance) /
180
-        //                        ($entry->getRatedGames() + 1) - $entry->getProvisoryRating()
181
-        //                      = ($performance - $entry->getProvisoryRating()) / ($entry->getRatedGames() + 1)
182
-        $change->setProvisoryRanking(($performance - $entry->getProvisoryRanking()) / ($entry->getRatedGames() + 1));
183
-        $change->setPointsChange(0.0);
184
-        $change->setRatedGames(1);
185
-      } else if (!$teamHasProvisory && !$opponentHasProvisory) {
186
-        //real elo ranking
187
-        $change->setProvisoryRanking(0.0);
188
-        $change->setPointsChange(self::K * $expectationDiff);
189
-        $change->setRatedGames(1);
190
-      } else {
191
-        //does not get rated
192
-        $change->setProvisoryRanking(0.0);
193
-        $change->setPointsChange(0.0);
194
-        $change->setRatedGames(0);
195
-      }
196
-      $changes[] = $change;
197
-    }
151
+	foreach ($entries as $entry) {
152
+	  $change = $this->getOrCreateChange($game, $entry->getRankingSystemList()->getRankingSystem(),
153
+		$entry->getPlayer());
154
+	  $change->setPlayedGames(1);
155
+	  $factor = 2 * $result - 1;
156
+	  if ($entry->getPlayedGames() < self::NUM_PROVISORY_GAMES) {
157
+		//provisory entry => recalculate
158
+		if (count($entries) > 1) {
159
+		  $teamMatesAverage = ($teamAverage * count($entries) - $entry->getProvisoryRanking()) /
160
+			(count($entries) - 1);
161
+		  if ($teamMatesAverage > $opponentAverage + self::MAX_DIFF_TO_OPPONENT_FOR_PROVISORY) {
162
+			$teamMatesAverage = $opponentAverage + self::MAX_DIFF_TO_OPPONENT_FOR_PROVISORY;
163
+		  }
164
+		  if ($teamMatesAverage < $opponentAverage - self::MAX_DIFF_TO_OPPONENT_FOR_PROVISORY) {
165
+			$teamMatesAverage = $opponentAverage - self::MAX_DIFF_TO_OPPONENT_FOR_PROVISORY;
166
+		  }
167
+		  $performance = $opponentAverage * (1 + self::PROVISORY_PARTNER_FACTOR) -
168
+			$teamMatesAverage * self::PROVISORY_PARTNER_FACTOR;
169
+		} else {
170
+		  $performance = $opponentAverage;
171
+		}
172
+		if ($performance < self::START) {
173
+		  $performance = self::START;
174
+		}
175
+		$performance += self::EXP_DIFF * $factor;
176
+		//old average performance = $entry->getProvisoryRating()
177
+		//=> new average performance = ($entry->getProvisoryRating() * $entry->getRatedGames() + $performance) /
178
+		//                             ($entry->getRatedGames() + 1)
179
+		//=> performance change = ($entry->getProvisoryRating() * $entry->getRatedGames() + $performance) /
180
+		//                        ($entry->getRatedGames() + 1) - $entry->getProvisoryRating()
181
+		//                      = ($performance - $entry->getProvisoryRating()) / ($entry->getRatedGames() + 1)
182
+		$change->setProvisoryRanking(($performance - $entry->getProvisoryRanking()) / ($entry->getRatedGames() + 1));
183
+		$change->setPointsChange(0.0);
184
+		$change->setRatedGames(1);
185
+	  } else if (!$teamHasProvisory && !$opponentHasProvisory) {
186
+		//real elo ranking
187
+		$change->setProvisoryRanking(0.0);
188
+		$change->setPointsChange(self::K * $expectationDiff);
189
+		$change->setRatedGames(1);
190
+	  } else {
191
+		//does not get rated
192
+		$change->setProvisoryRanking(0.0);
193
+		$change->setPointsChange(0.0);
194
+		$change->setRatedGames(0);
195
+	  }
196
+	  $changes[] = $change;
197
+	}
198 198
   }
199 199
 
200 200
   /**
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
    */
205 205
   private function getEloAverage(array $entries): float
206 206
   {
207
-    $sum = 0;
208
-    foreach ($entries as $entry) {
209
-      $sum += $entry->getRatedGames() < self::NUM_PROVISORY_GAMES ? $entry->getProvisoryRanking() : $entry->getPoints();
210
-    }
211
-    return $sum / count($entries);
207
+	$sum = 0;
208
+	foreach ($entries as $entry) {
209
+	  $sum += $entry->getRatedGames() < self::NUM_PROVISORY_GAMES ? $entry->getProvisoryRanking() : $entry->getPoints();
210
+	}
211
+	return $sum / count($entries);
212 212
   }
213 213
 
214 214
   /**
@@ -218,12 +218,12 @@  discard block
 block discarded – undo
218 218
    */
219 219
   private function hasProvisoryEntry(array $entries): bool
220 220
   {
221
-    foreach ($entries as $entry) {
222
-      if ($entry->getPlayedGames() < self::NUM_PROVISORY_GAMES) {
223
-        return true;
224
-      }
225
-    }
226
-    return false;
221
+	foreach ($entries as $entry) {
222
+	  if ($entry->getPlayedGames() < self::NUM_PROVISORY_GAMES) {
223
+		return true;
224
+	  }
225
+	}
226
+	return false;
227 227
   }
228 228
 //</editor-fold desc="Private Methods">
229 229
 }
230 230
\ No newline at end of file
Please login to merge, or discard this patch.
Service/RankingSystem/EntityComparerByTimeStartTimeAndLocalIdentifier.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
    */
32 32
   public function __construct(TimeServiceInterface $timeService)
33 33
   {
34
-    $this->timeService = $timeService;
34
+	$this->timeService = $timeService;
35 35
   }
36 36
 //</editor-fold desc="Constructor">
37 37
 
@@ -42,18 +42,18 @@  discard block
 block discarded – undo
42 42
    */
43 43
   public function compareEntities(TournamentHierarchyInterface $entity1, TournamentHierarchyInterface $entity2): int
44 44
   {
45
-    $tmpE1 = $entity1;
46
-    $tmpE2 = $entity2;
47
-    while ($tmpE1 !== null && $tmpE2 !== null && $tmpE1->getId() !== $tmpE2->getId()) {
48
-      $comparison = $this->compareEntityTimes($tmpE1, $tmpE2);
49
-      if ($comparison !== 0) {
50
-        return $comparison;
51
-      }
52
-      $tmpE1 = $tmpE1->getParent();
53
-      $tmpE2 = $tmpE2->getParent();
54
-    }
45
+	$tmpE1 = $entity1;
46
+	$tmpE2 = $entity2;
47
+	while ($tmpE1 !== null && $tmpE2 !== null && $tmpE1->getId() !== $tmpE2->getId()) {
48
+	  $comparison = $this->compareEntityTimes($tmpE1, $tmpE2);
49
+	  if ($comparison !== 0) {
50
+		return $comparison;
51
+	  }
52
+	  $tmpE1 = $tmpE1->getParent();
53
+	  $tmpE2 = $tmpE2->getParent();
54
+	}
55 55
 
56
-    return $this->compareLocalIdentifiersWithinTournament($entity1, $entity2);
56
+	return $this->compareLocalIdentifiersWithinTournament($entity1, $entity2);
57 57
   }
58 58
 //</editor-fold desc="Public Methods">
59 59
 
@@ -66,23 +66,23 @@  discard block
 block discarded – undo
66 66
    *             entity2 are before the times of entity1 and 0 if they have the same times
67 67
    */
68 68
   protected function compareEntityTimes(TournamentHierarchyInterface $entity1,
69
-                                        TournamentHierarchyInterface $entity2)
69
+										TournamentHierarchyInterface $entity2)
70 70
   {
71
-    $time1 = $this->timeService->getTime($entity1);
72
-    $time2 = $this->timeService->getTime($entity2);
73
-    if ($time1 < $time2) {
74
-      return -1;
75
-    } else if ($time1 > $time2) {
76
-      return 1;
77
-    }
78
-    if ($entity1->getStartTime() !== null && $entity2->getStartTime() !== null) {
79
-      if ($entity1->getStartTime() < $entity2->getStartTime()) {
80
-        return -1;
81
-      } else if ($entity1->getStartTime() > $entity2->getStartTime()) {
82
-        return 1;
83
-      }
84
-    }
85
-    return 0;
71
+	$time1 = $this->timeService->getTime($entity1);
72
+	$time2 = $this->timeService->getTime($entity2);
73
+	if ($time1 < $time2) {
74
+	  return -1;
75
+	} else if ($time1 > $time2) {
76
+	  return 1;
77
+	}
78
+	if ($entity1->getStartTime() !== null && $entity2->getStartTime() !== null) {
79
+	  if ($entity1->getStartTime() < $entity2->getStartTime()) {
80
+		return -1;
81
+	  } else if ($entity1->getStartTime() > $entity2->getStartTime()) {
82
+		return 1;
83
+	  }
84
+	}
85
+	return 0;
86 86
   }
87 87
 
88 88
   /**
@@ -93,20 +93,20 @@  discard block
 block discarded – undo
93 93
    *             and 0 if the two entities are equal (<=> all predecessors have same local identifiers)
94 94
    */
95 95
   protected function compareLocalIdentifiersWithinTournament(TournamentHierarchyInterface $entity1,
96
-                                                             TournamentHierarchyInterface $entity2)
96
+															 TournamentHierarchyInterface $entity2)
97 97
   {
98
-    //compare unique identifiers within tournament
99
-    $predecessors1 = $this->getPredecessors($entity1);
100
-    $predecessors2 = $this->getPredecessors($entity2);
98
+	//compare unique identifiers within tournament
99
+	$predecessors1 = $this->getPredecessors($entity1);
100
+	$predecessors2 = $this->getPredecessors($entity2);
101 101
 
102
-    for ($i = count($predecessors1) - 1; $i >= 0; $i--) {
103
-      if ($predecessors1[$i]->getLocalIdentifier() !== $predecessors2[$i]->getLocalIdentifier()) {
104
-        return $predecessors1[$i]->getLocalIdentifier() <=> $predecessors2[$i]->getLocalIdentifier();
105
-      }
106
-    }
102
+	for ($i = count($predecessors1) - 1; $i >= 0; $i--) {
103
+	  if ($predecessors1[$i]->getLocalIdentifier() !== $predecessors2[$i]->getLocalIdentifier()) {
104
+		return $predecessors1[$i]->getLocalIdentifier() <=> $predecessors2[$i]->getLocalIdentifier();
105
+	  }
106
+	}
107 107
 
108
-    //the two entities are equal
109
-    return 0;
108
+	//the two entities are equal
109
+	return 0;
110 110
   }
111 111
 //</editor-fold desc="Protected Methods">
112 112
 
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
    */
119 119
   private function getPredecessors(TournamentHierarchyInterface $entity): array
120 120
   {
121
-    $res = [];
122
-    while ($entity !== null) {
123
-      $res[] = $entity;
124
-      $entity = $entity->getParent();
125
-    }
126
-    return $res;
121
+	$res = [];
122
+	while ($entity !== null) {
123
+	  $res[] = $entity;
124
+	  $entity = $entity->getParent();
125
+	}
126
+	return $res;
127 127
   }
128 128
 //</editor-fold desc="Private Methods">
129 129
 }
130 130
\ No newline at end of file
Please login to merge, or discard this patch.
src/Service/RankingSystem/RankingSystemInterface.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
    *                       tournament before the change
40 40
    */
41 41
   public function updateRankingForTournament(RankingSystem $ranking, Tournament $tournament,
42
-                                             ?\DateTime $oldInfluence);
42
+											 ?\DateTime $oldInfluence);
43 43
 
44 44
   /**
45 45
    * Updates the rankings assuming all changes happened after $from.
Please login to merge, or discard this patch.