GameRankingSystemService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 50
rs 10
wmc 2
lcom 0
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntitiesQueryBuilder() 0 33 1
A getLevel() 0 4 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 1/2/18
7
 * Time: 2:34 PM
8
 */
9
10
namespace Tfboe\FmLib\Service\RankingSystem;
11
12
13
use Doctrine\ORM\Query;
14
use Doctrine\ORM\QueryBuilder;
15
use Tfboe\FmLib\Entity\GameInterface;
16
use Tfboe\FmLib\Entity\RankingSystemInterface;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Tfboe\FmLib\Service\Rank...\RankingSystemInterface.

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...
17
use Tfboe\FmLib\Helpers\Level;
18
19
20
/**
21
 * Class GameRankingSystemService
22
 * @package Tfboe\FmLib\Service\RankingSystemService
23
 */
24
abstract class GameRankingSystemService extends RankingSystemService implements GameRankingSystemInterface
25
{
26
//<editor-fold desc="Protected Methods">
27
  /**
28
   * @inheritDoc
29
   */
30
  protected function getEntitiesQueryBuilder(RankingSystemInterface $ranking, \DateTime $from, \DateTime $to): QueryBuilder
31
  {
32
    // query all relevant games
33
    $query = $this->getEntityManager()->createQueryBuilder();
34
    $query
35
      ->from(GameInterface::class, 'g')
36
      ->select('g')
37
      ->leftJoin('g.rankingSystems', 'grs', Query\Expr\Join::WITH, $query->expr()->eq('grs', ':ranking'))
38
      ->innerJoin('g.match', 'm')
39
      ->leftJoin('m.rankingSystems', 'mrs', Query\Expr\Join::WITH, $query->expr()->eq('mrs', ':ranking'))
40
      ->innerJoin('m.phase', 'p')
41
      ->leftJoin('p.rankingSystems', 'prs', Query\Expr\Join::WITH, $query->expr()->eq('prs', ':ranking'))
42
      ->innerJoin('p.competition', 'c')
43
      ->leftJoin('c.rankingSystems', 'crs', Query\Expr\Join::WITH, $query->expr()->eq('crs', ':ranking'))
44
      ->innerJoin('c.tournament', 't')
45
      ->leftJoin('t.rankingSystems', 'trs', Query\Expr\Join::WITH, $query->expr()->eq('trs', ':ranking'))
46
      ->setParameter('ranking', $ranking)
47
      ->andWhere("COALESCE(g.endTime, g.startTime, m.endTime, m.startTime, p.endTime, p.startTime, c.endTime, " .
48
        "c.startTime, t.endTime, t.startTime, t.updatedAt) > :from")
49
      ->setParameter('from', $from)
50
      ->andWhere("COALESCE(g.endTime, g.startTime, m.endTime, m.startTime, p.endTime, p.startTime, c.endTime, " .
51
        "c.startTime, t.endTime, t.startTime, t.updatedAt) <= :to")
52
      ->setParameter('to', $to)
53
      ->andWhere($query->expr()->orX(
54
        $query->expr()->isNotNull('grs.id'),
55
        $query->expr()->isNotNull('mrs.id'),
56
        $query->expr()->isNotNull('prs.id'),
57
        $query->expr()->isNotNull('crs.id'),
58
        $query->expr()->isNotNull('trs.id')
59
      ));
60
61
    return $query;
62
  }
63
64
  /**
65
   * @inheritDoc
66
   */
67
  protected function getLevel(): int
68
  {
69
    return Level::GAME;
70
  }
71
//</editor-fold desc="Protected Methods">
72
73
}