Passed
Push — master ( ffc9d9...c5e0f8 )
by
unknown
07:07
created

SaasClientService::__call()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 14
c 0
b 0
f 0
rs 10
cc 3
nc 3
nop 2
1
<?php
2
3
namespace Fluxter\SaasProviderBundle\Service;
4
5
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\HttpFoundation\Session\SessionInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFo...ession\SessionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Fluxter\SaasProviderBundle\Model\SaasClientInterface;
8
9
class SaasClientService
10
{
11
    /** @var EntityManagerInterface */
12
    private $em;
13
14
    /** @var SessionInterface */
15
    private $session;
16
17
    private $clientEntity;
18
19
    private const SaasClientSessionIndex = "SAASCLIENT";
20
21
    public function __construct(string $clientEntity, EntityManagerInterface $em, SessionInterface $session)
22
    {
23
        $this->em = $em;
24
        $this->session = $session;
25
        $this->clientEntity = $clientEntity;
26
    }
27
28
    public function __call($name, $arguments)
29
    {
30
        $client = $this->getCurrentCommunity();
0 ignored issues
show
Bug introduced by
The method getCurrentCommunity() does not exist on Fluxter\SaasProviderBund...rvice\SaasClientService. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        /** @scrutinizer ignore-call */ 
31
        $client = $this->getCurrentCommunity();
Loading history...
31
32
        $method = "get$name";
33
        if (method_exists($client, $method)) {
34
            return $client->$method();
35
        }
36
        $method = "is$name";
37
        if (method_exists($client, $method)) {
38
            return $client->$method();
39
        }
40
41
        throw new \Exception("Unknown SaaS-Client function / variable: {$name}!");
42
    }
43
44
    public function createClient()
45
    { }
46
47
    public function getCurrent()
48
    {
49
        if (!$this->session->has(self::SaasClientSessionIndex)) {
50
            throw new \Exception("SAAS-CLIENT SESSION VARIABLE NOT SPECIFIED");
51
        }
52
53
        // Todo Entity name from configuration
54
        $repo = $this->em->getRepository($this->clientEntity);
55
56
        /** @var SaasClientInterface $client */
57
        $client = $repo->findOneById($this->session->get(self::SaasClientSessionIndex));
58
        if ($client == null) {
59
            throw new \Exception("SAAS-CLIENT NOT FOUND!");
60
        }
61
62
        return $client;
63
    }
64
}
65