Completed
Push — master ( 98f65f...94fc25 )
by Paweł
21:33 queued 10:44
created

ApplicationResourceLocator::getApplicationPaths()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 4
Ratio 40 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Core Bundle.
5
 *
6
 * Copyright 2016 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 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\CoreBundle\Locator;
16
17
use SWP\Bundle\CoreBundle\Detection\DeviceDetectionInterface;
18
use Sylius\Bundle\ThemeBundle\Locator\ResourceLocatorInterface;
19
use Sylius\Bundle\ThemeBundle\Locator\ResourceNotFoundException;
20
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
21
use Symfony\Component\Filesystem\Filesystem;
22
23
class ApplicationResourceLocator implements ResourceLocatorInterface
24
{
25
    /**
26
     * @var Filesystem
27
     */
28
    private $filesystem;
29
30
    /**
31
     * @var DeviceDetectionInterface
32
     */
33
    private $deviceDetection;
34
35
    /**
36
     * @param Filesystem $filesystem
37
     */
38 101
    public function __construct(Filesystem $filesystem, DeviceDetectionInterface $deviceDetection)
39
    {
40 101
        $this->filesystem = $filesystem;
41 101
        $this->deviceDetection = $deviceDetection;
42 101
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 12
    public function locateResource(string $resourceName, ThemeInterface $theme): string
48
    {
49 12 View Code Duplication
        if (null !== $this->deviceDetection->getType()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50 12
            $path = sprintf('%s/%s/%s', $theme->getPath(), $this->deviceDetection->getType(), $resourceName);
51 12
            if ($this->filesystem->exists($path)) {
52 12
                return $path;
53
            }
54
        }
55
56 1
        $path = sprintf('%s/%s', $theme->getPath(), $resourceName);
57
        if (!$this->filesystem->exists($path)) {
58
            throw new ResourceNotFoundException($resourceName, $theme);
59
        }
60
61
        return $path;
62
    }
63
}
64