CurrencyConverterHandler::serializeToJson()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Rafał Muszyński <[email protected]>
5
 * @copyright 2015 Sourcefabric z.ú.
6
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
7
 */
8
namespace Newscoop\PaywallBundle\Serializer;
9
10
use JMS\Serializer\JsonSerializationVisitor;
11
use Newscoop\PaywallBundle\Currency\Context\CurrencyContextInterface;
12
use Newscoop\PaywallBundle\Entity\PriceableInterface;
13
use Sylius\Component\Currency\Converter\CurrencyConverterInterface;
14
15
/**
16
 * Currency converter handler. Handles currency conversion.
17
 */
18
class CurrencyConverterHandler
19
{
20
    private $converter;
21
    private $context;
22
23
    /**
24
     * Construct.
25
     *
26
     * @param CurrencyConverterInterface $converter
27
     * @param CurrencyContextInterface   $context
28
     */
29
    public function __construct(CurrencyConverterInterface $converter, CurrencyContextInterface $context)
30
    {
31
        $this->converter = $converter;
32
        $this->context = $context;
33
    }
34
35
    public function serializeToJson(JsonSerializationVisitor $visitor, PriceableInterface $subscription)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
        if (!$subscription) {
38
            return;
39
        }
40
41
        return $this->converter->convert($subscription->getPrice(), $this->context->getCurrency());
42
    }
43
}
44