GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 926faa...eb8df6 )
by Florian
04:05
created

DoctrineListener::postPersist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Stinger Enity Search package.
5
 *
6
 * (c) Oliver Kotte <[email protected]>
7
 * (c) Florian Meyer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
namespace StingerSoft\EntitySearchBundle\Services;
13
14
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
15
use Doctrine\Common\Persistence\ObjectManager;
16
use Doctrine\Common\EventSubscriber;
17
18
class DoctrineListener implements EventSubscriber {
19
20
	/**
21
	 *
22
	 * @var EntityHandler
23
	 */
24
	protected $entityHandler;
25
	
26
	/**
27
	 *
28
	 * @var SearchService
29
	 */
30
	protected $searchService;
31
32
	public function getSubscribedEvents() {
33
		return array(
34
			'postPersist',
35
			'postUpdate',
36
			'preRemove' 
37
		);
38
	}
39
40
	/**
41
	 * Constructor
42
	 *
43
	 * @param SearchService $searchService        	
44
	 */
45
	public function __construct(EntityHandler $entityHandler, SearchService $searchService) {
46
		$this->entityHandler = $entityHandler;
47
		$this->searchService = $searchService;
48
	}
49
50
	/**
51
	 * Index the entity after it is persisted for the first time
52
	 *
53
	 * @param LifecycleEventArgs $args        	
54
	 */
55
	public function postPersist(LifecycleEventArgs $args) {
56
		$this->updateEntity($args->getObject(), $args->getObjectManager());
57
	}
58
59
	/**
60
	 * Removes the entity from the index when it marked for deletion
61
	 *
62
	 * @param LifecycleEventArgs $args        	
63
	 */
64
	public function preRemove(LifecycleEventArgs $args) {
65
		$this->removeEntity($args->getObject(), $args->getObjectManager());
66
	}
67
68
	/**
69
	 * Updates the entity in the index after it is updated
70
	 *
71
	 * @param LifecycleEventArgs $args        	
72
	 */
73
	public function postUpdate(LifecycleEventArgs $args) {
74
		$this->updateEntity($args->getObject(), $args->getObjectManager());
75
	}
76
77
	/**
78
	 *
79
	 * @return EntityHandler
80
	 */
81
	protected function getEntityHandler() {
82
		return $this->entityHandler;
83
	}
84
	
85
	/**
86
	 *
87
	 * @return SearchService
88
	 */
89
	protected function getSearchService(ObjectManager $manager) {
90
		$this->searchService->setObjectManager($manager);
91
		return $this->searchService;
92
	}
93
94
	/**
95
	 *
96
	 * @param object $entity        	
97
	 */
98
	protected function updateEntity($entity, ObjectManager $manager) {
99
		$document = $this->getEntityHandler()->createDocument($manager, $entity);
100
		if($document !== false) {
101
			$this->getSearchService($manager)->saveDocument($document);
102
		}
103
	}
104
105
	/**
106
	 *
107
	 * @param object $entity        	
108
	 */
109
	protected function removeEntity($entity, ObjectManager $manager) {
110
		$document = $this->getEntityHandler()->createDocument($manager, $entity);
111
		if($document !== false) {
112
			$this->getSearchService($manager)->removeDocument($document);
113
		}
114
	}
115
}