Skip to content

Commit

Permalink
Simplify LibGuidesProfile config handling and test; fix types. (vufin…
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz authored Dec 3, 2024
1 parent 1f82179 commit 5292feb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
20 changes: 10 additions & 10 deletions module/VuFind/src/VuFind/Recommend/LibGuidesProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class LibGuidesProfile implements
/**
* List of strategies enabled to find a matching LibGuides profile
*
* @var int
* @var array
*/
protected $strategies = [];

Expand Down Expand Up @@ -119,14 +119,14 @@ public function __construct(
// Cache the data related to profiles for up to 10 minutes:
$this->cacheLifetime = intval($config->GetAccounts->cache_lifetime ?? 600);

if ($profile = $config->Profile) {
$strategies = $profile->get('strategies', []);
if ($profile = $config->Profile->toArray()) {
$strategies = $profile['strategies'] ?? [];
$this->strategies = is_string($strategies) ? [$strategies] : $strategies;

$this->callNumberToAlias = $profile->call_numbers ? $profile->call_numbers->toArray() : [];
$this->aliasToAccountId = $profile->profile_aliases ? $profile->profile_aliases->toArray() : [];
$this->callNumberField = $profile->get('call_number_field', 'callnumber-first');
$this->callNumberLength = $profile->get('call_number_length', 3);
$this->callNumberToAlias = $profile['call_numbers'] ?? [];
$this->aliasToAccountId = $profile['profile_aliases'] ?? [];
$this->callNumberField = $profile['call_number_field'] ?? 'callnumber-first';
$this->callNumberLength = $profile['call_number_length'] ?? 3;
}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ public function process($results)
/**
* Get terms related to the query.
*
* @return array
* @return mixed
*/
public function getResults()
{
Expand Down Expand Up @@ -211,7 +211,7 @@ public function getResults()
*
* @param \VuFind\Search\Base\Results $results Search results object
*
* @return array LibGuides account
* @return mixed LibGuides account object or false
*/
protected function findBestMatchByCallNumber($results)
{
Expand Down Expand Up @@ -269,7 +269,7 @@ protected function findBestMatchByCallNumber($results)
*
* @param \VuFind\Search\Base\Results $results Search results object
*
* @return array LibGuides account
* @return mixed LibGuides account object or false
*/
protected function findBestMatchBySubject($results)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class LibGuidesProfileTest extends \PHPUnit\Framework\TestCase
public function setUp(): void
{
// Mock LibGuides connector
$this->connector = $this->getMockBuilder(LibGuides::class)
->disableOriginalConstructor()
->getMock();
$this->connector = $this->createMock(LibGuides::class);
$accountsFixture = $this->getFixture('libguides/api/accounts');
$accounts = json_decode(substr($accountsFixture, strpos($accountsFixture, '[')));
$this->connector->method('getAccounts')->willReturn($accounts);
Expand Down Expand Up @@ -231,9 +229,7 @@ protected function buildQueryResults($queryString, $facets = []): Results
$queryResults = new Results(
$queryParams,
$this->createStub(\VuFindSearch\Service::class),
$this->getMockBuilder(\VuFind\Record\Loader::class)
->disableOriginalConstructor()
->getMock(),
$this->createMock(\VuFind\Record\Loader::class),
null,
$facets
);
Expand Down

0 comments on commit 5292feb

Please sign in to comment.