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 ( eb8df6...b4be3b )
by Florian
02:55
created

DoctrineListener   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 6
Bugs 1 Features 3
Metric Value
wmc 11
c 6
b 1
f 3
lcom 1
cbo 3
dl 0
loc 98
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 7 1
A __construct() 0 4 1
A postPersist() 0 3 1
A preRemove() 0 3 1
A postUpdate() 0 3 1
A getEntityToDocumentMapper() 0 3 1
A getSearchService() 0 4 1
A updateEntity() 0 6 2
A removeEntity() 0 6 2
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
use StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface;
18
19
class DoctrineListener implements EventSubscriber {
20
21
	/**
22
	 *
23
	 * @var EntityToDocumentMapperInterface
24
	 */
25
	protected $entityToDocumentMapper;
26
	
27
	/**
28
	 *
29
	 * @var SearchService
30
	 */
31
	protected $searchService;
32
33
	public function getSubscribedEvents() {
34
		return array(
35
			'postPersist',
36
			'postUpdate',
37
			'preRemove' 
38
		);
39
	}
40
41
	/**
42
	 * Constructor
43
	 *
44
	 * @param SearchService $searchService        	
45
	 */
46
	public function __construct(EntityToDocumentMapperInterface $entityToDocumentMapper, SearchService $searchService) {
47
		$this->entityToDocumentMapper = $entityToDocumentMapper;
48
		$this->searchService = $searchService;
49
	}
50
51
	/**
52
	 * Index the entity after it is persisted for the first time
53
	 *
54
	 * @param LifecycleEventArgs $args        	
55
	 */
56
	public function postPersist(LifecycleEventArgs $args) {
57
		$this->updateEntity($args->getObject(), $args->getObjectManager());
58
	}
59
60
	/**
61
	 * Removes the entity from the index when it marked for deletion
62
	 *
63
	 * @param LifecycleEventArgs $args        	
64
	 */
65
	public function preRemove(LifecycleEventArgs $args) {
66
		$this->removeEntity($args->getObject(), $args->getObjectManager());
67
	}
68
69
	/**
70
	 * Updates the entity in the index after it is updated
71
	 *
72
	 * @param LifecycleEventArgs $args        	
73
	 */
74
	public function postUpdate(LifecycleEventArgs $args) {
75
		$this->updateEntity($args->getObject(), $args->getObjectManager());
76
	}
77
78
	/**
79
	 *
80
	 * @return EntityToDocumentMapperInterface
81
	 */
82
	protected function getEntityToDocumentMapper() {
83
		return $this->entityToDocumentMapper;
84
	}
85
	
86
	/**
87
	 *
88
	 * @return SearchService
89
	 */
90
	protected function getSearchService(ObjectManager $manager) {
91
		$this->searchService->setObjectManager($manager);
92
		return $this->searchService;
93
	}
94
95
	/**
96
	 *
97
	 * @param object $entity        	
98
	 */
99
	protected function updateEntity($entity, ObjectManager $manager) {
100
		$document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity);
101
		if($document !== false) {
102
			$this->getSearchService($manager)->saveDocument($document);
0 ignored issues
show
Bug introduced by
It seems like $document defined by $this->getEntityToDocume...ment($manager, $entity) on line 100 can also be of type boolean; however, StingerSoft\EntitySearch...Service::saveDocument() does only seem to accept object<StingerSoft\Entit...hBundle\Model\Document>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
103
		}
104
	}
105
106
	/**
107
	 *
108
	 * @param object $entity        	
109
	 */
110
	protected function removeEntity($entity, ObjectManager $manager) {
111
		$document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity);
112
		if($document !== false) {
113
			$this->getSearchService($manager)->removeDocument($document);
0 ignored issues
show
Bug introduced by
It seems like $document defined by $this->getEntityToDocume...ment($manager, $entity) on line 111 can also be of type boolean; however, StingerSoft\EntitySearch...rvice::removeDocument() does only seem to accept object<StingerSoft\Entit...hBundle\Model\Document>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
114
		}
115
	}
116
}