@@ -53,7 +53,7 @@ |
||
| 53 | 53 | /** |
| 54 | 54 | * @param Document[] $results |
| 55 | 55 | */ |
| 56 | - public function setResults(array $results){ |
|
| 56 | + public function setResults(array $results) { |
|
| 57 | 57 | $this->results = $results; |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function addFacetValue($key, $value, $increaseCounterBy = 1) { |
| 33 | - if(!isset($this->facets[$key])){ |
|
| 33 | + if (!isset($this->facets[$key])) { |
|
| 34 | 34 | $this->facets[$key] = array(); |
| 35 | 35 | } |
| 36 | - if(!isset($this->facets[$key][$value])){ |
|
| 36 | + if (!isset($this->facets[$key][$value])) { |
|
| 37 | 37 | $this->facets[$key][$value] = 0; |
| 38 | 38 | } |
| 39 | 39 | $this->facets[$key][$value] = $this->facets[$key][$value] + $increaseCounterBy; |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @see \StingerSoft\EntitySearchBundle\Model\Result\FacetSet::getFacet() |
| 47 | 47 | */ |
| 48 | 48 | public function getFacet($key) { |
| 49 | - if(isset($this->facets[$key])) { |
|
| 49 | + if (isset($this->facets[$key])) { |
|
| 50 | 50 | return $this->facets[$key]; |
| 51 | 51 | } else { |
| 52 | 52 | return; |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | protected function updateEntity($entity, ObjectManager $manager) { |
| 99 | 99 | $document = $this->getEntityHandler()->createDocument($manager, $entity); |
| 100 | - if($document !== false) { |
|
| 100 | + if ($document !== false) { |
|
| 101 | 101 | $this->getSearchService($manager)->saveDocument($document); |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | protected function removeEntity($entity, ObjectManager $manager) { |
| 110 | 110 | $document = $this->getEntityHandler()->createDocument($manager, $entity); |
| 111 | - if($document !== false) { |
|
| 111 | + if ($document !== false) { |
|
| 112 | 112 | $this->getSearchService($manager)->removeDocument($document); |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -46,18 +46,18 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function __construct(SearchService $searchService, array $mapping = array()) { |
| 48 | 48 | $this->searchService = $searchService; |
| 49 | - foreach($mapping as $key => $config) { |
|
| 50 | - if(!isset($config['mappings'])) { |
|
| 51 | - throw new \InvalidArgumentException($key . ' has no mapping defined!'); |
|
| 49 | + foreach ($mapping as $key => $config) { |
|
| 50 | + if (!isset($config['mappings'])) { |
|
| 51 | + throw new \InvalidArgumentException($key.' has no mapping defined!'); |
|
| 52 | 52 | } |
| 53 | - if(!isset($config['persistence'])) { |
|
| 54 | - throw new \InvalidArgumentException($key . ' has no persistence defined!'); |
|
| 53 | + if (!isset($config['persistence'])) { |
|
| 54 | + throw new \InvalidArgumentException($key.' has no persistence defined!'); |
|
| 55 | 55 | } |
| 56 | - if(!isset($config['persistence']['model'])) { |
|
| 57 | - throw new \InvalidArgumentException($key . ' has no model defined!'); |
|
| 56 | + if (!isset($config['persistence']['model'])) { |
|
| 57 | + throw new \InvalidArgumentException($key.' has no model defined!'); |
|
| 58 | 58 | } |
| 59 | 59 | $map = array(); |
| 60 | - foreach($config['mappings'] as $fieldKey => $fieldConfig) { |
|
| 60 | + foreach ($config['mappings'] as $fieldKey => $fieldConfig) { |
|
| 61 | 61 | $map[$fieldKey] = isset($fieldConfig['propertyPath']) && $fieldConfig['propertyPath'] ? $fieldConfig['propertyPath'] : $fieldKey; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | * @return boolean |
| 73 | 73 | */ |
| 74 | 74 | public function isIndexable($object) { |
| 75 | - if($object instanceof SearchableEntity) { |
|
| 75 | + if ($object instanceof SearchableEntity) { |
|
| 76 | 76 | return true; |
| 77 | 77 | } |
| 78 | - if(count($this->getMapping($object)) > 0) { |
|
| 78 | + if (count($this->getMapping($object)) > 0) { |
|
| 79 | 79 | return true; |
| 80 | 80 | } |
| 81 | 81 | return false; |
@@ -89,11 +89,11 @@ discard block |
||
| 89 | 89 | * @return boolean|Document Returns false if no document could be created |
| 90 | 90 | */ |
| 91 | 91 | public function createDocument(ObjectManager $manager, $object) { |
| 92 | - if(!$this->isIndexable($object)) |
|
| 92 | + if (!$this->isIndexable($object)) |
|
| 93 | 93 | return false; |
| 94 | 94 | $document = $this->getSearchService($manager)->createEmptyDocumentFromEntity($object); |
| 95 | 95 | $index = $this->fillDocument($document, $object); |
| 96 | - if($index == false) |
|
| 96 | + if ($index == false) |
|
| 97 | 97 | return false; |
| 98 | 98 | |
| 99 | 99 | return $document; |
@@ -106,13 +106,13 @@ discard block |
||
| 106 | 106 | * @param object $object |
| 107 | 107 | * @return boolean |
| 108 | 108 | */ |
| 109 | - protected function fillDocument(Document &$document, $object) { |
|
| 110 | - if($object instanceof SearchableEntity) { |
|
| 109 | + protected function fillDocument(Document&$document, $object) { |
|
| 110 | + if ($object instanceof SearchableEntity) { |
|
| 111 | 111 | return $object->indexEntity($document); |
| 112 | 112 | } |
| 113 | 113 | $mapping = $this->getMapping($object); |
| 114 | 114 | $accessor = PropertyAccess::createPropertyAccessor(); |
| 115 | - foreach($mapping as $fieldName => $propertyPath) { |
|
| 115 | + foreach ($mapping as $fieldName => $propertyPath) { |
|
| 116 | 116 | $document->addField($fieldName, $accessor->getValue($object, $propertyPath)); |
| 117 | 117 | } |
| 118 | 118 | return true; |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | protected function getMapping($object) { |
| 128 | 128 | $clazz = get_class($object); |
| 129 | - if(isset($this->cachedMapping[$clazz])) { |
|
| 129 | + if (isset($this->cachedMapping[$clazz])) { |
|
| 130 | 130 | return $this->cachedMapping[$clazz]; |
| 131 | 131 | } |
| 132 | 132 | $ref = new \ReflectionClass($clazz); |
| 133 | 133 | |
| 134 | 134 | $mapping = array(); |
| 135 | 135 | |
| 136 | - foreach($this->mapping as $className => $config) { |
|
| 137 | - if($clazz == $className || $ref->isSubclassOf($className)) { |
|
| 136 | + foreach ($this->mapping as $className => $config) { |
|
| 137 | + if ($clazz == $className || $ref->isSubclassOf($className)) { |
|
| 138 | 138 | $mapping = array_merge($mapping, $config); |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -89,12 +89,14 @@ |
||
| 89 | 89 | * @return boolean|Document Returns false if no document could be created |
| 90 | 90 | */ |
| 91 | 91 | public function createDocument(ObjectManager $manager, $object) { |
| 92 | - if(!$this->isIndexable($object)) |
|
| 93 | - return false; |
|
| 92 | + if(!$this->isIndexable($object)) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 94 | 95 | $document = $this->getSearchService($manager)->createEmptyDocumentFromEntity($object); |
| 95 | 96 | $index = $this->fillDocument($document, $object); |
| 96 | - if($index == false) |
|
| 97 | - return false; |
|
| 97 | + if($index == false) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 98 | 100 | |
| 99 | 101 | return $document; |
| 100 | 102 | } |