ObjectStorage::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 12
cp 0
rs 9.8333
c 0
b 0
f 0
cc 4
nc 3
nop 2
crap 20
1
<?php
2
3
namespace Mathielen\ImportEngine\Storage;
4
5
use Mathielen\DataImport\Writer\ObjectWriter;
6
use Mathielen\ImportEngine\Storage\Parser\JmsMetadataParser;
7
use Mathielen\DataImport\Writer\ObjectWriter\ObjectFactoryInterface;
8
use Mathielen\DataImport\Writer\ObjectWriter\DefaultObjectFactory;
9
10
class ObjectStorage extends \SplObjectStorage implements StorageInterface
11
{
12
    /**
13
     * @var ObjectFactoryInterface
14
     */
15
    private $objectFactory;
16
17
    /**
18
     * @var JmsMetadataParser
19
     */
20
    private $metadataParser;
21
22 View Code Duplication
    public function __construct($classOrObjectFactory, JmsMetadataParser $metadataParser)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
23
    {
24
        if (is_object($classOrObjectFactory) && $classOrObjectFactory instanceof ObjectFactoryInterface) {
25
            $objectFactory = $classOrObjectFactory;
26
        } elseif (is_string($classOrObjectFactory)) {
27
            $objectFactory = new DefaultObjectFactory($classOrObjectFactory);
28
        } else {
29
            throw new \InvalidArgumentException('classOrObjectFactory must be of type string or ObjectFactoryInterface');
30
        }
31
32
        $this->objectFactory = $objectFactory;
33
        $this->metadataParser = $metadataParser;
34
    }
35
36
    public function getFields()
37
    {
38
        $fields = $this->metadataParser->parse(array('class' => $this->objectFactory->getClassname(), 'groups' => array()));
0 ignored issues
show
Bug introduced by
The method getClassname() does not seem to exist on object<Mathielen\DataImp...ObjectFactoryInterface>.

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...
39
40
        return $fields;
41
    }
42
43
    /**
44
     * (non-PHPdoc).
45
     *
46
     * @see \Mathielen\ImportEngine\Source\SourceInterface::reader()
47
     */
48
    public function reader()
49
    {
50
        //@TODO implement me
51
    }
52
53
    /**
54
     * (non-PHPdoc).
55
     *
56
     * @see \Mathielen\ImportEngine\Source\StorageInterface::writer()
57
     */
58
    public function writer()
59
    {
60
        $writer = new ObjectWriter($this->objectFactory);
0 ignored issues
show
Documentation introduced by
$this->objectFactory is of type object<Mathielen\DataImp...ObjectFactoryInterface>, but the function expects a object<SplObjectStorage>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
62
        $storage = $this;
63
        $writer->setObjectHandler(function ($object) use ($storage) {
0 ignored issues
show
Bug introduced by
The method setObjectHandler() does not seem to exist on object<Mathielen\DataImport\Writer\ObjectWriter>.

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...
64
            $storage->attach($object);
65
        });
66
67
        return $writer;
68
    }
69
70
    /**
71
     * (non-PHPdoc).
72
     *
73
     * @see \Mathielen\ImportEngine\Source\SourceInterface::info()
74
     */
75
    public function info()
76
    {
77
        return new StorageInfo(array(
78
        ));
79
    }
80
}
81