Completed
Push — master ( 1af4f5...caaac4 )
by Andreas
03:43
created

objectmanager   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 229
Duplicated Lines 21.4 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 94.63%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
dl 49
loc 229
ccs 141
cts 149
cp 0.9463
rs 10
c 5
b 0
f 0
wmc 30
lcom 1
cbo 9

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 5 20 4
A update() 0 14 1
A copy_associations() 0 6 2
B kill_potential_proxies() 0 20 5
A delete() 5 23 2
A undelete() 0 9 1
A purge() 0 18 2
A approve() 13 13 1
A unapprove() 13 13 1
A lock() 13 13 1
A unlock() 0 10 1
A new_instance() 0 17 3
B copy_metadata() 0 22 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
4
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
6
 */
7
8
namespace midgard\portable\storage;
9
10
use midgard\portable\api\dbobject;
11
use midgard\portable\api\error\exception;
12
use midgard\portable\storage\metadata\entity;
13
use Doctrine\ORM\EntityManager;
14
use Doctrine\ORM\Proxy\Proxy;
15
use Doctrine\ORM\UnitOfWork;
16
use Doctrine\Common\Util\ClassUtils;
17
use midgard_datetime;
18
19
class objectmanager
20
{
21
    private $em;
22
23 102
    public function __construct(EntityManager $em)
0 ignored issues
show
Bug introduced by
You have injected the EntityManager via parameter $em. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.

The EntityManager might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:

function someFunction(ManagerRegistry $registry) {
    $em = $registry->getManager();
    $em->getConnection()->beginTransaction();
    try {
        // Do something.
        $em->getConnection()->commit();
    } catch (\Exception $ex) {
        $em->getConnection()->rollback();
        $em->close();

        throw $ex;
    }
}

If that code throws an exception and the EntityManager is closed. Any other code which depends on the same instance of the EntityManager during this request will fail.

On the other hand, if you instead inject the ManagerRegistry, the getManager() method guarantees that you will always get a usable manager instance.

Loading history...
24
    {
25 102
        $this->em = $em;
26 102
    }
27
28 102
    public function create(dbobject $entity)
29
    {
30 102
        foreach ($this->em->getClassMetadata(get_class($entity))->getAssociationNames() as $name) {
31 89
            if (!empty($entity->$name)) {
32
                //This makes sure that we don't have stale references
33 28
                $entity->$name = $entity->$name;
34 28
            }
35 102
        }
36
37
        //workaround for possible oid collisions in UnitOfWork
38
        //see http://www.doctrine-project.org/jira/browse/DDC-2785
39 102 View Code Duplication
        if ($this->em->getUnitOfWork()->getEntityState($entity) != UnitOfWork::STATE_NEW) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
40
            connection::log()->warning('oid collision during create detected, detaching ' . spl_object_hash($entity));
41
            $this->em->detach($entity);
42
        }
43
44 102
        $this->em->persist($entity);
45 102
        $this->em->flush($entity);
46 102
        $this->em->detach($entity);
47 102
    }
48
49 14
    public function update(dbobject $entity)
50
    {
51
        // if entities are loaded by querybuilder, they are managed at this point already,
52
        // which can in very rare (and very unreproducable) circumstances lead to the update
53
        // getting lost silently (because originalEntityData somehow is empty), so we detach
54
        // before doing anything else
55 14
        $this->em->detach($entity);
56 14
        $merged = $this->em->merge($entity);
57 14
        $this->copy_associations($entity, $merged);
58 14
        $this->em->persist($merged);
59 14
        $this->em->flush($merged);
60 14
        $this->em->detach($merged);
61 14
        $this->copy_metadata($merged, $entity);
62 14
    }
63
64
    /**
65
     * This is basically a workaround for some quirks when merging detached entities with changed associations
66
     *
67
     * @todo: This may or may not be a bug in Doctrine
68
     */
69 14
    private function copy_associations($source, $target)
70
    {
71 14
        foreach ($this->em->getClassMetadata(get_class($source))->getAssociationNames() as $name) {
72 12
            $target->$name = $source->$name;
73 14
        }
74 14
    }
75
76 26
    private function kill_potential_proxies($entity)
