Completed
Pull Request — master (#1)
by
unknown
12:30
created
DependencyInjection/StingerSoftEntitySearchExtension.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 
38 38
 		$container->setParameter('stinger_soft.entity_search.available_facets', $config['facets']);
39 39
 
40
-		$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
40
+		$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
41 41
 		$loader->load('services.yml');
42 42
 		
43 43
 		$entityToDocumentMapperDefinition = $container->getDefinition(EntityToDocumentMapperInterface::class);
Please login to merge, or discard this patch.
DependencyInjection/Compiler/FacetCompilerPass.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
 	 * @param ContainerBuilder $container
17 17
 	 */
18 18
 	public function process(ContainerBuilder $container) {
19
-		if(!$container->hasAlias(SearchService::class)) {
19
+		if (!$container->hasAlias(SearchService::class)) {
20 20
 			return;
21 21
 		}
22 22
 
23 23
 		$serviceId = (string)$container->getAlias(SearchService::class);
24 24
 
25
-		if(!$container->hasDefinition($serviceId)) {
25
+		if (!$container->hasDefinition($serviceId)) {
26 26
 			return;
27 27
 		}
28 28
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 		$servicesMap = array();
32 32
 		// Builds an array with fully-qualified type class names as keys and service IDs as values
33
-		foreach($container->findTaggedServiceIds(FacetServiceInterface::TAG_NAME, true) as $serviceId => $tag) {
33
+		foreach ($container->findTaggedServiceIds(FacetServiceInterface::TAG_NAME, true) as $serviceId => $tag) {
34 34
 			// Add form type service to the service locator
35 35
 			$serviceDefinition = $container->getDefinition($serviceId);
36 36
 			$servicesMap[$serviceDefinition->getClass()] = new Reference($serviceId);
Please login to merge, or discard this patch.
Form/FacetChoiceLoader.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 	public function loadValuesForChoices(array $choices, $value = null): array {
42 42
 		// is called on form creat with $choices containing the preset of the bound entity
43 43
 		$values = array();
44
-		foreach($choices as $key => $choice) {
44
+		foreach ($choices as $key => $choice) {
45 45
 			// we use a DataTransformer, thus only plain values arrive as choices which can be used directly as value
46
-			if(is_callable($value)) {
46
+			if (is_callable($value)) {
47 47
 				$values[$key] = (string)call_user_func($value, $choice, $key);
48 48
 			} else {
49 49
 				$values[$key] = $choice;
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 	public function loadChoicesForValues(array $values, $value = null): array {
88 88
 		// is called on form submit after loadValuesForChoices of form create and loadChoiceList of form view create
89 89
 		$choices = array();
90
-		foreach($values as $key => $val) {
90
+		foreach ($values as $key => $val) {
91 91
 			// we use a DataTransformer, thus only plain values arrive as choices which can be used directly as value
92
-			if(is_callable($value)) {
92
+			if (is_callable($value)) {
93 93
 				$choices[$key] = (string)call_user_func($value, $val, $key);
94 94
 			} else {
95 95
 				$choices[$key] = $val;
Please login to merge, or discard this patch.
Form/FacetType.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,12 +32,12 @@
 block discarded – undo
32 32
 		$builder->resetModelTransformers();
33 33
 		$builder->resetViewTransformers();
34 34
 		
35
-		if($options['multiple']) {
36
-			$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
35
+		if ($options['multiple']) {
36
+			$builder->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) {
37 37
 				$event->stopPropagation();
38 38
 			}, 1);
39 39
 		}
40
-		$builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
40
+		$builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) {
41 41
 			$data = $event->getForm()->getExtraData();
42 42
 			//$event->setData(array_unique(array_merge($data, $event->getData())));
43 43
 			$event->setData($data);
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,6 @@
 block discarded – undo
18 18
 use Symfony\Component\Form\FormEvent;
19 19
 use Symfony\Component\Form\FormEvents;
20 20
 use Symfony\Component\OptionsResolver\OptionsResolver;
21
-use Symfony\Component\HttpKernel\Kernel;
22 21
 
23 22
 class FacetType extends AbstractType {
24 23
 
Please login to merge, or discard this patch.
Services/Mapping/EntityToDocumentMapper.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -48,18 +48,18 @@  discard block
 block discarded – undo
48 48
 	 */
49 49
 	public function __construct(SearchService $searchService, array $mapping = array()) {
50 50
 		$this->searchService = $searchService;
51
-		foreach($mapping as $key => $config) {
52
-			if(!isset($config['mappings'])) {
53
-				throw new \InvalidArgumentException($key . ' has no mapping defined!');
51
+		foreach ($mapping as $key => $config) {
52
+			if (!isset($config['mappings'])) {
53
+				throw new \InvalidArgumentException($key.' has no mapping defined!');
54 54
 			}
55
-			if(!isset($config['persistence'])) {
56
-				throw new \InvalidArgumentException($key . ' has no persistence defined!');
55
+			if (!isset($config['persistence'])) {
56
+				throw new \InvalidArgumentException($key.' has no persistence defined!');
57 57
 			}
58
-			if(!isset($config['persistence']['model'])) {
59
-				throw new \InvalidArgumentException($key . ' has no model defined!');
58
+			if (!isset($config['persistence']['model'])) {
59
+				throw new \InvalidArgumentException($key.' has no model defined!');
60 60
 			}
61 61
 			$map = array();
62
-			foreach($config['mappings'] as $fieldKey => $fieldConfig) {
62
+			foreach ($config['mappings'] as $fieldKey => $fieldConfig) {
63 63
 				$map[$fieldKey] = isset($fieldConfig['propertyPath']) && $fieldConfig['propertyPath'] ? $fieldConfig['propertyPath'] : $fieldKey;
64 64
 			}
65 65
 			
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 	 * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::isIndexable()
75 75
 	 */
76 76
 	public function isIndexable(object $object) : bool {
77
-		if($object instanceof SearchableEntity) {
77
+		if ($object instanceof SearchableEntity) {
78 78
 			return true;
79 79
 		}
80
-		if(count($this->getMapping(get_class($object))) > 0) {
80
+		if (count($this->getMapping(get_class($object))) > 0) {
81 81
 			return true;
82 82
 		}
83 83
 		return false;
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	public function isClassIndexable(string $clazz) : bool {
94 94
 		$reflectionClass = new \ReflectionClass($clazz);
95
-		if(array_key_exists(SearchableEntity::class, $reflectionClass->getInterfaces())) {
95
+		if (array_key_exists(SearchableEntity::class, $reflectionClass->getInterfaces())) {
96 96
 			return true;
97 97
 		}
98
-		if(count($this->getMapping($clazz)) > 0) {
98
+		if (count($this->getMapping($clazz)) > 0) {
99 99
 			return true;
100 100
 		}
101 101
 		return false;
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 	 * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::createDocument()
108 108
 	 */
109 109
 	public function createDocument(ObjectManager $manager, object $object) : ?Document {
110
-		if(!$this->isIndexable($object))
110
+		if (!$this->isIndexable($object))
111 111
 			return null;
112 112
 		$document = $this->searchService->createEmptyDocumentFromEntity($object);
113 113
 		$index = $this->fillDocument($document, $object);
114
-		if($index === false)
114
+		if ($index === false)
115 115
 			return null;
116 116
 		
117 117
 		return $document;
@@ -125,12 +125,12 @@  discard block
 block discarded – undo
125 125
 	 * @return boolean
126 126
 	 */
127 127
 	protected function fillDocument(Document $document, object $object) : bool {
128
-		if($object instanceof SearchableEntity) {
128
+		if ($object instanceof SearchableEntity) {
129 129
 			return $object->indexEntity($document);
130 130
 		}
131 131
 		$mapping = $this->getMapping(\get_class($object));
132 132
 		$accessor = PropertyAccess::createPropertyAccessor();
133
-		foreach($mapping as $fieldName => $propertyPath) {
133
+		foreach ($mapping as $fieldName => $propertyPath) {
134 134
 			$document->addField($fieldName, $accessor->getValue($object, $propertyPath));
135 135
 		}
136 136
 		return true;
@@ -143,15 +143,15 @@  discard block
 block discarded – undo
143 143
 	 * @throws \ReflectionException
144 144
 	 */
145 145
 	protected function getMapping(string $clazz) : array {
146
-		if(isset($this->cachedMapping[$clazz])) {
146
+		if (isset($this->cachedMapping[$clazz])) {
147 147
 			return $this->cachedMapping[$clazz];
148 148
 		}
149 149
 		$ref = new \ReflectionClass($clazz);
150 150
 		
151 151
 		$mapping = array();
152 152
 		
153
-		foreach($this->mapping as $className => $config) {
154
-			if($clazz === $className || $ref->isSubclassOf($className)) {
153
+		foreach ($this->mapping as $className => $config) {
154
+			if ($clazz === $className || $ref->isSubclassOf($className)) {
155 155
 				$mapping = \array_merge($mapping, $config);
156 156
 			}
157 157
 		}
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -107,12 +107,14 @@
 block discarded – undo
107 107
 	 * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::createDocument()
108 108
 	 */
109 109
 	public function createDocument(ObjectManager $manager, object $object) : ?Document {
110
-		if(!$this->isIndexable($object))
111
-			return null;
110
+		if(!$this->isIndexable($object)) {
111
+					return null;
112
+		}
112 113
 		$document = $this->searchService->createEmptyDocumentFromEntity($object);
113 114
 		$index = $this->fillDocument($document, $object);
114
-		if($index === false)
115
-			return null;
115
+		if($index === false) {
116
+					return null;
117
+		}
116 118
 		
117 119
 		return $document;
118 120
 	}
Please login to merge, or discard this patch.
Services/DoctrineListener.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -131,7 +131,9 @@
 block discarded – undo
131 131
 	 * @param LifecycleEventArgs $args
132 132
 	 */
133 133
 	public function postUpdate(LifecycleEventArgs $args): void {
134
-		if(!$this->enableIndexing) return;
134
+		if(!$this->enableIndexing) {
135
+			return;
136
+		}
135 137
 		$this->updateEntity($args->getObject(), $args->getObjectManager());
136 138
 	}
137 139
 
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @param LifecycleEventArgs $args
119 119
 	 */
120 120
 	public function postPersist(LifecycleEventArgs $args): void {
121
-		if(!$this->enableIndexing) {
121
+		if (!$this->enableIndexing) {
122 122
 			return;
123 123
 		}
124 124
 		$this->updateEntity($args->getObject(), $args->getObjectManager());
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @throws \Doctrine\ORM\OptimisticLockException
131 131
 	 */
132 132
 	public function postFlush(PostFlushEventArgs $eventArgs): void {
133
-		if($this->needsFlush) {
133
+		if ($this->needsFlush) {
134 134
 			$this->needsFlush = false;
135 135
 			$eventArgs->getEntityManager()->flush();
136 136
 		}
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 * @param LifecycleEventArgs $args
143 143
 	 */
144 144
 	public function preRemove(LifecycleEventArgs $args): void {
145
-		if(!$this->enableIndexing) {
145
+		if (!$this->enableIndexing) {
146 146
 			return;
147 147
 		}
148 148
 		$this->removeEntity($args->getObject(), $args->getObjectManager());
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @param LifecycleEventArgs $args
155 155
 	 */
156 156
 	public function postUpdate(LifecycleEventArgs $args): void {
157
-		if(!$this->enableIndexing) return;
157
+		if (!$this->enableIndexing) return;
158 158
 		$this->updateEntity($args->getObject(), $args->getObjectManager());
159 159
 	}
160 160
 
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
 	 * @param object $entity
180 180
 	 */
181 181
 	protected function updateEntity(object $entity, ObjectManager $manager): void {
182
-		if($entity instanceof SearchableAlias) {
182
+		if ($entity instanceof SearchableAlias) {
183 183
 			$entity = $entity->getEntityToIndex();
184 184
 		}
185 185
 		$document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity);
186
-		if($document !== null) {
187
-			if($this->getEventDispatcher()) {
186
+		if ($document !== null) {
187
+			if ($this->getEventDispatcher()) {
188 188
 				$event = new DocumentPreSaveEvent($document);
189 189
 				$this->getEventDispatcher()->dispatch($event, DocumentPreSaveEvent::NAME);
190 190
 			}
@@ -198,11 +198,11 @@  discard block
 block discarded – undo
198 198
 	 * @param object $entity
199 199
 	 */
200 200
 	protected function removeEntity(object $entity, ObjectManager $manager): void {
201
-		if($entity instanceof SearchableAlias) {
201
+		if ($entity instanceof SearchableAlias) {
202 202
 			$entity = $entity->getEntityToIndex();
203 203
 		}
204 204
 		$document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity);
205
-		if($document !== null) {
205
+		if ($document !== null) {
206 206
 			$this->getSearchService()->removeDocument($document);
207 207
 			$this->needsFlush = true;
208 208
 		}
Please login to merge, or discard this patch.
Services/DummySearchService.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function autocomplete(string $search, int $maxResults = 10): array {
68 68
 		$words = array();
69
-		foreach($this->index as $doc) {
70
-			foreach($doc->getFields() as $content) {
71
-				if(is_string($content)) {
69
+		foreach ($this->index as $doc) {
70
+			foreach ($doc->getFields() as $content) {
71
+				if (is_string($content)) {
72 72
 					$words = array_merge($words, explode(' ', $content));
73 73
 				}
74 74
 			}
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 		$facets = new FacetSetAdapter();
93 93
 
94 94
 		$hits = array();
95
-		foreach($this->index as $key => $doc) {
96
-			foreach($doc->getFields() as $content) {
97
-				if(is_string($content) && stripos($content, $term) !== false) {
98
-					if(!isset($hits[$key])) {
95
+		foreach ($this->index as $key => $doc) {
96
+			foreach ($doc->getFields() as $content) {
97
+				if (is_string($content) && stripos($content, $term) !== false) {
98
+					if (!isset($hits[$key])) {
99 99
 						$hits[$key] = 0;
100 100
 					}
101 101
 					$hits[$key] = $hits[$key] + 1;
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		}
105 105
 		arsort($hits);
106 106
 		$results = array();
107
-		foreach(array_keys($hits) as $docId) {
107
+		foreach (array_keys($hits) as $docId) {
108 108
 			$doc = $this->index[$docId];
109 109
 			$facets->addFacetValue(FacetSet::FACET_ENTITY_TYPE, $doc->getEntityClass());
110 110
 			$facets->addFacetValue(FacetSet::FACET_AUTHOR, (string)$doc->getFieldValue(Document::FIELD_AUTHOR));
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		$id = $document->getEntityClass();
132 132
 		$id .= '#';
133 133
 		$entityId = $document->getEntityId();
134
-		if(is_scalar($entityId)) {
134
+		if (is_scalar($entityId)) {
135 135
 			$id .= $entityId;
136 136
 		} else {
137 137
 			$id .= md5(serialize($entityId));
Please login to merge, or discard this patch.
Model/DocumentAdapter.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	public function getFieldValue($fieldName) {
86 86
 		$value = $this->fields[$fieldName] ?? null;
87
-		if(\in_array($fieldName, self::$forceSingleValueFields) && \is_array($value)) {
87
+		if (\in_array($fieldName, self::$forceSingleValueFields) && \is_array($value)) {
88 88
 			return current($value);
89 89
 		}
90 90
 		return $value;
@@ -97,15 +97,15 @@  discard block
 block discarded – undo
97 97
 	 * @see \StingerSoft\EntitySearchBundle\Model\Document::addMultiValueField()
98 98
 	 */
99 99
 	public function addMultiValueField(string $fieldName, $value): void {
100
-		if(!array_key_exists($fieldName, $this->fields)) {
100
+		if (!array_key_exists($fieldName, $this->fields)) {
101 101
 			$this->fields[$fieldName] = array(
102 102
 				$value
103 103
 			);
104
-		} else if(!\is_array($this->fields[$fieldName])) {
104
+		} else if (!\is_array($this->fields[$fieldName])) {
105 105
 			$this->fields[$fieldName] = array(
106 106
 				$value, $this->fields[$fieldName]
107 107
 			);
108
-		} else if(!\in_array($value, $this->fields[$fieldName])) {
108
+		} else if (!\in_array($value, $this->fields[$fieldName])) {
109 109
 			$this->fields[$fieldName][] = $value;
110 110
 		}
111 111
 	}
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 */
129 129
 	public function setEntityClass(string $clazz): void {
130 130
 		$this->entityClass = $clazz;
131
-		if(!$this->entityType) {
131
+		if (!$this->entityType) {
132 132
 			$this->entityType = $clazz;
133 133
 		}
134 134
 	}
Please login to merge, or discard this patch.
Model/Result/FacetSetAdapter.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,10 +33,10 @@  discard block
 block discarded – undo
33 33
 
34 34
 	public function addFacetValue(string $key, string $label, $value = null, int $increaseCounterBy = 1) : void {
35 35
 		$value = $value ?? $label;
36
-		if(!isset($this->facets[$key])) {
36
+		if (!isset($this->facets[$key])) {
37 37
 			$this->facets[$key] = array();
38 38
 		}
39
-		if(!isset($this->facets[$key][$label])) {
39
+		if (!isset($this->facets[$key][$label])) {
40 40
 			$this->facets[$key][$label] = array(
41 41
 				'value' => $value,
42 42
 				'count' => 0,
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @see \StingerSoft\EntitySearchBundle\Model\Result\FacetSet::getFacet()
53 53
 	 */
54 54
 	public function getFacet(string $key): ?array {
55
-		if(isset($this->facets[$key])) {
55
+		if (isset($this->facets[$key])) {
56 56
 			return $this->facets[$key];
57 57
 		}
58 58
 		return null;
Please login to merge, or discard this patch.