Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from lordthorzonus/analysis-qg6V7w
Browse files Browse the repository at this point in the history
Applied fixes from StyleCI
  • Loading branch information
lordthorzonus committed Jun 27, 2016
2 parents 6d67f1f + 929de7b commit 7c0397b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/ActiveRecord/Searchable.php
Expand Up @@ -115,7 +115,7 @@ public function updateInIndices()
public static function reindex()
{
$manager = static::getAlgoliaManager();

$manager->reindex(__CLASS__);
}

Expand Down
22 changes: 9 additions & 13 deletions src/AlgoliaManager.php
Expand Up @@ -152,7 +152,7 @@ public function pushMultipleToIndices(array $searchableModels)
$response = [];

foreach ($indices as $index) {
/** @var Index $index */
/* @var Index $index */
$response[$index->indexName] = $index->addObjects($algoliaRecords);
}

Expand Down Expand Up @@ -193,7 +193,7 @@ public function updateMultipleInIndices(array $searchableModels)
$response = [];

foreach ($indices as $index) {
/** @var Index $index */
/* @var Index $index */
$response[$index->indexName] = $index->saveObjects($algoliaRecords);
}

Expand Down Expand Up @@ -261,7 +261,6 @@ public function reindex($className)
$temporaryIndex->setSettings($settings);

$response[$index->indexName] = $this->moveIndex($temporaryIndexName, $index->indexName);

}

return $response;
Expand Down Expand Up @@ -319,15 +318,15 @@ private function checkImplementsSearchableInterface($class)

/**
* Returns the name of the class for given object.
*
*
* @param $class
*
*
* @return string
*/
private function getClassName($class)
{
$reflectionClass = new \ReflectionClass($class);

return $reflectionClass->name;
}

Expand All @@ -342,17 +341,15 @@ private function initIndices(SearchableInterface $searchableModel)
{
$indexNames = $searchableModel->getIndices();

$indices = array_map(function($indexName){

if($this->env !== null){
$indices = array_map(function ($indexName) {
if ($this->env !== null) {
$indexName = $this->env . '_' . $indexName;
}

return $this->initIndex($indexName);
}, $indexNames);

return $indices;

}

/**
Expand All @@ -371,15 +368,14 @@ private function getIndicesAndAlgoliaRecordsFromSearchableModelArray(array $sear

$algoliaRecords = array_map(function ($searchableModel) use ($arrayType) {
/** @var $searchableModel SearchableInterface */
if (!$searchableModel instanceof $arrayType) {
throw new \InvalidArgumentException("The given array should not contain multiple different classes");
if (! $searchableModel instanceof $arrayType) {
throw new \InvalidArgumentException('The given array should not contain multiple different classes');
}

$algoliaRecord = $searchableModel->getAlgoliaRecord();
$algoliaRecord['objectID'] = $searchableModel->getObjectID();

return $algoliaRecord;

}, $searchableModels);

return [$indices, $algoliaRecords];
Expand Down
5 changes: 1 addition & 4 deletions tests/Helpers/DummyModel.php
@@ -1,19 +1,16 @@
<?php


namespace leinonen\Yii2Algolia\Tests\Helpers;


use leinonen\Yii2Algolia\SearchableInterface;
use yii\base\Model;

class DummyModel extends Model implements SearchableInterface
{

public $test;
public $otherProperty;
public $id;

/**
* Returns an array of indices for this model.
*
Expand Down
1 change: 0 additions & 1 deletion tests/Helpers/SynchronousAutoIndexedDummyModel.php
Expand Up @@ -18,4 +18,3 @@ public function behaviors()
];
}
}

8 changes: 4 additions & 4 deletions tests/Integration/AlgoliaManagerTest.php
Expand Up @@ -92,12 +92,12 @@ public function it_uses_right_index_according_to_given_env()
'class' => AlgoliaComponent::class,
'applicationId' => getenv('ALGOLIA_ID'),
'apiKey' => getenv('ALGOLIA_KEY'),
'env' => 'test'
'env' => 'test',
],
],
]);

$algoliaManager = Yii::$container->get(AlgoliaManager::class);
$algoliaManager = Yii::$container->get(AlgoliaManager::class);

$searchableObject = $this->makeDummyActiveRecord();
$searchableObject->shouldReceive('getIndices')->andReturn(['index']);
Expand Down Expand Up @@ -139,7 +139,7 @@ private function deleteIndex($index)
$this->assertArrayHasKey('deletedAt', $deleteResult);
$this->assertArrayHasKey('taskID', $deleteResult);
}

/**
* Returns a dummy Yii's Base Mdoel object.
*
Expand All @@ -152,7 +152,7 @@ private function makeDummyModel($objectId = 1)
return new DummyModel([
'id' => $objectId,
'test' => 'test',
'otherProperty' => 'otherProperty'
'otherProperty' => 'otherProperty',
]);
}

Expand Down
11 changes: 5 additions & 6 deletions tests/Unit/AlgoliaManagerTest.php
Expand Up @@ -296,7 +296,7 @@ public function it_can_update_multiple_searchable_objects_in_a_batch()
$manager = $this->getManager($mockAlgoliaClient, null, $mockAlgoliaFactory);
$manager->updateMultipleInIndices($arrayOfTestModels);
}

/**
* @test
* @expectedException \InvalidArgumentException
Expand All @@ -322,7 +322,7 @@ public function it_should_throw_an_exception_if_multiple_different_objects_are_u
$mockAlgoliaFactory->shouldReceive('makeSearchableObject')->with($testModelClassName)->andReturn($testModel);

$manager = $this->getManager($mockAlgoliaClient, null, $mockAlgoliaFactory);
$manager->updateMultipleInIndices([$testModel,$testModel2]);
$manager->updateMultipleInIndices([$testModel, $testModel2]);
}

/**
Expand Down Expand Up @@ -350,7 +350,7 @@ public function it_should_throw_an_exception_if_multiple_different_objects_are_u
$mockAlgoliaFactory->shouldReceive('makeSearchableObject')->with($testModelClassName)->andReturn($testModel);

$manager = $this->getManager($mockAlgoliaClient, null, $mockAlgoliaFactory);
$manager->pushMultipleToIndices([$testModel,$testModel2]);
$manager->pushMultipleToIndices([$testModel, $testModel2]);
}

/**
Expand All @@ -373,11 +373,11 @@ protected function getManager($client, $activeRecordFactory = null, $algoliaFact
];
}

if($activeRecordFactory === null) {
if ($activeRecordFactory === null) {
$activeRecordFactory = m::mock(ActiveRecordFactory::class);
}

if($algoliaFactory === null) {
if ($algoliaFactory === null) {
$algoliaFactory = m::mock(AlgoliaFactory::class);
}

Expand All @@ -388,4 +388,3 @@ protected function getManager($client, $activeRecordFactory = null, $algoliaFact
return $manager;
}
}

0 comments on commit 7c0397b

Please sign in to comment.