77
    {
78 26
        $classname = ClassUtils::getRealClass(get_class($entity));
79 26
        $cm = $this->em->getClassMetadata($classname);
80 26
        $changed_associations = $entity->__get_changed_associations();
81
82 26
        foreach ($cm->getAssociationNames() as $name) {
83 23
            if ($entity->$name === 0) {
84
                //This is necessary to kill potential proxy objects pointing to purged entities
85 20
                $entity->$name = 0;
86 23
            } elseif (!array_key_exists($name, $changed_associations)) {
87 10
                $value = $cm->getReflectionProperty($name)->getValue($entity);
88 10
                if ($value instanceof Proxy) {
89
                    //This makes sure that the associated entity doesn't end up in the changeset calculation
90 10
                    $value->__isInitialized__ = false;
0 ignored issues
show
Bug introduced by
Accessing __isInitialized__ on the interface Doctrine\ORM\Proxy\Proxy suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
91 10
                    continue;
92
                }
93
            }
94 26
        }
95 26
    }
96
97 26
    public function delete(dbobject $entity)
98
    {
99
        //we might deal with a proxy here, so we translate the classname
100 26
        $classname = ClassUtils::getRealClass(get_class($entity));
101 26
        $copy = new $classname($entity->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<midgard\portable\api\dbobject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
102
103
        //workaround for possible oid collisions in UnitOfWork
104
        //see http://www.doctrine-project.org/jira/browse/DDC-2785
105 26 View Code Duplication
        if ($this->em->getUnitOfWork()->getEntityState($copy) != UnitOfWork::STATE_DETACHED) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
106
            connection::log()->warning('oid collision during delete detected, detaching ' . spl_object_hash($copy));
107
            $this->em->detach($copy);
108
        }
109
110 26
        $copy = $this->em->merge($copy);
111 26
        $this->kill_potential_proxies($copy);
112 26
        $copy->metadata_deleted = true;
113
114 26
        $this->em->persist($copy);
115 26
        $this->em->flush($copy);
116 26
        $this->em->detach($copy);
117 26
        $this->em->detach($entity);
118 26
        $this->copy_metadata($copy, $entity, 'delete');
119 26
    }
120
121 3
    public function undelete(dbobject $entity)
122
    {
123 3
        $entity->metadata_deleted = false;
0 ignored issues
show
Documentation introduced by
The property metadata_deleted does not exist on object<midgard\portable\api\dbobject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
124 3
        $this->kill_potential_proxies($entity);
125
126 3
        $this->em->persist($entity);
127 3
        $this->em->flush($entity);
128 3
        $this->em->detach($entity);
129 3
    }
130
131 17
    public function purge(dbobject $entity)
132
    {
133 17
        $this->em->getFilters()->disable('softdelete');
134
        try {
135 17
            $entity = $this->em->merge($entity);
136
            // If we don't refresh here, Doctrine might try to update before deleting and
137
            // throw exceptions about new entities being found (most likely stale association proxies)
138
            // @todo: In Doctrine 2.5, this behavior should be removed, so we may be able to remove this workaround
139 17
            $this->em->refresh($entity);
140 17
        } catch (\Exception $e) {
141 1
            $this->em->getFilters()->enable('softdelete');
142 1
            throw $e;
143
        }
144 17
        $this->em->getFilters()->enable('softdelete');
145 17
        $this->em->remove($entity);
146 17
        $this->em->flush($entity);
147 17
        $this->em->detach($entity);
148 17
    }
