Completed
Pull Request — master (#10)
by dan
09:38
created

FileToObject   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

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 EntityManager
27
     */
28
    private $manager;
29
    private $entityClassName;
30
31
    public function __construct(EntityManagerInterface $manager, ImageEntityNameResolver $nameResolver)
32
    {
33
        $this->manager = $manager;
0 ignored issues
show
Documentation Bug introduced by
$manager is of type object<Doctrine\ORM\EntityManagerInterface>, but the property $manager was declared to be of type object<Doctrine\ORM\EntityManager>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
34
35
        $entityClassName       = $nameResolver->getClassName();
36
        $this->entityClassName = $entityClassName;
37
    }
38
39
    /**
40
     * Fetches and returns the image object based on the file name.
41
     *
42
     * @param $filename
43
     *
44
     * @return mixed
45
     * @internal param $entityClassName
46
     */
47
    public function getObjectFromFilename($filename)
48
    {
49
        /** @var ResponsiveImageRepositoryInterface $repository */
50
        $repository = $this->manager->getRepository($this->entityClassName);
51
52
        if ($repository instanceof ResponsiveImageRepositoryInterface) {
53
            $fileObject = $repository->findImageFromFilename($filename);
54
55
            return $fileObject;
56
        }
57
58
        return null;
59
    }
60
}