TenantableFilter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A addFilterConstraint() 0 12 3
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\MultiTenancyBundle\Query\Filter;
16
17
use Doctrine\ORM\Mapping\ClassMetadata;
18
use Doctrine\ORM\Query\Filter\SQLFilter;
19
use SWP\Component\MultiTenancy\Model\TenantAwareInterface;
20
21
/**
22
 * Tenantable Filter class.
23
 */
24
class TenantableFilter extends SQLFilter
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
30
    {
31
        if (!$targetEntity->reflClass->implementsInterface(TenantAwareInterface::class)) {
32
            return '';
33
        }
34
35
        if ($this->hasParameter('tenantCode')) {
36
            return sprintf('%s.tenant_code = %s', $targetTableAlias, $this->getParameter('tenantCode'));
37
        }
38
39
        return '';
40
    }
41
}
42