Completed
Push — api ( cecea0...116a36 )
by Kamil
29:57 queued 30s
created

ExchangeRateFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filterProperty() 0 18 2
A getDescription() 0 12 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\ApiBundle\Filters;
15
16
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
17
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
18
use Doctrine\ORM\QueryBuilder;
19
use Webmozart\Assert\Assert;
20
21
final class ExchangeRateFilter extends AbstractContextAwareFilter
22
{
23
    protected function filterProperty(
24
        string $property,
25
        $value,
26
        QueryBuilder $queryBuilder,
27
        QueryNameGeneratorInterface $queryNameGenerator,
28
        string $resourceClass,
29
        string $operationName = null
30
    ) {
31
        if ($property === 'currencyCode') {
32
            $queryBuilder
33
                ->innerJoin('o.sourceCurrency', 'sourceCurrency')
34
                ->innerJoin('o.targetCurrency', 'targetCurrency')
35
                ->where('sourceCurrency.code LIKE CONCAT(\'%\', :code, \'%\')')
36
                ->orWhere('targetCurrency.code LIKE CONCAT(\'%\', :code, \'%\')')
37
                ->setParameter('code', $value)
38
            ;
39
        }
40
    }
41
42
    public function getDescription(string $resourceClass): array
43
    {
44
        $description = [];
45
46
        $description['currencyCode'] = [
47
            'type' => 'string',
48
            'required' => false,
49
            'property' => 'currencyCode',
50
        ];
51
52
        return $description;
53
    }
54
}
55