Completed
Pull Request — develop (#251)
by
unknown
07:31
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
 * @author fedys
20
 * @since 0.26
21
 */
22
class DeleteRemovedAttachmentsSubscriber implements EventSubscriber
23
{
24
    /**
25
     * @see \Doctrine\Common\EventSubscriber::getSubscribedEvents()
26
     */
27
    public function getSubscribedEvents()
28
    {
29
        return array('postRemoveEntity');
30
    }
31
    
32
    /**
33
     * Removes attachments
34
     *
35
     * @param LifecycleEventArgs $eventArgs
36
     */
37
    public function postRemoveEntity(LifecycleEventArgs $eventArgs)
38
    {
39
        $file = $eventArgs->getDocument();
40
        if (!$file instanceof Attachment) {
41
            return;
42
        }
43
        
44
        $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...
45
        $dm = $eventArgs->getDocumentManager();
46
        $dm->createQueryBuilder('Cv\Entity\Cv')
47
           ->update()->multiple(true)
48
           ->field('attachments')->equals($fileId)->pull($fileId)
49
           ->getQuery()->execute();
50
    }
51
}
52