Completed
Pull Request — develop (#251)
by
unknown
14:19 queued 06:05
created

postRemoveEntity()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
namespace Cv\Repository\Event;
11
12
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;
13
use Doctrine\Common\EventSubscriber;
14
use Cv\Entity\Attachment;
15
16
/**
17
 * Subscriber for deleting CV attachment references
18
 */
19
class DeleteRemovedAttachmentsSubscriber implements EventSubscriber
20
{
21
    /**
22
     * @see \Doctrine\Common\EventSubscriber::getSubscribedEvents()
23
     */
24
    public function getSubscribedEvents()
25
    {
26
        return array('postRemoveEntity');
27
    }
28
    
29
    /**
30
     * Removes attachments
31
     *
32
     * @param LifecycleEventArgs $eventArgs
33
     */
34
    public function postRemoveEntity(LifecycleEventArgs $eventArgs)
35
    {
36
        $file = $eventArgs->getDocument();
37
        if (!$file instanceof Attachment) {
38
            return;
39
        }
40
        
41
        $fileId = new \MongoId($file->id);
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in Core\Entity\AbstractIdentifiableEntity. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
42
        $dm = $eventArgs->getDocumentManager();
43
        $dm->createQueryBuilder('Cv\Entity\Cv')
44
           ->update()->multiple(true)
45
           ->field('attachments')->equals($fileId)->pull($fileId)
46
           ->getQuery()->execute();
47
    }
48
}
49