FileToObject   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getObjectFromFilename() 0 13 2
1
<?php
2
/**
3
 * This file is part of the IrishDan\ResponsiveImageBundle package.
4
 *
5
 * (c) Daniel Byrne <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source
8
 * code.
9
 */
10
11
namespace IrishDan\ResponsiveImageBundle\File;
12
13
use Doctrine\ORM\EntityManager;
14
use Doctrine\ORM\EntityManagerInterface;
15
use IrishDan\ResponsiveImageBundle\ImageEntityNameResolver;
16
use IrishDan\ResponsiveImageBundle\ResponsiveImageRepositoryInterface;
17
18
/**
19
 * Class FileToObject
20
 *
21
 * @package ResponsiveImageBundle
22
 */
23
class FileToObject
24
{
25
    /**
26
     * @var EntityManagerInterface
27
     */
28
    private $manager;
29
    /**
30
     * @var string
31
     */
32
    private $entityClassName;
33
34
    public function __construct(EntityManagerInterface $manager, ImageEntityNameResolver $nameResolver)
35
    {
36
        $this->manager = $manager;
37
38
        $entityClassName       = $nameResolver->getClassName();
39
        $this->entityClassName = $entityClassName;
40
    }
41
42
    /**
43
     * Fetches and returns the image object based on the file name.
44
     *
45
     * @param $filename
46
     *
47
     * @return mixed
48
     * @internal param $entityClassName
49
     */
50
    public function getObjectFromFilename($filename)
51
    {
52
        /** @var ResponsiveImageRepositoryInterface $repository */
53
        $repository = $this->manager->getRepository($this->entityClassName);
54
55
        if ($repository instanceof ResponsiveImageRepositoryInterface) {
56
            $fileObject = $repository->findImageFromFilename($filename);
57
58
            return $fileObject;
59
        }
60
61
        return null;
62
    }
63
}