149
150 2 View Code Duplication
    public function approve(dbobject $entity)
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...
151
    {
152 2
        $user = connection::get_user();
153 2
        $ref = $this->em->getReference(get_class($entity), $entity->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<midgard\portable\api\dbobject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
154 2
        $ref->metadata_isapproved = true;
155 2
        $ref->metadata_approver = $user->person;
156 2
        $ref->metadata_approved = new midgard_datetime;
157
158 2
        $this->em->persist($ref);
159 2
        $this->em->flush($ref);
160 2
        $this->em->detach($entity);
161 2
        $this->copy_metadata($ref, $entity, 'approve');
162 2
    }
163
164 1 View Code Duplication
    public function unapprove(dbobject $entity)
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...
165
    {
166 1
        $user = connection::get_user();
167 1
        $ref = $this->em->getReference(get_class($entity), $entity->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<midgard\portable\api\dbobject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
168 1
        $ref->metadata_isapproved = false;
169 1
        $ref->metadata_approver = $user->person;
170 1
        $ref->metadata_approved = new midgard_datetime;
171
172 1
        $this->em->persist($ref);
173 1
        $this->em->flush($ref);
174 1
        $this->em->detach($entity);
175 1
        $this->copy_metadata($ref, $entity, 'approve');
176 1
    }
177
178 2 View Code Duplication
    public function lock(dbobject $entity)
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...
179
    {
180 2
        $user = connection::get_user();
181 2
        $ref = $this->em->getReference(get_class($entity), $entity->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<midgard\portable\api\dbobject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
182 2
        $ref->metadata_islocked = true;
183 2
        $ref->metadata_locker = $user->person;
184 2
        $ref->metadata_locked = new midgard_datetime;
185
186 2
        $this->em->persist($ref);
187 2
        $this->em->flush($ref);
188 2
        $this->em->detach($entity);
189 2
        $this->copy_metadata($ref, $entity, 'lock');
190 2
    }
191
192 1
    public function unlock(dbobject $entity)
193
    {
194 1
        $ref = $this->em->getReference(get_class($entity), $entity->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<midgard\portable\api\dbobject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
195 1
        $ref->metadata_islocked = false;
196
197 1
        $this->em->persist($ref);
198 1
        $this->em->flush($ref);
199 1
        $this->em->detach($entity);
200 1
        $this->copy_metadata($ref, $entity, 'lock');
201 1
    }
202
203
    /**
204
     * @param string $classname
205
     * @return dbobject
206
     */
207 102
    public function new_instance($classname)
208
    {
209
        //workaround for possible oid collisions in UnitOfWork
210
        //see http://www.doctrine-project.org/jira/browse/DDC-2785
211 102
        $counter = 0;
212 102
        $candidates = array();
213
        do {
214 102
            $entity = new $classname;
215 102
            if ($counter++ > 100) {
216
                throw new exception('Failed to create fresh ' . $classname . ' instance (all tried oids are already known to UoW)');
217
            }
218
            //we keep the entity in memory to make sure we get a different oid during the next iteration
219 102
            $candidates[] = $entity;
220 102
        } while ($this->em->getUnitOfWork()->getEntityState($entity) !== UnitOfWork::STATE_NEW);
221
        // TODO: Calling $em->getUnitOfWork()->isInIdentityMap($entity) returns false in the same situation. Why?
222 102
        return $entity;
223
    }
224
225 38
    private function copy_metadata($source, $target, $action = 'update')
226
    {
227 38
        if (!$source instanceof entity) {
228 1
            return;
229
        }
230
231 37
        $target->metadata_revised = $source->metadata_revised;
0 ignored issues
show
Bug introduced by
Accessing metadata_revised on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
232 37
        $target->metadata_revisor = $source->metadata_revisor;
0 ignored issues
show
Bug introduced by
Accessing metadata_revisor on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
233 37
        $target->metadata_revision = $source->metadata_revision;
0 ignored issues
show
Bug introduced by
Accessing metadata_revision on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
234
235 37
        if ($action == 'lock') {
236 2
            $target->metadata_islocked = $source->metadata_islocked;
0 ignored issues
show
Bug introduced by
Accessing metadata_islocked on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
237 2
            $target->metadata_locker = $source->metadata_locker;
0 ignored issues
show
Bug introduced by
Accessing metadata_locker on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
238 2
            $target->metadata_locked = $source->metadata_locked;
0 ignored issues
show
Bug introduced by
Accessing metadata_locked on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
239 37
        } elseif ($action == 'approve') {
240 2
            $target->metadata_isapproved = $source->metadata_isapproved;
0 ignored issues
show
Bug introduced by
Accessing metadata_isapproved on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
241 2
            $target->metadata_approver = $source->metadata_approver;
0 ignored issues
show
Bug introduced by
Accessing metadata_approver on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
242 2
            $target->metadata_approved = $source->metadata_approved;
0 ignored issues
show
Bug introduced by
Accessing metadata_approved on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
243 35
        } elseif ($action == 'delete') {
244 26
            $target->metadata_deleted = $source->metadata_deleted;
0 ignored issues
show
Bug introduced by
Accessing metadata_deleted on the interface midgard\portable\storage\metadata\entity suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
245 26
        }
246 37
    }
247
}
248