| @@ -13,13 +13,11 @@ | ||
| 13 | 13 | |
| 14 | 14 | namespace StingerSoft\EntitySearchBundle\Command; | 
| 15 | 15 | |
| 16 | -use Doctrine\Common\Persistence\ObjectManager; | |
| 17 | 16 | use Doctrine\DBAL\Platforms\SQLServerPlatform; | 
| 18 | 17 | use Doctrine\ORM\EntityManager; | 
| 19 | 18 | use Doctrine\ORM\Mapping\ClassMetadata; | 
| 20 | 19 | use StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface; | 
| 21 | 20 | use StingerSoft\EntitySearchBundle\Services\SearchService; | 
| 22 | -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |
| 23 | 21 | use Symfony\Component\Console\Command\Command; | 
| 24 | 22 | use Symfony\Component\Console\Helper\ProgressBar; | 
| 25 | 23 | use Symfony\Component\Console\Input\InputArgument; | 
| @@ -60,13 +60,13 @@ discard block | ||
| 60 | 60 | $this->searchService = $searchService; | 
| 61 | 61 | $this->entityToDocumentMapper = $mapper; | 
| 62 | 62 | // Detect upload path | 
| 63 | -		if(!self::$defaultUploadPath) { | |
| 64 | -			if(Kernel::VERSION_ID < 40200) { | |
| 63 | +		if (!self::$defaultUploadPath) { | |
| 64 | +			if (Kernel::VERSION_ID < 40200) { | |
| 65 | 65 | $root = $kernel->getRootDir(); | 
| 66 | 66 |  			} else { | 
| 67 | 67 | $root = $kernel->getProjectDir(); | 
| 68 | 68 | } | 
| 69 | - self::$defaultUploadPath = $root . '/../web/uploads'; | |
| 69 | + self::$defaultUploadPath = $root.'/../web/uploads'; | |
| 70 | 70 | } | 
| 71 | 71 | } | 
| 72 | 72 | |
| @@ -102,7 +102,7 @@ discard block | ||
| 102 | 102 | // Get the entity argument | 
| 103 | 103 |  		$entity = $input->getArgument('entity'); | 
| 104 | 104 | |
| 105 | -		if($entity === 'all') { | |
| 105 | +		if ($entity === 'all') { | |
| 106 | 106 | /** | 
| 107 | 107 | * @var EntityManager $entityManager | 
| 108 | 108 | */ | 
| @@ -113,12 +113,12 @@ discard block | ||
| 113 | 113 | /** | 
| 114 | 114 | * @var ClassMetadata $m | 
| 115 | 115 | */ | 
| 116 | -			foreach($meta as $m) { | |
| 116 | +			foreach ($meta as $m) { | |
| 117 | 117 | |
| 118 | -				if($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { | |
| 118 | +				if ($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { | |
| 119 | 119 | continue; | 
| 120 | 120 | } | 
| 121 | -				if(!$this->entityToDocumentMapper->isClassIndexable($m->getReflectionClass()->getName())) { | |
| 121 | +				if (!$this->entityToDocumentMapper->isClassIndexable($m->getReflectionClass()->getName())) { | |
| 122 | 122 | continue; | 
| 123 | 123 | } | 
| 124 | 124 | $this->indexEntity($input, $output, $m->getReflectionClass()->getName()); | 
| @@ -150,7 +150,7 @@ discard block | ||
| 150 | 150 |  		try { | 
| 151 | 151 | // Get repository for the given entity type | 
| 152 | 152 | $repository = $entityManager->getRepository($entity); | 
| 153 | -		} catch(\Exception $e) { | |
| 153 | +		} catch (\Exception $e) { | |
| 154 | 154 |  			$output->writeln(sprintf('<error>No repository found for "%s", check your input</error>', $entity)); | 
| 155 | 155 | return; | 
| 156 | 156 | } | 
| @@ -162,7 +162,7 @@ discard block | ||
| 162 | 162 | |
| 163 | 163 | $useBatch = !($entityManager->getConnection()->getDatabasePlatform() instanceof SQLServerPlatform); | 
| 164 | 164 | $iterableResult = $useBatch ? $queryBuilder->getQuery()->iterate() : $queryBuilder->getQuery()->getResult(); | 
| 165 | -		if($entityCount === 0) { | |
| 165 | +		if ($entityCount === 0) { | |
| 166 | 166 |  			$output->writeln('<comment>No entities found for indexing</comment>'); | 
| 167 | 167 | return; | 
| 168 | 168 | } | 
| @@ -172,21 +172,21 @@ discard block | ||
| 172 | 172 | $entitiesIndexed = 0; | 
| 173 | 173 | |
| 174 | 174 | // Index each entity separate | 
| 175 | -		foreach($iterableResult as $row) { | |
| 175 | +		foreach ($iterableResult as $row) { | |
| 176 | 176 | $entity = $useBatch ? $row[0] : $row; | 
| 177 | 177 | $progressBar->advance(); | 
| 178 | -			if($this->entityToDocumentMapper->isIndexable($entity)) { | |
| 178 | +			if ($this->entityToDocumentMapper->isIndexable($entity)) { | |
| 179 | 179 | $document = $this->entityToDocumentMapper->createDocument($entityManager, $entity); | 
| 180 | -				if($document === null) { | |
| 180 | +				if ($document === null) { | |
| 181 | 181 | continue; | 
| 182 | 182 | } | 
| 183 | 183 |  				try { | 
| 184 | 184 | $this->searchService->saveDocument($document); | 
| 185 | 185 | $entitiesIndexed++; | 
| 186 | -				} catch(\Exception $e) { | |
| 187 | -					$output->writeln('<error>Failed to index entity with ID ' . $document->getEntityId() . '</error>'); | |
| 186 | +				} catch (\Exception $e) { | |
| 187 | +					$output->writeln('<error>Failed to index entity with ID '.$document->getEntityId().'</error>'); | |
| 188 | 188 | } | 
| 189 | -				if($entitiesIndexed % 50 === 0) { | |
| 189 | +				if ($entitiesIndexed % 50 === 0) { | |
| 190 | 190 | $entityManager->flush(); | 
| 191 | 191 | } | 
| 192 | 192 | } | 
| @@ -196,7 +196,7 @@ discard block | ||
| 196 | 196 | $entityManager->clear(); | 
| 197 | 197 | $progressBar->finish(); | 
| 198 | 198 |  		$output->writeln(''); | 
| 199 | -		$output->writeln('<comment>Indexed ' . $entitiesIndexed . ' entities</comment>'); | |
| 199 | +		$output->writeln('<comment>Indexed '.$entitiesIndexed.' entities</comment>'); | |
| 200 | 200 | } | 
| 201 | 201 | |
| 202 | 202 | } | 
| 203 | 203 | \ No newline at end of file | 
| @@ -94,6 +94,7 @@ discard block | ||
| 94 | 94 | * The name of the field | 
| 95 | 95 | * @param mixed $value | 
| 96 | 96 | * The value of this field | 
| 97 | + * @return void | |
| 97 | 98 | */ | 
| 98 | 99 | public function addField(string $fieldName, $value): void; | 
| 99 | 100 | |
| @@ -122,6 +123,7 @@ discard block | ||
| 122 | 123 | * The name of the field | 
| 123 | 124 | * @param mixed $value | 
| 124 | 125 | * The additional value of this field | 
| 126 | + * @return void | |
| 125 | 127 | */ | 
| 126 | 128 | public function addMultiValueField(string $fieldName, $value): void; | 
| 127 | 129 | |
| @@ -133,6 +135,7 @@ discard block | ||
| 133 | 135 | * | 
| 134 | 136 | * @param string $clazz | 
| 135 | 137 | * The classname | 
| 138 | + * @return void | |
| 136 | 139 | */ | 
| 137 | 140 | public function setEntityClass(string $clazz): void; | 
| 138 | 141 | |
| @@ -152,6 +155,7 @@ discard block | ||
| 152 | 155 | * | 
| 153 | 156 | * @param mixed $id | 
| 154 | 157 | * The ID of the corresponding entity | 
| 158 | + * @return void | |
| 155 | 159 | */ | 
| 156 | 160 | public function setEntityId($id): void; | 
| 157 | 161 | |
| @@ -168,6 +172,7 @@ discard block | ||
| 168 | 172 | * hiding some programatically needed complexity from the user | 
| 169 | 173 | * | 
| 170 | 174 | * @param string $type | 
| 175 | + * @return void | |
| 171 | 176 | */ | 
| 172 | 177 | public function setEntityType(string $type): void; | 
| 173 | 178 | |
| @@ -178,7 +183,6 @@ discard block | ||
| 178 | 183 | * | 
| 179 | 184 | * If no entity type is set, the class will be used instead | 
| 180 | 185 | * | 
| 181 | - * @param string $type | |
| 182 | 186 | */ | 
| 183 | 187 | public function getEntityType(): string; | 
| 184 | 188 | |
| @@ -188,6 +192,7 @@ discard block | ||
| 188 | 192 | * <strong>note:</strong> This may not supported by the underlying implementation | 
| 189 | 193 | * | 
| 190 | 194 | * @param string $path | 
| 195 | + * @return void | |
| 191 | 196 | */ | 
| 192 | 197 | public function setFile(string $path): void; | 
| 193 | 198 | |
| @@ -106,7 +106,7 @@ | ||
| 106 | 106 | * | 
| 107 | 107 | * @param string $name | 
| 108 | 108 | * Name of the property to set | 
| 109 | - * @param mixed $value | |
| 109 | + * @param string[] $value | |
| 110 | 110 | * The value of the property | 
| 111 | 111 | */ | 
| 112 | 112 |  	public function __set($name, $value): void { | 
| @@ -92,10 +92,10 @@ discard block | ||
| 92 | 92 | * @return array | 
| 93 | 93 | */ | 
| 94 | 94 |  	public function __get($name) { | 
| 95 | -		if(strrpos($name, 'facet_', -strlen($name)) !== false) { | |
| 95 | +		if (strrpos($name, 'facet_', -strlen($name)) !== false) { | |
| 96 | 96 | $facetname = substr($name, 6); | 
| 97 | 97 | |
| 98 | -			if(isset($this->facets[$facetname])) { | |
| 98 | +			if (isset($this->facets[$facetname])) { | |
| 99 | 99 | return $this->facets[$facetname]; | 
| 100 | 100 | } | 
| 101 | 101 | return array(); | 
| @@ -110,7 +110,7 @@ discard block | ||
| 110 | 110 | * The value of the property | 
| 111 | 111 | */ | 
| 112 | 112 |  	public function __set($name, $value): void { | 
| 113 | -		if(strrpos($name, 'facet_', -strlen($name)) !== false) { | |
| 113 | +		if (strrpos($name, 'facet_', -strlen($name)) !== false) { | |
| 114 | 114 | $facetname = substr($name, 6); | 
| 115 | 115 | $this->facets[$facetname] = $value; | 
| 116 | 116 | } | 
| @@ -123,7 +123,7 @@ discard block | ||
| 123 | 123 | * @return boolean | 
| 124 | 124 | */ | 
| 125 | 125 |  	public function __isset($name): bool { | 
| 126 | -		if(strrpos($name, 'facet_', -strlen($name)) !== false) { | |
| 126 | +		if (strrpos($name, 'facet_', -strlen($name)) !== false) { | |
| 127 | 127 | return true; | 
| 128 | 128 | } | 
| 129 | 129 | |
| @@ -40,5 +40,8 @@ | ||
| 40 | 40 | */ | 
| 41 | 41 | public function getFacets(): array; | 
| 42 | 42 | |
| 43 | + /** | |
| 44 | + * @return void | |
| 45 | + */ | |
| 43 | 46 | public function addFacetValue(string $key, string $label, $value = null, int $increaseCounterBy = 1) : void; | 
| 44 | 47 | } | 
| 45 | 48 | \ No newline at end of file | 
| @@ -22,7 +22,6 @@ | ||
| 22 | 22 | /** | 
| 23 | 23 | * Tries to create a document from the given object | 
| 24 | 24 | * | 
| 25 | - * @param object $object | |
| 26 | 25 | * @return object Returns false if no document could be created | 
| 27 | 26 | */ | 
| 28 | 27 | public function getEntity(Document $document) : ?object; | 
| @@ -61,7 +61,7 @@ discard block | ||
| 61 | 61 | /** | 
| 62 | 62 | * Get annotation mapping configuration | 
| 63 | 63 | * | 
| 64 | - * @return \Doctrine\ORM\Configuration | |
| 64 | + * @return \PHPUnit\Framework\MockObject\MockObject | |
| 65 | 65 | */ | 
| 66 | 66 |  	protected function getMockAnnotatedConfig() { | 
| 67 | 67 | // We need to mock every method except the ones which | 
| @@ -93,7 +93,7 @@ discard block | ||
| 93 | 93 | /** | 
| 94 | 94 | * Creates default mapping driver | 
| 95 | 95 | * | 
| 96 | - * @return \Doctrine\ORM\Mapping\Driver\Driver | |
| 96 | + * @return AnnotationDriver | |
| 97 | 97 | */ | 
| 98 | 98 |  	protected function getMetadataDriverImplementation() { | 
| 99 | 99 | return new AnnotationDriver($_ENV['annotation_reader'], $this->getPaths()); | 
| @@ -77,6 +77,9 @@ | ||
| 77 | 77 | |
| 78 | 78 | } | 
| 79 | 79 | |
| 80 | + /** | |
| 81 | + * @param \StingerSoft\EntitySearchBundle\Services\DummySearchService $searchService | |
| 82 | + */ | |
| 80 | 83 |  	protected function getSearchController(?SearchService $searchService = null): SearchController { | 
| 81 | 84 | $searchService = $searchService ?? $this->getDummySearchService(); | 
| 82 | 85 | |
| @@ -97,7 +97,7 @@ discard block | ||
| 97 | 97 | return \in_array($id, ['twig', 'form.factory'], true); | 
| 98 | 98 | }); | 
| 99 | 99 |  		$container->method('get')->willReturnCallback(function($id) use ($that) { | 
| 100 | -			if($id === 'form.factory') { | |
| 100 | +			if ($id === 'form.factory') { | |
| 101 | 101 | $resolvedFormTypeFactory = new ResolvedFormTypeFactory(); | 
| 102 | 102 | $formTypeFactory = Forms::createFormFactoryBuilder() | 
| 103 | 103 | ->addType(new FacetType()) | 
| @@ -107,7 +107,7 @@ discard block | ||
| 107 | 107 | ->getFormFactory(); | 
| 108 | 108 | return $formTypeFactory; | 
| 109 | 109 | } | 
| 110 | -			if($id === 'twig') { | |
| 110 | +			if ($id === 'twig') { | |
| 111 | 111 | return $that; | 
| 112 | 112 | } | 
| 113 | 113 | }); | 
| @@ -32,7 +32,7 @@ discard block | ||
| 32 | 32 | private $facetFormatter; | 
| 33 | 33 | |
| 34 | 34 |  	public function searchAction(Request $request, DocumentToEntityMapperInterface $mapper) { | 
| 35 | -		if($request->query->get('term', false) !== false) { | |
| 35 | +		if ($request->query->get('term', false) !== false) { | |
| 36 | 36 |  			$this->setSearchTerm($request->getSession(), $request->query->get('term')); | 
| 37 | 37 |  			return $this->redirectToRoute('stinger_soft_entity_search_search'); | 
| 38 | 38 | } | 
| @@ -48,8 +48,8 @@ discard block | ||
| 48 | 48 | )); | 
| 49 | 49 | |
| 50 | 50 | $facetForm->handleRequest($request); | 
| 51 | -		if($facetForm->isSubmitted()) { | |
| 52 | -			if($facetForm->get('clear')->isClicked()) { | |
| 51 | +		if ($facetForm->isSubmitted()) { | |
| 52 | +			if ($facetForm->get('clear')->isClicked()) { | |
| 53 | 53 | $query->setFacets($this->getDefaultFacets()); | 
| 54 | 54 | } | 
| 55 | 55 | $this->setSearchTerm($request->getSession(), $query->getSearchTerm()); | 
| @@ -67,9 +67,9 @@ discard block | ||
| 67 | 67 | |
| 68 | 68 |  			$page = (int)$request->query->get('page', 1); | 
| 69 | 69 | $results = null; | 
| 70 | -			if($result instanceof PaginatableResultSet) { | |
| 70 | +			if ($result instanceof PaginatableResultSet) { | |
| 71 | 71 | $results = $result->paginate($page, $this->getResultsPerPage()); | 
| 72 | -			} elseif($results !== null) { | |
| 72 | +			} elseif ($results !== null) { | |
| 73 | 73 | $results = $result->getResults(($page - 1) * $this->getResultsPerPage(), $this->getResultsPerPage()); | 
| 74 | 74 | } | 
| 75 | 75 | |
| @@ -80,7 +80,7 @@ discard block | ||
| 80 | 80 | 'mapper' => $mapper, | 
| 81 | 81 | 'facetForm' => $facetForm->createView() | 
| 82 | 82 | )); | 
| 83 | -		} catch(\Exception $exception) { | |
| 83 | +		} catch (\Exception $exception) { | |
| 84 | 84 | $response = $this->render($this->getErrorTemplate(), array( | 
| 85 | 85 | 'error' => $exception->getMessage(), | 
| 86 | 86 | 'term' => $query->getSearchTerm() | 
| @@ -124,7 +124,7 @@ discard block | ||
| 124 | 124 |  	protected function getConfiguredUsedFacets(array $queryUsedFacets) { | 
| 125 | 125 | $availableFacets = $this->getAvailableFacets(); | 
| 126 | 126 | $usedFacets = array(); | 
| 127 | -		foreach($queryUsedFacets as $queryUsedFacet) { | |
| 127 | +		foreach ($queryUsedFacets as $queryUsedFacet) { | |
| 128 | 128 | $usedFacets[$queryUsedFacet] = $availableFacets[$queryUsedFacet]; | 
| 129 | 129 | } | 
| 130 | 130 | return $usedFacets; | 
| @@ -191,15 +191,15 @@ discard block | ||
| 191 | 191 | } | 
| 192 | 192 | |
| 193 | 193 |  	protected function initFacets() { | 
| 194 | -		if(!$this->availableFacets) { | |
| 194 | +		if (!$this->availableFacets) { | |
| 195 | 195 | $this->availableFacets = array(); | 
| 196 | 196 | $this->facetFormatter = array(); | 
| 197 | 197 | |
| 198 | 198 |  			$facetServices = $this->getParameter('stinger_soft.entity_search.available_facets'); | 
| 199 | -			foreach($facetServices as $facetServiceId) { | |
| 199 | +			foreach ($facetServices as $facetServiceId) { | |
| 200 | 200 | $facetService = $this->searchService->getFacet($facetServiceId); | 
| 201 | 201 | $this->availableFacets[$facetService->getField()] = $facetService->getFormOptions(); | 
| 202 | -				if($facetService->getFacetFormatter()) { | |
| 202 | +				if ($facetService->getFacetFormatter()) { | |
| 203 | 203 | $this->facetFormatter[$facetService->getField()] = $facetService->getFacetFormatter(); | 
| 204 | 204 | } | 
| 205 | 205 | } | 
| @@ -213,7 +213,7 @@ discard block | ||
| 213 | 213 | * @return string[string][] | 
| 214 | 214 | */ | 
| 215 | 215 |  	protected function getSearchFacets(SessionInterface $session) { | 
| 216 | - $facets = $session->get($this->getSessionPrefix() . '_facets', false); | |
| 216 | + $facets = $session->get($this->getSessionPrefix().'_facets', false); | |
| 217 | 217 | return $facets ? \json_decode($facets, true) : $this->getDefaultFacets(); | 
| 218 | 218 | } | 
| 219 | 219 | |
| @@ -224,7 +224,7 @@ discard block | ||
| 224 | 224 | * @param string[string][] $facets | 
| 225 | 225 | */ | 
| 226 | 226 |  	protected function setSearchFacets(SessionInterface $session, $facets) { | 
| 227 | - $session->set($this->getSessionPrefix() . '_facets', \json_encode($facets)); | |
| 227 | + $session->set($this->getSessionPrefix().'_facets', \json_encode($facets)); | |
| 228 | 228 | } | 
| 229 | 229 | |
| 230 | 230 | /** | 
| @@ -234,7 +234,7 @@ discard block | ||
| 234 | 234 | * @return mixed | 
| 235 | 235 | */ | 
| 236 | 236 |  	protected function getSearchTerm(SessionInterface $session) { | 
| 237 | - return $session->get($this->getSessionPrefix() . '_term', false); | |
| 237 | + return $session->get($this->getSessionPrefix().'_term', false); | |
| 238 | 238 | } | 
| 239 | 239 | |
| 240 | 240 | /** | 
| @@ -244,7 +244,7 @@ discard block | ||
| 244 | 244 | * @param string $term | 
| 245 | 245 | */ | 
| 246 | 246 |  	protected function setSearchTerm(SessionInterface $session, $term) { | 
| 247 | - $session->set($this->getSessionPrefix() . '_term', $term); | |
| 247 | + $session->set($this->getSessionPrefix().'_term', $term); | |
| 248 | 248 | } | 
| 249 | 249 | |
| 250 | 250 | } | 
| 251 | 251 | \ No newline at end of file | 
| @@ -16,7 +16,7 @@ discard block | ||
| 16 | 16 | |
| 17 | 17 |  class FacetSetAdapterTest extends \PHPUnit\Framework\TestCase { | 
| 18 | 18 | |
| 19 | -	public function testAddFacetValue(){ | |
| 19 | +	public function testAddFacetValue() { | |
| 20 | 20 | $facets = new FacetSetAdapter(array()); | 
| 21 | 21 | $this->assertCount(0, $facets); | 
| 22 | 22 | $facets->addFacetValue(Document::FIELD_AUTHOR, 'Oliver Kotte'); | 
| @@ -26,13 +26,13 @@ discard block | ||
| 26 | 26 | $this->assertCount(1, $facets); | 
| 27 | 27 | $this->assertCount(2, $facets->getFacet(Document::FIELD_AUTHOR)); | 
| 28 | 28 | |
| 29 | -		foreach($facets as $facetKey => $facetValues){ | |
| 29 | +		foreach ($facets as $facetKey => $facetValues) { | |
| 30 | 30 | $this->assertEquals(Document::FIELD_AUTHOR, $facetKey); | 
| 31 | 31 | $this->assertCount(2, $facetValues); | 
| 32 | 32 | } | 
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | -	public function testGetFacet(){ | |
| 35 | +	public function testGetFacet() { | |
| 36 | 36 | $facets = new FacetSetAdapter(array()); | 
| 37 | 37 | $this->assertCount(0, $facets); | 
| 38 | 38 |  		$this->assertNull($facets->getFacet('NotExisting')); |