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

ExchangeRateFilter::filterProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.6666
cc 2
nc 2
nop 6
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