CurrencyManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
namespace GGGGino\SkuskuCartBundle\Service;
4
5
use Doctrine\ORM\EntityManager;
6
use GGGGino\SkuskuCartBundle\Exception\CurrencyNotFoundException;
7
use GGGGino\SkuskuCartBundle\Model\SkuskuCart;
8
use GGGGino\SkuskuCartBundle\Model\SkuskuCartProduct;
9
use GGGGino\SkuskuCartBundle\Model\SkuskuCurrencyInterface;
10
use GGGGino\SkuskuCartBundle\Model\SkuskuCustomerInterface;
11
use GGGGino\SkuskuCartBundle\Model\SkuskuProductInterface;
12
use Symfony\Component\Form\Form;
13
use Symfony\Component\Form\FormInterface;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\RequestStack;
16
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
17
18
class CurrencyManager implements CurrencyManagerInterface
19
{
20
    /**
21
     * @var EntityManager
22
     */
23
    private $em;
24
25
    /**
26
     * @var TokenStorage
27
     */
28
    private $tokenStorage;
29
30
    /**
31
     * @var RequestStack
32
     */
33
    private $requestStack;
34
35
    /**
36
     * CartExtension constructor.
37
     * @param EntityManager $em
38
     * @param TokenStorage $tokenStorage
39
     * @param RequestStack $requestStack
40
     */
41
    public function __construct(EntityManager $em, TokenStorage $tokenStorage, RequestStack $requestStack)
42
    {
43
        $this->em = $em;
44
        $this->tokenStorage = $tokenStorage;
45
        $this->requestStack = $requestStack;
46
    }
47
48
    /**
49
     * @return SkuskuCurrencyInterface[]
50
     */
51
    public function getActiveCurrencies()
52
    {
53
        return $this->em->getRepository(SkuskuCurrencyInterface::class)->findAll();
54
    }
55
56
    /**
57
     * @return SkuskuCurrencyInterface
58
     * @throws CurrencyNotFoundException
59
     */
60
    public function getCurrentCurrency()
61
    {
62
        /** @var string $currencyIdentifier */
63
        $currencyIdentifier = $this->requestStack->getCurrentRequest()->attributes->get('skusku_cu');
64
65
        /** @var SkuskuCurrencyInterface $locale */
66
        $locale = $this->em->getRepository(SkuskuCurrencyInterface::class)->findOneByIsoCode($currencyIdentifier);
0 ignored issues
show
Bug introduced by
The method findOneByIsoCode() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findOneBy()? ( Ignorable by Annotation )

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

66
        $locale = $this->em->getRepository(SkuskuCurrencyInterface::class)->/** @scrutinizer ignore-call */ findOneByIsoCode($currencyIdentifier);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68
        if( !$locale ) {
0 ignored issues
show
introduced by
$locale is of type GGGGino\SkuskuCartBundle...SkuskuCurrencyInterface, thus it always evaluated to true.
Loading history...
69
            throw new CurrencyNotFoundException();
70
        }
71
72
        return $locale;
73
    }
74
}