Completed
Push — master ( 77f195...b72026 )
by JHONATAN
02:28
created

TransferManager::detach()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Vox\Webservice;
4
5
use Doctrine\Common\Persistence\ObjectRepository;
6
use Metadata\MetadataFactoryInterface;
7
use Vox\Webservice\Metadata\TransferMetadata;
8
use Vox\Webservice\Proxy\ProxyFactory;
9
use Vox\Webservice\Proxy\ProxyFactoryInterface;
10
11
class TransferManager implements TransferManagerInterface
12
{
13
    /**
14
     * @var UnityOfWorkInterface
15
     */
16
    private $unityOfWork;
17
    
18
    /**
19
     * @var MetadataFactoryInterface
20
     */
21
    private $metadataFactory;
22
    
23
    /**
24
     * @var WebserviceClientInterface
25
     */
26
    private $webserviceClient;
27
    
28
    /**
29
     * @var TransferPersisterInterface
30
     */
31
    private $transferPersister;
32
    
33
    /**
34
     * @var ProxyFactoryInterface
35
     */
36
    private $proxyFactory;
37
    
38 13
    public function __construct(
39
        MetadataFactoryInterface $metadataFactory,
40
        WebserviceClientInterface $webserviceClient,
41
        ProxyFactoryInterface $proxyFactory = null
42
    ) {
43 13
        $this->metadataFactory  = $metadataFactory;
44 13
        $this->webserviceClient = $webserviceClient;
45 13
        $this->proxyFactory     = $proxyFactory ?? new ProxyFactory();
46
        
47 13
        $this->clear();
48 13
    }
49
    
50
    /**
51
     * @todo injection of these objects
52
     * 
53
     * @param type $objectName
0 ignored issues
show
Bug introduced by
The type Vox\Webservice\type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
54
     */
55 13
    public function clear($objectName = null)
56
    {
57 13
        $this->unityOfWork       = new UnityOfWork($this->metadataFactory);
58 13
        $this->transferPersister = new TransferPersister(
59 13
            $this->metadataFactory,
60 13
            $this->unityOfWork,
61 13
            $this->webserviceClient
62
        );
63 13
    }
64
65
    public function contains($object): bool
66
    {
67
        return $this->unityOfWork->contains($object);
68
    }
69
70
    public function detach($object)
71
    {
72
        $this->unityOfWork->detach($object);
73
    }
74
75 3
    public function find($className, $id)
76
    {
77 3
        return $this->getRepository($className)->find($id);
78
    }
79
80 6
    public function flush()
81
    {
82 6
        foreach ($this->unityOfWork as $transfer) {
83 6
            $this->transferPersister->save($transfer);
84
        }
85 6
    }
86
87 12
    public function getClassMetadata($className): TransferMetadata
88
    {
89 12
        if(is_object($className)) {
90
            $className = get_class($className);
91
        }
92
        
93 12
        return $this->metadataFactory->getMetadataForClass($className);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->metadataFa...ataForClass($className) returns the type null|Metadata\ClassHierarchyMetadata which is incompatible with the type-hinted return Vox\Webservice\Metadata\TransferMetadata.
Loading history...
94
    }
95
96
    public function getMetadataFactory(): MetadataFactoryInterface
97
    {
98
        return $this->metadataFactory;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->metadataFactory returns the type Metadata\MetadataFactoryInterface which is incompatible with the return type mandated by Doctrine\Common\Persiste...r::getMetadataFactory() of Doctrine\Common\Persiste...ng\ClassMetadataFactory.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
99
    }
100
101 7
    public function getRepository($className): ObjectRepository
102
    {
103 7
        return new TransferRepository(
104 7
            $className,
105 7
            $this->webserviceClient,
106 7
            $this->unityOfWork,
107 7
            $this,
108 7
            $this->proxyFactory
109
        );
110
    }
111
112
    public function initializeObject($obj)
113
    {
114
        
115
    }
116
117
    public function merge($object)
118
    {
119
        
120
    }
121
122 2
    public function persist($object)
123
    {
124 2
        $this->unityOfWork->attach($object);
125 2
    }
126
127
    public function refresh($object)
128
    {
129
        
130
    }
131
132 1
    public function remove($object)
133
    {
134 1
        $this->unityOfWork->remove($object);
135 1
    }
136
}
137