Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Tests

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']

name: PHP ${{ matrix.php }}

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run tests
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
composer.lock
vendor
.phpunit.result.cache
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
All notable changes to this project will be documented in this file. This
project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.0] - 2026-01-29
### Changed
- Minimum PHP version is now 7.2 (previously 5.4)
- Migrate CI from Travis to GitHub Actions
- Add type hints to all `extract()` methods (`?string` parameter, `array` return)

### Security
- Upgrade PHPUnit to 8.5.52 to fix unsafe deserialization vulnerability

## [0.10.1] - 2018-04-09
### Fixed
- Restored support for extracting hyphenated ISBN-10s with registration group
Expand Down Expand Up @@ -81,4 +90,5 @@ project adheres to [Semantic Versioning](http://semver.org/).
[0.8.0]: https://github.com/altmetric/php-identifiers/releases/tag/v0.8.0
[0.9.0]: https://github.com/altmetric/php-identifiers/releases/tag/v0.9.0
[0.10.0]: https://github.com/altmetric/php-identifiers/releases/tag/v0.10.0
[1.0.0]: https://github.com/altmetric/php-identifiers/releases/tag/v1.0.0
[0.10.1]: https://github.com/altmetric/php-identifiers/releases/tag/v0.10.1
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2017 Altmetric LLP
Copyright (c) 2016-2026 Altmetric LLP

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Identifiers [![Build Status](https://travis-ci.org/altmetric/php-identifiers.svg?branch=master)](https://travis-ci.org/altmetric/php-identifiers)
# Identifiers [![Tests](https://github.com/altmetric/php-identifiers/actions/workflows/tests.yml/badge.svg)](https://github.com/altmetric/php-identifiers/actions/workflows/tests.yml)

Collection of utilities related to the extraction, validation and normalization
of various scholarly identifiers.

**Current version:** 0.10.1
**Supported PHP versions:** 5.4, 5.5, 5.6, 7
**Current version:** 1.0.0
**Supported PHP versions:** 7.2+

## Installation

Expand Down Expand Up @@ -161,6 +161,6 @@ We also maintain [a version of this library for Ruby](https://github.com/altmetr

## License

Copyright © 2016-2017 Altmetric LLP
Copyright © 2016-2026 Altmetric LLP

Distributed under the [MIT License](http://opensource.org/licenses/MIT).
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
}
],
"require": {
"php": ">= 5.4.0"
"php": ">= 7.2"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
"phpunit/phpunit": "^8.5.52"
},
"suggest": {
"ext-mbstring": "Needed for multibyte string support (alternatively, require symfony/polyfill-mbstring)"
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<phpunit colors="true" bootstrap="vendor/autoload.php">
<testsuites>
<testsuite>
<testsuite name="Identifiers">
<directory>tests</directory>
</testsuite>
</testsuites>
Expand Down
3 changes: 2 additions & 1 deletion src/AdsBibcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class AdsBibcode
{
public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';
preg_match_all('/\b\d{4}[a-z][0-9a-z&.]{14}\b/ui', $str, $matches);

return $matches[0];
Expand Down
4 changes: 3 additions & 1 deletion src/ArxivId.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class ArxivId
}xiu
EOT;

public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';

return array_merge(self::extractPre2007ArxivIds($str), self::extractPost2007ArxivIds($str));
}

Expand Down
3 changes: 2 additions & 1 deletion src/Doi.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class Doi
}xu
EOT;

public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';
preg_match_all(self::REGEXP, mb_strtolower($str, 'UTF-8'), $matches);

return $matches[0];
Expand Down
3 changes: 2 additions & 1 deletion src/Handle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class Handle
{
public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';
preg_match_all('#\b[\d.]+/\S+\b#u', $str, $matches);

return $matches[0];
Expand Down
12 changes: 7 additions & 5 deletions src/Isbn.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ class Isbn
}xu
EOT;

public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';

return array_merge(self::extractIsbnAs($str), self::extractIsbn13s($str), self::extractIsbn10s($str));
}

Expand Down Expand Up @@ -123,9 +125,9 @@ private static function stripHyphenation($match, $limit)
return $isbn;
}

