From 93c29bd6a20f31430c4be1c291efe137380eae10 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Wed, 17 Aug 2022 20:08:47 +1200 Subject: [PATCH] chore: php cs lint, remove outdated author list --- .editorconfig | 26 +++++++ composer.json | 23 +------ phpcs.xml.dist | 4 +- src/ElasticaPercolateService.php | 13 ++-- src/ElasticaService.php | 111 +++++++++++++++++------------- src/Jobs/ReindexAfterWriteJob.php | 13 ++-- src/ManyManyList.php | 9 ++- src/PaginatedList.php | 2 +- src/ReindexTask.php | 1 + src/ResultList.php | 26 ++++--- src/Searchable.php | 85 +++++++++++++++-------- tests/ElasticaServiceTest.php | 8 ++- 12 files changed, 192 insertions(+), 129 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ee325e2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +# For more information about the properties used in +# this file, please see the EditorConfig documentation: +# http://editorconfig.org/ + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,js,json,css,scss,feature}] +indent_size = 2 +indent_style = space + +[composer.json] +indent_size = 4 + +# Don't perform any clean-up on thirdparty files +[thirdparty/**] +trim_trailing_whitespace = false +insert_final_newline = false diff --git a/composer.json b/composer.json index 66fea7f..3b1005b 100644 --- a/composer.json +++ b/composer.json @@ -10,35 +10,18 @@ "elastica" ], "license": "BSD-3-Clause", - "authors": [ - { - "name": "Andrew Short", - "email": "andrewjshort@gmail.com" - }, - { - "name": "Marcus Nyeholt", - "email": "marcus@silverstripe.com.au" - }, - { - "name": "Glenn Bautista", - "email": "glenn@vinta.tech" - }, - { - "name": "Ben Dubuisson", - "email": "ben.dubuisson@heyday.co.nz" - } - ], "support": { "issues": "http://github.com/heyday/silverstripe-elastica/issues" }, "require": { - "php": ">=7.2", + "php": ">=7.4", "ruflin/elastica": "^7", "elasticsearch/elasticsearch": ">=7.3.0", "symbiote/silverstripe-queuedjobs": "^4" }, "require-dev": { - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "^3.4" }, "autoload": { "psr-4": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c3facac..2180341 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,10 +1,12 @@ CodeSniffer ruleset for SilverStripe coding conventions. - + src + tests + diff --git a/src/ElasticaPercolateService.php b/src/ElasticaPercolateService.php index fb7c1e0..6bb99cd 100644 --- a/src/ElasticaPercolateService.php +++ b/src/ElasticaPercolateService.php @@ -13,12 +13,13 @@ class ElasticaPercolateService extends ElasticaService /** * ElasticaPercolateService constructor. - * @param Client $client + * + * @param Client $client * @param $indexName * @param LoggerInterface|null $logger - * @param null $indexingMemory - * @param string $searchableExtensionClassName - * @param null $doctypeToPercolate + * @param null $indexingMemory + * @param string $searchableExtensionClassName + * @param null $doctypeToPercolate */ public function __construct( Client $client, @@ -34,7 +35,7 @@ public function __construct( } /** - * @param Searchable $record + * @param Searchable $record * @return Response|null * @throws Exception */ @@ -47,7 +48,7 @@ public function index($record) } /** - * @param Searchable $record + * @param Searchable $record * @return Response|null * @throws Exception */ diff --git a/src/ElasticaService.php b/src/ElasticaService.php index 3893c63..c58a76e 100644 --- a/src/ElasticaService.php +++ b/src/ElasticaService.php @@ -78,8 +78,8 @@ class ElasticaService * * @param Client $client * @param string $indexName - * @param LoggerInterface|null $logger Increases the memory limit while indexing. - * @param string $indexingMemory A memory limit string, such as "64M". + * @param LoggerInterface|null $logger Increases the memory limit while indexing. + * @param string $indexingMemory A memory limit string, such as "64M". * @param string $searchableExtensionClassName */ public function __construct( @@ -122,9 +122,10 @@ protected function getIndexConfig() /** * Performs a search query and returns either a ResultList (SS template compatible) or an Elastica\ResultSet - * @param Query|string|array $query - * @param array $options Options defined in \Elastica\Search - * @param bool $returnResultList + * + * @param Query|string|array $query + * @param array $options Options defined in \Elastica\Search + * @param bool $returnResultList * @return ResultList | ResultSet */ public function search($query, $options = null, $returnResultList = true) @@ -142,12 +143,14 @@ public function search($query, $options = null, $returnResultList = true) */ public function createIndex() { - return $this->runQuery(function () { - $index = $this->getIndex(); - $config = $this->getIndexConfig() ?: []; - $forceRecreate = !empty($config); - return $index->create($config, $forceRecreate); - }); + return $this->runQuery( + function () { + $index = $this->getIndex(); + $config = $this->getIndexConfig() ?: []; + $forceRecreate = !empty($config); + return $index->create($config, $forceRecreate); + } + ); } /** @@ -157,16 +160,18 @@ public function createIndex() */ public function deleteIndex() { - return $this->runQuery(function () { - $index = $this->getIndex(); - return $index->delete(); - }); + return $this->runQuery( + function () { + $index = $this->getIndex(); + return $index->delete(); + } + ); } /** * Either creates or updates a record in the index. * - * @param Searchable|DataObject $record + * @param Searchable|DataObject $record * @return Response|null|bool Return response, or true if batched * @throws Exception */ @@ -197,11 +202,13 @@ public function index($record) } // Add document - return $this->runQuery(function () use ($index, $document) { - $response = $index->addDocument($document); - $index->refresh(); - return $response; - }); + return $this->runQuery( + function () use ($index, $document) { + $response = $index->addDocument($document); + $index->refresh(); + return $response; + } + ); } /** @@ -219,8 +226,8 @@ protected function isBatching() * For example, you might call batch with a closure that initiates ->index() on 20 records. * On the conclusion of this closure, those 20 updates will be batched together into a single update * - * @param callable $callback Callback within which to batch updates - * @param int $documentsProcessed Number of documents processed during this batch + * @param callable $callback Callback within which to batch updates + * @param int $documentsProcessed Number of documents processed during this batch * @return mixed result of $callback * @throws Exception */ @@ -242,7 +249,7 @@ public function batch(callable $callback, &$documentsProcessed = 0) /** * Process a batch update * - * @param Document[][][] $batch List of updates for this batch, grouped by type + * @param Document[][][] $batch List of updates for this batch, grouped by type * @return int Number of documents updated in this batch */ protected function flushBatch($batch) @@ -252,13 +259,13 @@ protected function flushBatch($batch) // process batches $index = null; foreach ($batch as $type => $changes) { - $typeObject = null; foreach ($changes as $action => $documents) { if (empty($documents)) { continue; } $index = $index ?: $this->getIndex(); $documentsProcessed += count($documents); + switch ($action) { case self::UPDATES: $index->addDocuments($documents); @@ -275,18 +282,20 @@ protected function flushBatch($batch) } } } + // Refresh if any documents updated if ($documentsProcessed && $index) { $index->refresh(); } + return $documentsProcessed; } /** * Add document to batch query * - * @param string $type elasticsearch type name - * @param string $action self::DELETES or self::UPDATES + * @param string $type elasticsearch type name + * @param string $action self::DELETES or self::UPDATES * @param Document $document */ protected function batchDocument($type, $action, $document) @@ -314,7 +323,7 @@ protected function batchDocument($type, $action, $document) } /** - * @param Searchable|DataObject $record + * @param Searchable|DataObject $record * @return Response|null|bool Response, or true if batched * @throws Exception */ @@ -348,7 +357,7 @@ public function remove($record) /** * Creates the index and the type mappings. * - * @param bool $recreate + * @param bool $recreate * @throws Exception */ public function define($recreate = false) @@ -365,7 +374,9 @@ public function define($recreate = false) } foreach ($this->getIndexedClasses() as $class) { - /** @var Searchable */ + /** + * @var Searchable + */ $sng = singleton($class); $props = $sng->getElasticaMapping(); @@ -375,29 +386,31 @@ public function define($recreate = false) /** * Re-indexes each record in the index. + * * @throws Exception */ public function refresh() { - Versioned::withVersionedMode(function () { - Versioned::set_stage(Versioned::LIVE); - - foreach ($this->getIndexedClasses() as $class) { - - foreach (DataObject::get($class) as $record) { - // Only index records with Show In Search enabled, or those that don't expose that fielid - if (!$record->hasField('ShowInSearch') || $record->ShowInSearch) { - if ($this->index($record)) { - $this->printActionMessage($record, 'INDEXED'); - } - } else { - if ($this->remove($record)) { - $this->printActionMessage($record, 'REMOVED'); + Versioned::withVersionedMode( + function () { + Versioned::set_stage(Versioned::LIVE); + + foreach ($this->getIndexedClasses() as $class) { + foreach (DataObject::get($class) as $record) { + // Only index records with Show In Search enabled, or those that don't expose that fielid + if (!$record->hasField('ShowInSearch') || $record->ShowInSearch) { + if ($this->index($record)) { + $this->printActionMessage($record, 'INDEXED'); + } + } else { + if ($this->remove($record)) { + $this->printActionMessage($record, 'REMOVED'); + } } } } } - }); + ); } /** @@ -438,7 +451,7 @@ protected function printActionMessage(DataObject $record, $action) * If a logger is configured, log the exception there. * Otherwise the exception is thrown * - * @param Exception $exception + * @param Exception $exception * @throws Exception */ protected function exception($exception) @@ -461,7 +474,7 @@ protected function exception($exception) /** * Check if response has any errors * - * @param Response|null $response + * @param Response|null $response * @throws Exception */ protected function logResponse(Response $response = null) @@ -475,7 +488,7 @@ protected function logResponse(Response $response = null) $data = $response->getData(); $errorMessage = $data['message'] ?? $response->getErrorMessage() - ?: sprintf("HTTP %d error", $response->getStatus()); + ?: sprintf("HTTP %d error", $response->getStatus()); $message = "Elastica server error: $errorMessage"; // If no logger specified expose error normally @@ -490,7 +503,7 @@ protected function logResponse(Response $response = null) /** * Run elastic search query * - * @param callable $callback A callback that generates an Elastica Response object + * @param callable $callback A callback that generates an Elastica Response object * @return Response The response * @throws Exception */ diff --git a/src/Jobs/ReindexAfterWriteJob.php b/src/Jobs/ReindexAfterWriteJob.php index 1bdf392..04948f5 100644 --- a/src/Jobs/ReindexAfterWriteJob.php +++ b/src/Jobs/ReindexAfterWriteJob.php @@ -2,6 +2,7 @@ namespace Heyday\Elastica\Jobs; +use Heyday\Elastica\Searchable; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Injector\Injector; use SilverStripe\ORM\DataList; @@ -12,14 +13,15 @@ /** * Class ReindexAfterWriteJob + * * @package Heyday\Elastica\Jobs */ class ReindexAfterWriteJob extends AbstractQueuedJob implements QueuedJob { /** - * * get the instance to reindex and the service * ReindexAfterWriteJob constructor. + * * @param int $id * @param string $class */ @@ -100,11 +102,9 @@ protected function updateDependentClasses($versionToIndex, $service) $list = DataList::create($class); foreach ($list as $object) { - if ($object instanceof DataObject && - $object->hasExtension('Heyday\\Elastica\\Searchable') - ) { - if (($object instanceof SiteTree && $object->ShowInSearch) || - (!$object instanceof SiteTree) + if ($object instanceof DataObject && $object->hasExtension(Searchable::class)) { + if (($object instanceof SiteTree && $object->ShowInSearch) + || (!$object instanceof SiteTree) ) { $service->index($object); } else { @@ -119,6 +119,7 @@ protected function updateDependentClasses($versionToIndex, $service) /** * Return an array of dependant class names. These are classes that need to be reindexed when an instance of the * extended class is updated or when a relationship to it changes. + * * @return array|mixed */ public function dependentClasses($versionToIndex) diff --git a/src/ManyManyList.php b/src/ManyManyList.php index 5b9fa37..65687dc 100644 --- a/src/ManyManyList.php +++ b/src/ManyManyList.php @@ -10,13 +10,14 @@ /** * A drop in replacement for the default ManyManyList. * This class allows us to invalidate records when many many relations change. + * * @package Heyday\Elastica\SilverStripe */ class ManyManyList extends SilverStripeManyManyList { /** - * @param mixed $item - * @param array $extraFields + * @param mixed $item + * @param array $extraFields * @throws Exception */ public function add($item, $extraFields = []) @@ -53,7 +54,9 @@ public function removeAll() parent::removeAll(); $items = DataList::create($this->dataClass); - /** @var DataObject $item */ + /** + * @var DataObject $item +*/ foreach ($items as $item) { $item->extend('onAfterManyManyRelationRemove'); } diff --git a/src/PaginatedList.php b/src/PaginatedList.php index c4a7323..41cbfed 100644 --- a/src/PaginatedList.php +++ b/src/PaginatedList.php @@ -4,6 +4,7 @@ /** * Class PaginatedList + * * @package Heyday\Elastica */ class PaginatedList extends \SilverStripe\ORM\PaginatedList @@ -41,5 +42,4 @@ public function LastItem() return parent::getTotalItems(); } - } diff --git a/src/ReindexTask.php b/src/ReindexTask.php index 83c522b..01aed2c 100644 --- a/src/ReindexTask.php +++ b/src/ReindexTask.php @@ -24,6 +24,7 @@ class ReindexTask extends BuildTask /** * ReindexTask constructor. + * * @param ElasticaService $service */ public function __construct(ElasticaService $service) diff --git a/src/ResultList.php b/src/ResultList.php index 6ea5aeb..219039d 100644 --- a/src/ResultList.php +++ b/src/ResultList.php @@ -51,18 +51,20 @@ public function __construct(Index $index, Query $query, LoggerInterface $logger parent::__construct(); //Optimise the query by just getting back the ids and types - $query->setStoredFields([ + $query->setStoredFields( + [ '_id', Searchable::TYPE_FIELD, 'highlight' - ]); + ] + ); if (Versioned::get_reading_mode() == Versioned::LIVE) { $publishedFilter = $query->hasParam('post_filter') ? $query->getParam('post_filter') : null; if (!$publishedFilter) { $publishedFilter = new Query\BoolQuery(); - } else if (!($publishedFilter instanceof Query\BoolQuery)) { + } elseif (!($publishedFilter instanceof Query\BoolQuery)) { throw new \RuntimeException("Please use a bool query for your post_filter"); } @@ -93,7 +95,9 @@ public function __clone() */ public function getIDs() { - /** @var $found Result[] */ + /** + * @var $found Result[] +*/ $found = $this->getResults(); $ids = []; @@ -148,8 +152,8 @@ public function getIterator() } /** - * @param int $limit - * @param int $offset + * @param int $limit + * @param int $offset * @return ResultList */ public function limit($limit, $offset = 0) @@ -163,7 +167,7 @@ public function limit($limit, $offset = 0) } /** - * @param array $sortArgs + * @param array $sortArgs * @return ResultList */ public function sort(array $sortArgs) @@ -321,8 +325,8 @@ public function last() /** - * @param string $key - * @param string $title + * @param string $key + * @param string $title * @return Map */ public function map($key = 'ID', $title = 'Title') @@ -331,7 +335,7 @@ public function map($key = 'ID', $title = 'Title') } /** - * @param string $col + * @param string $col * @return array */ public function column($col = 'ID') @@ -350,7 +354,7 @@ public function column($col = 'ID') } /** - * @param callable $callback + * @param callable $callback * @return $this */ public function each($callback) diff --git a/src/Searchable.php b/src/Searchable.php index 0c2d46b..ad6189f 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -27,19 +27,21 @@ class Searchable extends DataExtension { /** * Key used by elastic to determine the type of document. + * * @var string */ public const TYPE_FIELD = 'type'; /** * Key added to every indexed document to determine published status. + * * @var string */ public const PUBLISHED_FIELD = 'SS_Published'; /** * @config - * @var array + * @var array */ private static $elasticsearch_field_mappings = [ 'PrimaryKey' => 'integer', @@ -64,9 +66,10 @@ class Searchable extends DataExtension /** * ElasticSearch 7.0 compatibility: Use a custom 'type' field instead of deprecated _type + * * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html#_custom_type_field * - * @var array + * @var array * @config */ private static $indexed_fields = [ @@ -83,7 +86,7 @@ class Searchable extends DataExtension /** * @config - * @var array + * @var array */ private static $exclude_relations = []; @@ -164,6 +167,7 @@ public function indexedFields() /** * Return an array of dependant class names. These are classes that need to be reindexed when an instance of the * extended class is updated or when a relationship to it changes. + * * @return array */ public function dependentClasses() @@ -201,6 +205,7 @@ public function getElasticaPublishedStatus() /** * Replacing the SS3 inheritedDatabaseFields() method + * * @return array */ public function inheritedDatabaseFields() @@ -250,7 +255,8 @@ public function getElasticaFields() /** * Clean up the data type name - * @param string $dataType + * + * @param string $dataType * @return string */ protected function stripDataTypeParameters($dataType) @@ -259,7 +265,7 @@ protected function stripDataTypeParameters($dataType) } /** - * @param string $dateString + * @param string $dateString * @return string|null */ protected function formatDate($dateString) @@ -273,7 +279,7 @@ protected function formatDate($dateString) /** * Coerce strings into integers * - * @param mixed $intString + * @param mixed $intString * @return int|null */ protected function formatInt($intString) @@ -287,7 +293,7 @@ protected function formatInt($intString) /** * Coerce strings into floats * - * @param mixed $floatString + * @param mixed $floatString * @return float|null */ protected function formatFloat($floatString) @@ -373,6 +379,7 @@ public function getSearchableFieldValues() /** * Updates the record in the search index, or removes it as necessary. + * * @throws Exception */ public function onAfterWrite() @@ -387,7 +394,7 @@ public function onAfterWrite() /** * reIndex related content * - * @param string $stage + * @param string $stage * @throws Exception */ public function reIndex($stage = Versioned::LIVE) @@ -415,8 +422,8 @@ public function reIndex($stage = Versioned::LIVE) /** * Batch update all documents attached to the index for this record * - * @param callable $callback - * @param int $documentsProcessed + * @param callable $callback + * @param int $documentsProcessed * @return mixed * @throws Exception */ @@ -427,6 +434,7 @@ public function batchIndex(callable $callback, &$documentsProcessed = 0) /** * Removes the record from the search index. + * * @throws Exception */ public function onBeforeDelete() @@ -441,6 +449,7 @@ public function onBeforeDelete() /** * Update dependent classes after the extended object has been removed from a ManyManyList + * * @throws Exception */ public function onAfterManyManyRelationRemove() @@ -454,6 +463,7 @@ public function onAfterManyManyRelationRemove() /** * Update dependent classes after the extended object has been added to a ManyManyList + * * @throws Exception */ public function onAfterManyManyRelationAdd() @@ -467,6 +477,7 @@ public function onAfterManyManyRelationAdd() /** * Updates the records of all instances of dependent classes. + * * @throws Exception */ protected function updateDependentClasses() @@ -492,7 +503,7 @@ protected function updateDependentClasses() /** * Serialise a file attachment * - * @param File $file + * @param File $file * @return array Value for 'attachment' type */ protected function createAttachment(File $file) @@ -510,9 +521,9 @@ protected function createAttachment(File $file) /** * Build searchable spec for a given field * - * @param string $fieldName - * @param array $params Spec params - * @param string $className + * @param string $fieldName + * @param array $params Spec params + * @param string $className * @return array */ protected function getSearchableFieldsForRelation($fieldName, $params, $className) @@ -523,7 +534,9 @@ protected function getSearchableFieldsForRelation($fieldName, $params, $classNam } // Skip if this relation class has no elasticsearch content - /** @var DataObject|Searchable $related */ + /** + * @var DataObject|Searchable $related + */ $related = DataObject::singleton($className); if (!$related->hasExtension(Searchable::class)) { return []; @@ -559,16 +572,18 @@ protected function getSearchableFieldsForRelation($fieldName, $params, $classNam /** * Get all fields from a relation on a parent object * - * @param string $fieldName - * @param array $params Spec params - * @param string $className + * @param string $fieldName + * @param array $params Spec params + * @param string $className * @return array */ protected function getSearchableFieldValuesForRelation($fieldName, $params, $className) { // Detect attachment if (isset($params['type']) && $params['type'] === 'attachment') { - /** @var File $file */ + /** + * @var File $file + */ $file = $this->owner->relField($fieldName); if (!$file instanceof File || !$file->exists()) { return []; @@ -577,7 +592,9 @@ protected function getSearchableFieldValuesForRelation($fieldName, $params, $cla } // Skip if this relation class has no elasticsearch content - /** @var DataObject|Searchable $relatedSingleton */ + /** + * @var DataObject|Searchable $relatedSingleton + */ $relatedSingleton = DataObject::singleton($className); if (!$relatedSingleton->hasExtension(Searchable::class)) { return []; @@ -590,7 +607,9 @@ protected function getSearchableFieldValuesForRelation($fieldName, $params, $cla } // Handle unary relations - /** @var DataObject|Searchable $relatedItem */ + /** + * @var DataObject|Searchable $relatedItem + */ $relatedItem = null; // Handle unary sets $isUnary = $relatedList instanceof DataObject; @@ -604,7 +623,9 @@ protected function getSearchableFieldValuesForRelation($fieldName, $params, $cla // Note: Unary relations are treated as a single-length list if (isset($params['type']) && $params['type'] === 'nested') { $relationValues = []; - /** @var DataObject|Searchable $relationListItem */ + /** + * @var DataObject|Searchable $relationListItem + */ foreach ($relatedList as $relationListItem) { $relationValues[] = $relationListItem->getSearchableFieldValues(); } @@ -647,7 +668,7 @@ protected function getSearchableFieldValuesForRelation($fieldName, $params, $cla } /** - * @param $fieldValue + * @param $fieldValue * @return bool */ protected function formatBoolean($fieldValue) @@ -659,17 +680,20 @@ protected function formatBoolean($fieldValue) * Format a scalar value for the index document * Note: Respects array values * - * @param array $params Spec params - * @param mixed $fieldValue + * @param array $params Spec params + * @param mixed $fieldValue * @return mixed */ protected function formatValue($params, $fieldValue) { // Map array of values safely if (is_array($fieldValue)) { - return array_map(function ($value) use ($params) { - return $this->formatValue($params, $value); - }, $fieldValue); + return array_map( + function ($value) use ($params) { + return $this->formatValue($params, $value); + }, + $fieldValue + ); } $type = isset($params['type']) ? $params['type'] : null; @@ -690,8 +714,8 @@ protected function formatValue($params, $fieldValue) /** * Get extra params for a field from the parent document * - * @param string $fieldName - * @param array $params + * @param string $fieldName + * @param array $params * @return array */ protected function getExtraFieldParams($fieldName, $params) @@ -720,6 +744,7 @@ protected function getExtraFieldParams($fieldName, $params) /** * Trigger a queuedjob to update this item. * Require queuedjobs to be setup. + * * @throws ValidationException */ protected function queueReindex() diff --git a/tests/ElasticaServiceTest.php b/tests/ElasticaServiceTest.php index 68bf8d2..bcf54b3 100644 --- a/tests/ElasticaServiceTest.php +++ b/tests/ElasticaServiceTest.php @@ -11,7 +11,9 @@ class ElasticaServiceTest extends SapphireTest { public function testDefineDeletesIndexIfRecreateIsPassed() { - /** @var ElasticaService|PHPUnit_Framework_MockObject_MockObject $service */ + /** + * @var ElasticaService|PHPUnit_Framework_MockObject_MockObject $service +*/ $service = $this->getMockBuilder(ElasticaService::class) ->disableOriginalConstructor() ->setMethods(['getIndex', 'createIndex', 'getIndexedClasses']) @@ -19,7 +21,9 @@ public function testDefineDeletesIndexIfRecreateIsPassed() $service->expects($this->once())->method('getIndexedClasses')->willReturn([]); - /** @var Index|PHPUnit_Framework_MockObject_MockObject $index */ + /** + * @var Index|PHPUnit_Framework_MockObject_MockObject $index +*/ $index = $this->createMock(Index::class); $index->expects($this->exactly(2))->method('exists')->willReturnOnConsecutiveCalls(true, false); $index->expects($this->once())->method('delete');