1 | <?php |
||
10 | class DoctrineStorage implements StorageInterface |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @var EntityManagerInterface |
||
15 | */ |
||
16 | private $entityManager; |
||
17 | |||
18 | /** |
||
19 | * @var Query |
||
20 | */ |
||
21 | private $query; |
||
22 | |||
23 | private $entityName; |
||
24 | |||
25 | 1 | public function __construct(EntityManagerInterface $entityManager, $entityName=null, Query $query=null) |
|
26 | { |
||
27 | 1 | $this->entityManager = $entityManager; |
|
28 | 1 | $this->entityName = $entityName; |
|
29 | |||
30 | 1 | if (is_null($query) && is_string($entityName) && class_exists($entityName)) { |
|
31 | 1 | $query = $this->entityManager->createQueryBuilder() |
|
32 | 1 | ->select('o') |
|
33 | 1 | ->from($this->entityName, 'o') |
|
34 | 1 | ->getQuery(); |
|
35 | } |
||
36 | |||
37 | 1 | $this->query = $query; |
|
38 | 1 | } |
|
39 | |||
40 | /** |
||
41 | * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::writer() |
||
42 | */ |
||
43 | 1 | public function writer() |
|
44 | { |
||
45 | 1 | if (empty($this->entityName)) { |
|
46 | throw new InvalidConfigurationException("Can only use doctrine for writing if entityName is given."); |
||
47 | } |
||
48 | |||
49 | 1 | $writer = new DoctrineWriter($this->entityManager, $this->entityName); |
|
|
|||
50 | 1 | $writer->setTruncate(false); |
|
51 | |||
52 | 1 | return $writer; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::info() |
||
57 | */ |
||
58 | 1 | public function info() |
|
59 | { |
||
60 | 1 | $count = count($this->reader()); |
|
61 | |||
62 | 1 | return new StorageInfo(array( |
|
63 | 1 | 'name' => $this->query->getDQL(), |
|
64 | 1 | 'type' => 'DQL Query', |
|
65 | 1 | 'count' => $count |
|
66 | )); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::reader() |
||
71 | */ |
||
72 | 1 | public function reader() |
|
76 | |||
77 | /** |
||
78 | * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::getFields() |
||
79 | */ |
||
80 | public function getFields() |
||
84 | } |
||
85 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.