private static function isValidIsbn13($str)
private static function isValidIsbn13(?string $str): bool
{
if (strlen($str) !== 13) {
if ($str === null || strlen($str) !== 13) {
return false;
}

Expand All @@ -134,9 +136,9 @@ private static function isValidIsbn13($str)
return $checkDigit === (int) $str[12];
}

private static function isValidIsbn10($str)
private static function isValidIsbn10(?string $str): bool
{
if (strlen($str) !== 10) {
if ($str === null || strlen($str) !== 10) {
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/NationalClinicalTrialId.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class NationalClinicalTrialId
{
public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';
preg_match_all('/\bNCT\d+\b/ui', $str, $matches);

return array_map('strtoupper', $matches[0]);
Expand Down
3 changes: 2 additions & 1 deletion src/OrcidId.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

class OrcidId
{
public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';
preg_match_all('/\d{4}-\d{4}-\d{4}-\d{3}[\dX]/i', $str, $matches);

return array_filter(array_map('strtoupper', $matches[0]), [__CLASS__, 'isValid']);
Expand Down
4 changes: 3 additions & 1 deletion src/PubmedId.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class PubmedId
}xu
EOT;

public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';

return array_merge(self::extractPubmedIds($str), self::extractPubmedUris($str));
}

Expand Down
3 changes: 2 additions & 1 deletion src/RepecId.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class RepecId
{
public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';
preg_match_all('/\brepec:\S+\b/ui', $str, $matches);

return array_map(
Expand Down
3 changes: 2 additions & 1 deletion src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class Uri
#x
EOF;

public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';
preg_match_all(self::REGEXP, $str, $matches);

return $matches[0];
Expand Down
3 changes: 2 additions & 1 deletion src/Urn.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class Urn
{
public static function extract($str)
public static function extract(?string $str): array
{
$str = $str ?? '';
preg_match_all(
'/\burn:(?!urn:)[a-z0-9][a-z0-9\-]{1,31}:(?:[a-z0-9()+,-.:=@;$_!*\']|' .
'%(?:2[1-9a-f]|[3-6][0-9a-f]|7[0-9a-e]))+/i',
Expand Down
2 changes: 1 addition & 1 deletion tests/AdsBibcodeTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class AdsBibcodeTest extends \PHPUnit_Framework_TestCase
class AdsBibcodeTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsBibcodes()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/ArxivIdTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class ArxivIdTest extends \PHPUnit_Framework_TestCase
class ArxivIdTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsPre2007ArxivIds()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/DoiTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class DoiTest extends \PHPUnit_Framework_TestCase
class DoiTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsDois()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/HandleTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class HandleTest extends \PHPUnit_Framework_TestCase
class HandleTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsHandles()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/IsbnTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class IsbnTest extends \PHPUnit_Framework_TestCase
class IsbnTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsIsbn13s()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/NationalClinicalTrialIdTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class NationalClinicalTrialIdTest extends \PHPUnit_Framework_TestCase
class NationalClinicalTrialIdTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsNctIds()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/OrcidIdTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class OrcidIdTest extends \PHPUnit_Framework_TestCase
class OrcidIdTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsOrcids()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/PubmedIdTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class PubmedIdTest extends \PHPUnit_Framework_TestCase
class PubmedIdTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsPubmedIDs()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/RepecIdTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class RepecIdTest extends \PHPUnit_Framework_TestCase
class RepecIdTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsRepecIds()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/UriTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class UriTest extends \PHPUnit_Framework_TestCase
class UriTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsValidUris()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/UrnTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Altmetric\Identifiers;

class UrnTest extends \PHPUnit_Framework_TestCase
class UrnTest extends \PHPUnit\Framework\TestCase
{
public function testExtractsValidUrns()
{
Expand Down