Skip to content

Commit

Permalink
rector changes
Browse files Browse the repository at this point in the history
  • Loading branch information
limenet committed Apr 7, 2023
1 parent 8ef62df commit a9e33b2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
10 changes: 8 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src'
]);

$rectorConfig->skip([
CountArrayToEmptyArrayComparisonRector::class,
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81
LevelSetList::UP_TO_PHP_81,
SetList::CODE_QUALITY
]);
};
8 changes: 7 additions & 1 deletion src/Command/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Process\Process;
use Valantic\ElasticaBridgeBundle\DocumentType\Index\IndexDocumentInterface;
use Valantic\ElasticaBridgeBundle\Elastica\Client\ElasticsearchClient;
use Valantic\ElasticaBridgeBundle\Exception\Index\BlueGreenIndicesIncorrectlySetupException;
use Valantic\ElasticaBridgeBundle\Index\IndexInterface;
Expand Down Expand Up @@ -236,6 +237,11 @@ protected function checkRandomDocument(ElasticaIndex $index, IndexInterface $ind
$esDocs = $index->search();
$esDoc = $esDocs[random_int(0, $esDocs->count() - 1)]->getDocument();
$indexDocumentInstance = $indexConfig->getIndexDocumentInstance($esDoc);
$this->output->writeln(sprintf('<comment>-> ES %s -> %s %s</comment>', $esDoc->getId(), $indexDocumentInstance ? $indexDocumentInstance->getPimcoreElement($esDoc)->getType() : 'FAILED', $indexDocumentInstance ? $indexDocumentInstance->getPimcoreElement($esDoc)->getId() : 'FAILED'));
$this->output->writeln(sprintf(
'<comment>-> ES %s -> %s %s</comment>',
$esDoc->getId(),
$indexDocumentInstance instanceof IndexDocumentInterface ? $indexDocumentInstance->getPimcoreElement($esDoc)->getType() : 'FAILED',
$indexDocumentInstance instanceof IndexDocumentInterface ? $indexDocumentInstance->getPimcoreElement($esDoc)->getId() : 'FAILED'
));
}
}
2 changes: 1 addition & 1 deletion src/Command/PopulateIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function populateIndex(IndexInterface $indexConfig, ElasticaIndex $esI
$this->output->writeln('');
$this->output->writeln(sprintf('In %s line %d', $throwable->getFile(), $throwable->getLine()));
$this->output->writeln('');
if ($throwable->getMessage()) {
if (!empty($throwable->getMessage())) {
$this->output->writeln($throwable->getMessage());
$this->output->writeln('');
}
Expand Down
6 changes: 3 additions & 3 deletions src/DocumentType/AbstractDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getListingClass(): string
return $this->getSubType() . '\Listing';
}

if (in_array($this->getType(), [DocumentInterface::TYPE_ASSET], true)) {
if ($this->getType() === DocumentInterface::TYPE_ASSET) {
return AssetListing::class;
}

Expand All @@ -116,7 +116,7 @@ public function getPimcoreElement(ElasticaDocument $document): AbstractElement
$pimcoreId = $this->getPimcoreId($document);
$element = Concrete::getById($pimcoreId);

if ($element === null) {
if (!$element instanceof Concrete) {
throw new PimcoreElementNotFoundException($pimcoreId);
}

Expand All @@ -129,7 +129,7 @@ public function getPimcoreElement(ElasticaDocument $document): AbstractElement
$pimcoreId = $this->getPimcoreId($document);
$element = $documentTypeClass::getById($pimcoreId);

if ($element === null) {
if (!$element instanceof PimcoreDocument) {
throw new PimcoreElementNotFoundException($pimcoreId);
}

Expand Down
6 changes: 3 additions & 3 deletions src/EventListener/Pimcore/AbstractListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function decideAction(AbstractElement $element): void
foreach ($this->indexHelper->matchingIndicesForElement($this->indexRepository->flattened(), $element) as $index) {
$indexDocument = $index->findIndexDocumentInstanceByPimcore($element);

if (!$indexDocument) {
if (!$indexDocument instanceof IndexDocumentInterface) {
continue;
}

Expand Down Expand Up @@ -94,7 +94,7 @@ protected function ensurePresent(AbstractElement $element): void
foreach ($this->indexHelper->matchingIndicesForElement($this->indexRepository->flattened(), $element) as $index) {
$indexDocument = $index->findIndexDocumentInstanceByPimcore($element);

if (!$indexDocument) {
if (!$indexDocument instanceof IndexDocumentInterface) {
continue;
}

Expand All @@ -121,7 +121,7 @@ protected function ensureMissing(AbstractElement $element): void
foreach ($this->indexHelper->matchingIndicesForElement($this->indexRepository->flattened(), $element) as $index) {
$indexDocument = $index->findIndexDocumentInstanceByPimcore($element);

if (!$indexDocument) {
if (!$indexDocument instanceof IndexDocumentInterface) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Index/AbstractIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getElasticaIndex(): Index

public function isElementAllowedInIndex(AbstractElement $element): bool
{
return $this->findIndexDocumentInstanceByPimcore($element) !== null;
return $this->findIndexDocumentInstanceByPimcore($element) instanceof IndexDocumentInterface;
}

public function getIndexDocumentInstance(Document $document): ?IndexDocumentInterface
Expand All @@ -97,7 +97,7 @@ public function getDocumentFromElement(AbstractElement $element): ?Document
{
$documentInstance = $this->findIndexDocumentInstanceByPimcore($element);

if (!$documentInstance) {
if (!$documentInstance instanceof IndexDocumentInterface) {
return null;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ public function documentResultToElements(ResultSet $result): array
foreach ($result->getDocuments() as $esDoc) {
$instance = $this->getIndexDocumentInstance($esDoc);

if (!$instance) {
if (!$instance instanceof IndexDocumentInterface) {
continue;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ final public function getBlueGreenActiveSuffix(): string

$aliases = array_filter(
$this->client->request('_aliases')->getData(),
fn (array $datum): bool => in_array($this->getName(), array_keys($datum['aliases']), true)
fn (array $datum): bool => array_key_exists($this->getName(), $datum['aliases'])
);

if (count($aliases) !== 1) {
Expand Down

0 comments on commit a9e33b2

Please sign in to comment.