Skip to content

Commit

Permalink
Keep only the most complete data
Browse files Browse the repository at this point in the history
  • Loading branch information
XavRsl committed Jul 17, 2018
1 parent 7ebf932 commit cfa057f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Models/Journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public function add(array $journal): array
{
foreach ($journal as $key => $value) {
if ($this->shouldKeepAttribute($key, $value)) {
if (is_array($value)) {
$value = array_unique($value);
}
$this->list[$key] = $value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function shouldKeepAttribute(string $key, $value): bool
return true;
}

return $function($this->list[$key]) > $function($value);
return $function($this->list[$key]) < $function($value);
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/Integration/RegressionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace PubPeerFoundation\PublicationDataExtractor\Test\Integration;

use PubPeerFoundation\PublicationDataExtractor\Fetcher;
use PubPeerFoundation\PublicationDataExtractor\Test\TestCase;
use PubPeerFoundation\PublicationDataExtractor\IdentifierResolver;

class RegressionTest extends TestCase
{
/** @test */
public function it_can_extract_issns()
{
$identifier = new IdentifierResolver('10.1002/0471142727.mb0418s103');
$dataFetcher = new Fetcher($identifier->handle());

$output = $dataFetcher->fetch();

$this->assertArrayIsValid($output->getData());

$issnIdentifiers = array_filter($output->getData()['identifiers'], function ($identifier) {
return 'issn' === $identifier['type'];
});

$this->assertCount(1, $issnIdentifiers);
$this->assertTrue('John Wiley & Sons, Inc.' === $output->getData()['journal']['publisher']);
$this->assertCount(1, $output->getData()['journal']['issn']);
}
}

0 comments on commit cfa057f

Please sign in to comment.