@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | * @param LifecycleEventArgs $args |
74 | 74 | */ |
75 | 75 | public function postPersist(LifecycleEventArgs $args) { |
76 | - if(!$this->enableIndexing) return; |
|
76 | + if (!$this->enableIndexing) return; |
|
77 | 77 | $this->updateEntity($args->getObject(), $args->getObjectManager()); |
78 | 78 | } |
79 | 79 | |
80 | 80 | public function postFlush(PostFlushEventArgs $eventArgs) { |
81 | - if($this->needsFlush) { |
|
81 | + if ($this->needsFlush) { |
|
82 | 82 | $this->needsFlush = false; |
83 | 83 | $eventArgs->getEntityManager()->flush(); |
84 | 84 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param LifecycleEventArgs $args |
91 | 91 | */ |
92 | 92 | public function preRemove(LifecycleEventArgs $args) { |
93 | - if(!$this->enableIndexing) return; |
|
93 | + if (!$this->enableIndexing) return; |
|
94 | 94 | $this->removeEntity($args->getObject(), $args->getObjectManager()); |
95 | 95 | } |
96 | 96 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @param LifecycleEventArgs $args |
101 | 101 | */ |
102 | 102 | public function postUpdate(LifecycleEventArgs $args) { |
103 | - if(!$this->enableIndexing) return; |
|
103 | + if (!$this->enableIndexing) return; |
|
104 | 104 | $this->updateEntity($args->getObject(), $args->getObjectManager()); |
105 | 105 | } |
106 | 106 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function updateEntity($entity, ObjectManager $manager) { |
129 | 129 | $document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity); |
130 | - if($document !== false) { |
|
130 | + if ($document !== false) { |
|
131 | 131 | $this->getSearchService($manager)->saveDocument($document); |
132 | 132 | } |
133 | 133 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | protected function removeEntity($entity, ObjectManager $manager) { |
140 | 140 | $document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity); |
141 | - if($document !== false) { |
|
141 | + if ($document !== false) { |
|
142 | 142 | $this->getSearchService($manager)->removeDocument($document); |
143 | 143 | } |
144 | 144 | } |
@@ -73,7 +73,9 @@ discard block |
||
73 | 73 | * @param LifecycleEventArgs $args |
74 | 74 | */ |
75 | 75 | public function postPersist(LifecycleEventArgs $args) { |
76 | - if(!$this->enableIndexing) return; |
|
76 | + if(!$this->enableIndexing) { |
|
77 | + return; |
|
78 | + } |
|
77 | 79 | $this->updateEntity($args->getObject(), $args->getObjectManager()); |
78 | 80 | } |
79 | 81 | |
@@ -90,7 +92,9 @@ discard block |
||
90 | 92 | * @param LifecycleEventArgs $args |
91 | 93 | */ |
92 | 94 | public function preRemove(LifecycleEventArgs $args) { |
93 | - if(!$this->enableIndexing) return; |
|
95 | + if(!$this->enableIndexing) { |
|
96 | + return; |
|
97 | + } |
|
94 | 98 | $this->removeEntity($args->getObject(), $args->getObjectManager()); |
95 | 99 | } |
96 | 100 | |
@@ -100,7 +104,9 @@ discard block |
||
100 | 104 | * @param LifecycleEventArgs $args |
101 | 105 | */ |
102 | 106 | public function postUpdate(LifecycleEventArgs $args) { |
103 | - if(!$this->enableIndexing) return; |
|
107 | + if(!$this->enableIndexing) { |
|
108 | + return; |
|
109 | + } |
|
104 | 110 | $this->updateEntity($args->getObject(), $args->getObjectManager()); |
105 | 111 | } |
106 | 112 |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | |
101 | 101 | /** |
102 | 102 | * |
103 | - * @param FormBuilderInterface|Form $builder |
|
103 | + * @param FormInterface $builder |
|
104 | 104 | * @param FacetSet $facets |
105 | 105 | */ |
106 | 106 | protected function createFacets($builder, FacetSet $facets, array $options, $data) { |
@@ -143,6 +143,9 @@ discard block |
||
143 | 143 | return $choices; |
144 | 144 | } |
145 | 145 | |
146 | + /** |
|
147 | + * @param string $facetType |
|
148 | + */ |
|
146 | 149 | protected function formatFacet($formatter, $facetType, $facet, $count) { |
147 | 150 | $default = $facet . ' (' . $count . ')'; |
148 | 151 | if(!$formatter) { |
@@ -134,12 +134,15 @@ |
||
134 | 134 | protected function generateFacetChoices($facetType, array $facets, array $selectedFacets = array(), $formatter) { |
135 | 135 | $choices = array(); |
136 | 136 | foreach($facets as $facet => $count) { |
137 | - if($count == 0 && !in_array($facet, $selectedFacets)) |
|
138 | - continue; |
|
137 | + if($count == 0 && !in_array($facet, $selectedFacets)) { |
|
138 | + continue; |
|
139 | + } |
|
139 | 140 | $choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet; |
140 | 141 | } |
141 | 142 | foreach($selectedFacets as $facet) { |
142 | - if(isset($facets[$facet])) continue; |
|
143 | + if(isset($facets[$facet])) { |
|
144 | + continue; |
|
145 | + } |
|
143 | 146 | $count = 0; |
144 | 147 | $choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet; |
145 | 148 | } |
@@ -53,25 +53,25 @@ discard block |
||
53 | 53 | $maxChoiceGroupCount = $options['max_choice_group_count']; |
54 | 54 | $data = array(); |
55 | 55 | |
56 | - if($usedFacets && !$result) { |
|
56 | + if ($usedFacets && !$result) { |
|
57 | 57 | $data = array(); |
58 | - foreach($usedFacets as $facetType) { |
|
58 | + foreach ($usedFacets as $facetType) { |
|
59 | 59 | $preferredChoices = isset($preferredFilterChoices[$facetType]) ? $preferredFilterChoices[$facetType] : array(); |
60 | 60 | $i = 0; |
61 | - $builder->add('facet_' . $facetType, FacetType::class, array( |
|
62 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
61 | + $builder->add('facet_'.$facetType, FacetType::class, array( |
|
62 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
63 | 63 | 'multiple' => true, |
64 | 64 | 'expanded' => true, |
65 | 65 | 'allow_extra_fields' => true, |
66 | - 'preferred_choices' => function ($val) use ($preferredChoices, $data, $facetType, $maxChoiceGroupCount, &$i) { |
|
67 | - return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($data['facet_' . $facetType]) && in_array($val, $data['facet_' . $facetType])); |
|
66 | + 'preferred_choices' => function($val) use ($preferredChoices, $data, $facetType, $maxChoiceGroupCount, &$i) { |
|
67 | + return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($data['facet_'.$facetType]) && in_array($val, $data['facet_'.$facetType])); |
|
68 | 68 | } |
69 | 69 | )); |
70 | 70 | unset($i); |
71 | 71 | } |
72 | 72 | } |
73 | - if($result) { |
|
74 | - $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options, $result) { |
|
73 | + if ($result) { |
|
74 | + $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($options, $result) { |
|
75 | 75 | $this->createFacets($event->getForm(), $result->getFacets(), $options, $event->getData()); |
76 | 76 | }); |
77 | 77 | } |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | $maxChoiceGroupCount = $options['max_choice_group_count']; |
110 | 110 | $selectedFacets = $data->getFacets(); |
111 | 111 | |
112 | - foreach($facets->getFacets() as $facetType => $facetValues) { |
|
112 | + foreach ($facets->getFacets() as $facetType => $facetValues) { |
|
113 | 113 | $preferredChoices = isset($preferredFilterChoices[$facetType]) ? $preferredFilterChoices[$facetType] : array(); |
114 | 114 | |
115 | 115 | $i = 0; |
116 | - $builder->add('facet_' . $facetType, FacetType::class, array( |
|
117 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
116 | + $builder->add('facet_'.$facetType, FacetType::class, array( |
|
117 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
118 | 118 | 'multiple' => true, |
119 | 119 | 'expanded' => true, |
120 | 120 | 'allow_extra_fields' => true, |
121 | 121 | 'choices' => $this->generateFacetChoices($facetType, $facetValues, isset($selectedFacets[$facetType]) ? $selectedFacets[$facetType] : array(), $options['facet_formatter']), |
122 | - 'preferred_choices' => function ($val) use ($preferredChoices, $selectedFacets, $facetType, $maxChoiceGroupCount, &$i) { |
|
122 | + 'preferred_choices' => function($val) use ($preferredChoices, $selectedFacets, $facetType, $maxChoiceGroupCount, &$i) { |
|
123 | 123 | return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($selectedFacets[$facetType]) && in_array($val, $selectedFacets[$facetType])); |
124 | 124 | } |
125 | 125 | )); |
@@ -134,13 +134,13 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function generateFacetChoices($facetType, array $facets, array $selectedFacets = array(), $formatter) { |
136 | 136 | $choices = array(); |
137 | - foreach($facets as $facet => $count) { |
|
138 | - if($count == 0 && !in_array($facet, $selectedFacets)) |
|
137 | + foreach ($facets as $facet => $count) { |
|
138 | + if ($count == 0 && !in_array($facet, $selectedFacets)) |
|
139 | 139 | continue; |
140 | 140 | $choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet; |
141 | 141 | } |
142 | - foreach($selectedFacets as $facet) { |
|
143 | - if(isset($facets[$facet])) continue; |
|
142 | + foreach ($selectedFacets as $facet) { |
|
143 | + if (isset($facets[$facet])) continue; |
|
144 | 144 | $count = 0; |
145 | 145 | $choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet; |
146 | 146 | } |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | } |
149 | 149 | |
150 | 150 | protected function formatFacet($formatter, $facetType, $facet, $count) { |
151 | - $default = $facet . ' (' . $count . ')'; |
|
152 | - if(!$formatter) { |
|
151 | + $default = $facet.' ('.$count.')'; |
|
152 | + if (!$formatter) { |
|
153 | 153 | return $default; |
154 | 154 | } |
155 | 155 | return call_user_func($formatter, $facetType, $facet, $count, $default); |
@@ -31,7 +31,7 @@ |
||
31 | 31 | * @see \StingerSoft\EntitySearchBundle\Services\SearchService::setObjectManager() |
32 | 32 | */ |
33 | 33 | public function setObjectManager(ObjectManager $om) { |
34 | - if($this->objectManager) |
|
34 | + if ($this->objectManager) |
|
35 | 35 | return; |
36 | 36 | $this->objectManager = $om; |
37 | 37 | } |
@@ -31,8 +31,9 @@ |
||
31 | 31 | * @see \StingerSoft\EntitySearchBundle\Services\SearchService::setObjectManager() |
32 | 32 | */ |
33 | 33 | public function setObjectManager(ObjectManager $om) { |
34 | - if($this->objectManager) |
|
35 | - return; |
|
34 | + if($this->objectManager) { |
|
35 | + return; |
|
36 | + } |
|
36 | 37 | $this->objectManager = $om; |
37 | 38 | } |
38 | 39 |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | |
26 | 26 | /** |
27 | 27 | * |
28 | - * @param number $save |
|
28 | + * @param integer $save |
|
29 | 29 | * Number of expected saves |
30 | - * @param number $delete |
|
30 | + * @param integer $delete |
|
31 | 31 | * Number of expected deletions |
32 | 32 | */ |
33 | 33 | protected function registerDoctrineListener($save = 0, $delete = 0) { |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | |
51 | 51 | /** |
52 | 52 | * |
53 | - * @param number $save |
|
53 | + * @param integer $save |
|
54 | 54 | * Number of expected saves |
55 | - * @param number $delete |
|
55 | + * @param integer $delete |
|
56 | 56 | * Number of expected deletions |
57 | 57 | */ |
58 | 58 | protected function registerSearchService($save = 0, $delete = 0) { |
@@ -23,7 +23,6 @@ |
||
23 | 23 | /** |
24 | 24 | * Tries to create a document from the given object |
25 | 25 | * |
26 | - * @param object $object |
|
27 | 26 | * @return boolean|Document Returns false if no document could be created |
28 | 27 | */ |
29 | 28 | public function getEntity(Document $document); |
@@ -137,7 +137,7 @@ |
||
137 | 137 | /** |
138 | 138 | * Fetches the mapping for the given object including the mapping of superclasses |
139 | 139 | * |
140 | - * @param object $object |
|
140 | + * @param string $clazz |
|
141 | 141 | * @return \StingerSoft\EntitySearchBundle\Services\string[string] |
142 | 142 | */ |
143 | 143 | protected function getMapping($clazz) { |
@@ -47,18 +47,18 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct(SearchService $searchService, array $mapping = array()) { |
49 | 49 | $this->searchService = $searchService; |
50 | - foreach($mapping as $key => $config) { |
|
51 | - if(!isset($config['mappings'])) { |
|
52 | - throw new \InvalidArgumentException($key . ' has no mapping defined!'); |
|
50 | + foreach ($mapping as $key => $config) { |
|
51 | + if (!isset($config['mappings'])) { |
|
52 | + throw new \InvalidArgumentException($key.' has no mapping defined!'); |
|
53 | 53 | } |
54 | - if(!isset($config['persistence'])) { |
|
55 | - throw new \InvalidArgumentException($key . ' has no persistence defined!'); |
|
54 | + if (!isset($config['persistence'])) { |
|
55 | + throw new \InvalidArgumentException($key.' has no persistence defined!'); |
|
56 | 56 | } |
57 | - if(!isset($config['persistence']['model'])) { |
|
58 | - throw new \InvalidArgumentException($key . ' has no model defined!'); |
|
57 | + if (!isset($config['persistence']['model'])) { |
|
58 | + throw new \InvalidArgumentException($key.' has no model defined!'); |
|
59 | 59 | } |
60 | 60 | $map = array(); |
61 | - foreach($config['mappings'] as $fieldKey => $fieldConfig) { |
|
61 | + foreach ($config['mappings'] as $fieldKey => $fieldConfig) { |
|
62 | 62 | $map[$fieldKey] = isset($fieldConfig['propertyPath']) && $fieldConfig['propertyPath'] ? $fieldConfig['propertyPath'] : $fieldKey; |
63 | 63 | } |
64 | 64 | |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::isIndexable() |
74 | 74 | */ |
75 | 75 | public function isIndexable($object) { |
76 | - if($object instanceof SearchableEntity) { |
|
76 | + if ($object instanceof SearchableEntity) { |
|
77 | 77 | return true; |
78 | 78 | } |
79 | - if(count($this->getMapping(get_class($object))) > 0) { |
|
79 | + if (count($this->getMapping(get_class($object))) > 0) { |
|
80 | 80 | return true; |
81 | 81 | } |
82 | 82 | return false; |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function isClassIndexable($clazz) { |
92 | 92 | $reflectionClass = new \ReflectionClass($clazz); |
93 | - if(array_key_exists(SearchableEntity::class, $reflectionClass->getInterfaces())) { |
|
93 | + if (array_key_exists(SearchableEntity::class, $reflectionClass->getInterfaces())) { |
|
94 | 94 | return true; |
95 | 95 | } |
96 | - if(count($this->getMapping($clazz)) > 0) { |
|
96 | + if (count($this->getMapping($clazz)) > 0) { |
|
97 | 97 | return true; |
98 | 98 | } |
99 | 99 | return false; |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::createDocument() |
106 | 106 | */ |
107 | 107 | public function createDocument(ObjectManager $manager, $object) { |
108 | - if(!$this->isIndexable($object)) |
|
108 | + if (!$this->isIndexable($object)) |
|
109 | 109 | return false; |
110 | 110 | $document = $this->getSearchService($manager)->createEmptyDocumentFromEntity($object); |
111 | 111 | $index = $this->fillDocument($document, $object); |
112 | - if($index == false) |
|
112 | + if ($index == false) |
|
113 | 113 | return false; |
114 | 114 | |
115 | 115 | return $document; |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | * @param object $object |
123 | 123 | * @return boolean |
124 | 124 | */ |
125 | - protected function fillDocument(Document &$document, $object) { |
|
126 | - if($object instanceof SearchableEntity) { |
|
125 | + protected function fillDocument(Document&$document, $object) { |
|
126 | + if ($object instanceof SearchableEntity) { |
|
127 | 127 | return $object->indexEntity($document); |
128 | 128 | } |
129 | 129 | $mapping = $this->getMapping(get_class($object)); |
130 | 130 | $accessor = PropertyAccess::createPropertyAccessor(); |
131 | - foreach($mapping as $fieldName => $propertyPath) { |
|
131 | + foreach ($mapping as $fieldName => $propertyPath) { |
|
132 | 132 | $document->addField($fieldName, $accessor->getValue($object, $propertyPath)); |
133 | 133 | } |
134 | 134 | return true; |
@@ -141,15 +141,15 @@ discard block |
||
141 | 141 | * @return \StingerSoft\EntitySearchBundle\Services\string[string] |
142 | 142 | */ |
143 | 143 | protected function getMapping($clazz) { |
144 | - if(isset($this->cachedMapping[$clazz])) { |
|
144 | + if (isset($this->cachedMapping[$clazz])) { |
|
145 | 145 | return $this->cachedMapping[$clazz]; |
146 | 146 | } |
147 | 147 | $ref = new \ReflectionClass($clazz); |
148 | 148 | |
149 | 149 | $mapping = array(); |
150 | 150 | |
151 | - foreach($this->mapping as $className => $config) { |
|
152 | - if($clazz == $className || $ref->isSubclassOf($className)) { |
|
151 | + foreach ($this->mapping as $className => $config) { |
|
152 | + if ($clazz == $className || $ref->isSubclassOf($className)) { |
|
153 | 153 | $mapping = array_merge($mapping, $config); |
154 | 154 | } |
155 | 155 | } |
@@ -105,12 +105,14 @@ |
||
105 | 105 | * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::createDocument() |
106 | 106 | */ |
107 | 107 | public function createDocument(ObjectManager $manager, $object) { |
108 | - if(!$this->isIndexable($object)) |
|
109 | - return false; |
|
108 | + if(!$this->isIndexable($object)) { |
|
109 | + return false; |
|
110 | + } |
|
110 | 111 | $document = $this->getSearchService($manager)->createEmptyDocumentFromEntity($object); |
111 | 112 | $index = $this->fillDocument($document, $object); |
112 | - if($index == false) |
|
113 | - return false; |
|
113 | + if($index == false) { |
|
114 | + return false; |
|
115 | + } |
|
114 | 116 | |
115 | 117 | return $document; |
116 | 118 | } |
@@ -54,7 +54,7 @@ |
||
54 | 54 | * |
55 | 55 | * @see \StingerSoft\EntitySearchBundle\Model\SearchableEntity::indexEntity() |
56 | 56 | */ |
57 | - public function indexEntity(Document &$document) { |
|
57 | + public function indexEntity(Document&$document) { |
|
58 | 58 | $document->addField(Document::FIELD_TITLE, $this->getTitle()); |
59 | 59 | return self::$index; |
60 | 60 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | * |
50 | 50 | * @see \StingerSoft\EntitySearchBundle\Model\SearchableEntity::indexEntity() |
51 | 51 | */ |
52 | - public function indexEntity(Document &$document) { |
|
52 | + public function indexEntity(Document&$document) { |
|
53 | 53 | $document->addField(Document::FIELD_TITLE, $this->getTitle()); |
54 | 54 | return self::$index; |
55 | 55 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | ); |
45 | 45 | $config = null === $config ? $this->getMockAnnotatedConfig() : $config; |
46 | 46 | $em = EntityManager::create($conn, $config, $evm ?: $this->getEventManager()); |
47 | - $schema = array_map(function ($class) use ($em) { |
|
47 | + $schema = array_map(function($class) use ($em) { |
|
48 | 48 | return $em->getClassMetadata($class); |
49 | 49 | }, (array)$this->getUsedEntityFixtures()); |
50 | 50 | $schemaTool = new SchemaTool($em); |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | $refl = new \ReflectionClass($configurationClass); |
70 | 70 | $methods = $refl->getMethods(); |
71 | 71 | $mockMethods = array(); |
72 | - foreach($methods as $method) { |
|
73 | - if($method->name !== 'addFilter' && $method->name !== 'getFilterClassName') { |
|
72 | + foreach ($methods as $method) { |
|
73 | + if ($method->name !== 'addFilter' && $method->name !== 'getFilterClassName') { |
|
74 | 74 | $mockMethods[] = $method->name; |
75 | 75 | } |
76 | 76 | } |
77 | 77 | $config = $this->getMockBuilder($configurationClass)->setMethods($mockMethods)->getMock(); |
78 | - $config->expects($this->once())->method('getProxyDir')->will($this->returnValue(__DIR__ . '/../../temp')); |
|
78 | + $config->expects($this->once())->method('getProxyDir')->will($this->returnValue(__DIR__.'/../../temp')); |
|
79 | 79 | $config->expects($this->once())->method('getProxyNamespace')->will($this->returnValue('Proxy')); |
80 | 80 | $config->expects($this->any())->method('getDefaultQueryHints')->will($this->returnValue(array())); |
81 | 81 | $config->expects($this->once())->method('getAutoGenerateProxyClasses')->will($this->returnValue(true)); |