Skip to content

Commit

Permalink
Merge pull request #260 from elifesciences/support-php-8.x
Browse files Browse the repository at this point in the history
Support PHP 8.x
  • Loading branch information
scottaubrey authored Nov 7, 2024
2 parents 59e4132 + f3c7be2 commit 8c3ca7d
Show file tree
Hide file tree
Showing 24 changed files with 41 additions and 34 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"require": {
"php": "^7.1",
"php": "^7.1 || ^8.0",
"composer/package-versions-deprecated": "1.11.99.2",
"elife/api-client": "^1.0",
"guzzlehttp/promises": "^1.0",
Expand All @@ -32,7 +32,7 @@
"mtdowling/jmespath.php": "^2.0",
"phpspec/phpspec": "^5.1 || ^6.3 || ^7.5",
"phpspec/prophecy": "^1.10",
"phpunit/phpunit": "^7.5",
"phpunit/phpunit": "^7.5 || ^9.6",
"psr/http-message": "^1.0",
"squizlabs/php_codesniffer": "^3.5"
},
Expand Down
2 changes: 1 addition & 1 deletion src/ArrayFromIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final public function toArray() : array
return $array;
}

final private function all() : PromiseSequence
private function all() : PromiseSequence
{
return new PromiseSequence(
$promise = new Promise(
Expand Down
4 changes: 2 additions & 2 deletions src/CanBeSliced.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait CanBeSliced

abstract public function slice(int $offset, int $length = null) : Sequence;

final private function getPage(int $page) : Sequence
private function getPage(int $page) : Sequence
{
if (empty($this->pages)) {
for ($i = 0; $i < $this->count(); ++$i) {
Expand All @@ -31,7 +31,7 @@ final private function getPage(int $page) : Sequence
return $this->pages[$page];
}

final private function resetPages()
private function resetPages()
{
$this->pages = [];
$this->pageBatch = 100;
Expand Down
1 change: 1 addition & 0 deletions src/Collection/ArraySequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function offsetExists($offset) : bool
return isset($this->array[$offset]);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if (!isset($this->array[$offset])) {
Expand Down
1 change: 1 addition & 0 deletions src/Collection/EmptySequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function offsetExists($offset) : bool
return false;
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return null;
Expand Down
1 change: 1 addition & 0 deletions src/Collection/PromiseSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public function offsetExists($offset) : bool
return $this->wait()->offsetExists($offset);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->wait()->offsetGet($offset);
Expand Down
4 changes: 2 additions & 2 deletions src/ImmutableArrayAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

trait ImmutableArrayAccess
{
final public function offsetSet($offset, $value)
final public function offsetSet($offset, $value): void
{
throw new BadMethodCallException('Object is immutable');
}

final public function offsetUnset($offset)
final public function offsetUnset($offset): void
{
throw new BadMethodCallException('Object is immutable');
}
Expand Down
10 changes: 6 additions & 4 deletions src/Model/SearchSubjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,35 @@ public function __construct(array $subjects, array $results)
$this->results = $results;
}

public function count()
public function count(): int
{
return count($this->subjects);
}

#[\ReturnTypeWillChange]
public function current()
{
return current($this->results);
}

public function next()
public function next(): void
{
next($this->subjects);
next($this->results);
}

#[\ReturnTypeWillChange]
public function key()
{
return current($this->subjects);
}

public function valid()
public function valid(): bool
{
return false !== $this->key();
}

public function rewind()
public function rewind(): void
{
reset($this->subjects);
reset($this->results);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/SearchTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(array $typesToResults)
$this->typesToResults = $typesToResults;
}

public function count()
public function count(): int
{
return count($this->typesToResults);
}
Expand Down
1 change: 1 addition & 0 deletions src/SlicedArrayAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function offsetExists($offset) : bool
return null !== $this->offsetGet($offset);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
try {
Expand Down
10 changes: 6 additions & 4 deletions src/SlicedIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ trait SlicedIterator

private $key = 1;

#[\ReturnTypeWillChange]
final public function current()
{
$page = (int) ceil($this->key / $this->pageBatch);
Expand All @@ -23,11 +24,12 @@ final public function current()
return $pageContents[$inPage];
}

final public function next()
final public function next(): void
{
++$this->key;
}

#[\ReturnTypeWillChange]
final public function key()
{
if ($this->key > $this->count()) {
Expand All @@ -37,17 +39,17 @@ final public function key()
return $this->key;
}

final public function valid()
final public function valid(): bool
{
return $this->key <= $this->count();
}

final public function rewind()
final public function rewind(): void
{
$this->key = 1;
}

final private function resetIterator()
private function resetIterator()
{
$this->rewind();
$this->resetPages();
Expand Down
3 changes: 1 addition & 2 deletions test/ApiSdkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public function it_creates_community()
$this->mockCommunityListCall(1, 1, 1);
$this->mockBlogArticleCall('model-1', true);

$this->assertInternalType(
'array',
$this->assertIsArray(
$this->apiSdk->getSerializer()->normalize($this->apiSdk->community()[0])
);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Client/DigestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function it_gets_a_digest()
$this->assertSame('Digest digest-7 text', $digest->getContent()[0]->getText());

$this->assertInstanceOf(ArticleVoR::class, $digest->getRelatedContent()[0]);
$this->assertContains('Homo naledi', $digest->getRelatedContent()[0]->getTitle());
$this->assertStringContainsString('Homo naledi', $digest->getRelatedContent()[0]->getTitle());

$this->mockArticleCall('09560', true, true, 1);

Expand Down
2 changes: 1 addition & 1 deletion test/Client/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public function it_has_counters_for_types()

$types = $this->search->types();
foreach ($types as $type => $counter) {
$this->assertInternalType('string', $type);
$this->assertIsString($type);
$this->assertRegexp('/^[a-z-]+$/', $type);
$this->assertGreaterThanOrEqual(0, $counter);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Model/ArticlePoATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

final class ArticlePoATest extends ArticleVersionTest
{
public function setUp()
public function setUp(): void
{
$this->builder = Builder::for(ArticlePoA::class);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Model/ArticleVoRTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

final class ArticleVoRTest extends ArticleVersionTest
{
public function setUp()
public function setUp(): void
{
$this->builder = Builder::for(ArticleVoR::class);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Model/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class CollectionTest extends TestCase
{
private $builder;

public function setUp()
public function setUp(): void
{
$this->builder = Builder::for(Collection::class);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Model/DigestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class DigestTest extends TestCase
{
private $builder;

public function setUp()
public function setUp(): void
{
$this->builder = Builder::for(Digest::class);
}
Expand Down
6 changes: 3 additions & 3 deletions test/Model/IdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class IdentifierTest extends TestCase
* @test
* @dataProvider identifierProvider
*/
public function it_has_a_type(string $method, string $type, string $id)
public function it_has_a_type(string $method, string $type, $id)
{
$identifier = Identifier::{$method}($id);

Expand All @@ -24,7 +24,7 @@ public function it_has_a_type(string $method, string $type, string $id)
* @test
* @dataProvider identifierProvider
*/
public function it_has_an_id(string $method, string $type, string $id)
public function it_has_an_id(string $method, string $type, $id)
{
$identifier = Identifier::{$method}($id);

Expand All @@ -35,7 +35,7 @@ public function it_has_an_id(string $method, string $type, string $id)
* @test
* @dataProvider identifierProvider
*/
public function it_can_be_created_from_a_string(string $method, string $type, string $id)
public function it_can_be_created_from_a_string(string $method, string $type, $id)
{
$identifier = Identifier::fromString("$type/$id");

Expand Down
2 changes: 1 addition & 1 deletion test/Model/PressPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class PressPackageTest extends TestCase
{
private $builder;

public function setUp()
public function setUp(): void
{
$this->builder = Builder::for(PressPackage::class);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Model/PromotionalCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class PromotionalCollectionTest extends TestCase
{
private $builder;

public function setUp()
public function setUp(): void
{
$this->builder = Builder::for(PromotionalCollection::class);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Model/ReviewedPreprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class ReviewedPreprintTest extends TestCase
{
private $builder;

public function setUp()
public function setUp(): void
{
$this->builder = Builder::for(ReviewedPreprint::class);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Model/SearchSubjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function it_is_iterable_with_subjects_as_keys()
foreach ($searchSubjects as $subject => $results) {
$this->assertInstanceOf(Subject::class, $subject);
$actualSubjects[] = $subject;
$this->assertInternalType('integer', $results);
$this->assertIsInt($results);
$actualResults[] = $results;
}

Expand Down
6 changes: 3 additions & 3 deletions test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ final protected function classNameProvider(string ...$classes) : Traversable

final protected function assertObjectsAreEqual($expected, $actual, $detail = '')
{
$this->assertInternalType('object', $expected, $detail);
$this->assertInternalType('object', $actual, $detail);
$this->assertIsObject($expected, $detail);
$this->assertIsObject($actual, $detail);
$this->assertInstanceOf(get_class($expected), $actual, $detail);

foreach (get_class_methods($actual) as $method) {
Expand Down Expand Up @@ -59,7 +59,7 @@ private function assertItemsAreEqual($expected, $actual, $detail = null)
if (is_object($actual)) {
$this->assertObjectsAreEqual($expected, $actual, $detail);
} elseif (is_array($actual)) {
$this->assertInternalType('array', $expected, "We are getting an array out of $detail but we were not expecting it");
$this->assertIsArray($expected, "We are getting an array out of $detail but we were not expecting it");
$this->assertEquals(count($expected), count($actual), "Count of $detail doesn't match expected");
foreach ($actual as $key => $actualItem) {
$this->assertItemsAreEqual($expected[$key], $actualItem, $detail.' '.$key);
Expand Down

0 comments on commit 8c3ca7d

Please sign in to comment.