getClassWithNamespace()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 2
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 1/3/17
7
 * Time: 7:29 PM
8
 */
9
10
namespace Tfboe\FmLib\Service;
11
12
use Illuminate\Contracts\Container\Container;
13
use Tfboe\FmLib\Service\RankingSystem\RankingSystemInterface;
14
15
/**
16
 * Class DynamicLoadingService
17
 * @package Tfboe\FmLib\Service
18
 */
19
class DynamicServiceLoadingService implements DynamicServiceLoadingServiceInterface
20
{
21
//<editor-fold desc="Fields">
22
  /** @var Container */
23
  private $app;
24
//</editor-fold desc="Fields">
25
26
//<editor-fold desc="Constructor">
27
  /**
28
   * DynamicServiceLoadingService constructor.
29
   * @param Container $app
30
   */
31
  public function __construct(Container $app)
32
  {
33
    $this->app = $app;
34
  }
35
//</editor-fold desc="Constructor">
36
37
//<editor-fold desc="Public Methods">
38
  /**
39
   * @inheritdoc
40
   */
41
  public function loadRankingSystemService(string $name): RankingSystemInterface
42
  {
43
    return $this->app->make($this->getClassWithNamespace($name, 'Tfboe\FmLib\Service\RankingSystem'));
44
  }
45
//</editor-fold desc="Public Methods">
46
47
//<editor-fold desc="Protected Methods">
48
  /**
49
   * Gets the full name of the given class with respect to the given namespace
50
   * @param string $class the class name
51
   * @param string $namespace the namespace
52
   * @return string the full class name (with namespace) and with interface
53
   */
54
  protected function getClassWithNamespace(string $class, string $namespace): string
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
    }
64
  }
65
//</editor-fold desc="Protected Methods">
66
//<editor-fold desc="Private Methods">
67
//</editor-fold desc="Private Methods">
68
}