Skip to content

Commit

Permalink
Align tools and settings with main project release 9.1 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz authored Oct 2, 2023
1 parent 227c1d3 commit 36563c6
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 63 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
VUFIND_LOCAL_DIR: $GITHUB_WORKSPACE/local
strategy:
matrix:
php-version: ['7.4', '8.0', '8.1']
php-version: ['8.0', '8.1', '8.2']
include:
- php-version: 7.4
phing_tasks: "phpunitfast"
- php-version: 8.0
phing_tasks: "phpunitfast"
- php-version: 8.1
phing_tasks: "phpunitfast"
- php-version: 8.2
phing_tasks: "phpunitfast phpcs-console php-cs-fixer-dryrun phpstan-console"

steps:
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## Next Release - TBD

### Added

- Nothing.

### Changed

- The minimum PHP version requirement has been raised to 8.0.

### Deprecated

- Nothing.

### Removed

- Nothing.

## Fixed

- Nothing.

## 1.0.2 - 2022-11-25

### Added
Expand Down
12 changes: 0 additions & 12 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@
<phingcall target="phpcs"/>
<phingcall target="phpunit"/>
<phingcall target="phpdoc"/>
<phingcall target="phpcpd"/>
<phingcall target="phpmd"/>
<phingcall target="pdepend"/>
<phingcall target="phploc"/>
<phingcall target="phpstan-checkstyle"/>
</target>

Expand All @@ -46,21 +44,11 @@
<exec command="${srcdir}/vendor/bin/phpmd ${srcdir}/src xml ${srcdir}/tests/phpmd.xml --exclude ${srcdir}/tests --reportfile ${builddir}/reports/phpmd.xml" />
</target>

<!-- Measure project with phploc -->
<target name="phploc">
<exec command="${srcdir}/vendor/bin/phploc --log-csv ${builddir}/reports/phploc.csv ${srcdir}/src" />
</target>

<!-- PHP_Depend code analysis -->
<target name="pdepend">
<exec command="${srcdir}/vendor/bin/pdepend --jdepend-xml=${builddir}/reports/jdepend.xml --jdepend-chart=${builddir}/reports/dependencies.svg --overview-pyramid=${builddir}/reports/pdepend-pyramid.svg ${srcdir}/src" />
</target>

<!-- PHP copy-and-paste detection -->
<target name="phpcpd">
<exec command="${srcdir}/vendor/bin/phpcpd --log-pmd ${builddir}/reports/pmd-cpd.xml --exclude tests ${srcdir}/src" />
</target>

<!-- PHP CodeSniffer -->
<target name="phpcbf">
<exec command="${srcdir}/vendor/bin/phpcbf --standard=${srcdir}/tests/phpcs.xml" escape="false" passthru="true" checkreturn="true" />
Expand Down
12 changes: 5 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,22 @@
},
"config": {
"platform": {
"php": "7.4.1"
"php": "8.0"
}
},
"require": {
"php": ">=7.4.1",
"php": ">=8.0",
"opis/json-schema": "^2.3.0",
"pcrov/jsonreader": "^1.0.2",
"vufind-org/vufindcode": "^1.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "3.14.4",
"friendsofphp/php-cs-fixer": "3.26.1",
"pear/http_request2": "2.5.1",
"phploc/phploc": "7.0.2",
"phpmd/phpmd": "2.13.0",
"phpstan/phpstan": "1.10.3",
"phpunit/phpunit": "9.6.4",
"phpstan/phpstan": "1.10.34",
"phpunit/phpunit": "9.6.12",
"phing/phing": "2.17.4",
"sebastian/phpcpd": "6.0.3",
"squizlabs/php_codesniffer": "3.7.2"
}
}
20 changes: 10 additions & 10 deletions src/Lint/CodeData.php

Large diffs are not rendered by default.

53 changes: 29 additions & 24 deletions src/MarcLint.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@

use VuFindCode\ISBN;

use function count;
use function in_array;
use function intval;
use function strlen;

/**
* Class for testing validity of MARC records against MARC21 standard.
*
Expand Down Expand Up @@ -178,7 +183,7 @@ protected function standardFieldChecks(MarcReader $marc): void
= isset($fieldsSeen['880.' . $tagNo])
? $fieldsSeen['880.' . $tagNo] + 1 : 1;
} else {
$this->warn("880: No subfield 6.");
$this->warn('880: No subfield 6.');
$tagrules = null;
}
} else {
Expand Down Expand Up @@ -305,7 +310,7 @@ protected function check020(array $field, MarcReader $marc): void

if ($current['code'] === 'a') {
if ((substr($data, 0, strlen($isbn)) != $isbn)) {
$this->warn("020: Subfield a may have invalid characters.");
$this->warn('020: Subfield a may have invalid characters.');
}

// report error if no space precedes a qualifier in subfield a
Expand Down Expand Up @@ -347,7 +352,7 @@ protected function check020(array $field, MarcReader $marc): void
if (strlen($isbn) == 10) {
$isbnObj = new ISBN($isbn);
if ($isbnObj->isValid()) {
$this->warn("020: Subfield z is numerically valid.");
$this->warn('020: Subfield z is numerically valid.');
}
}
}
Expand Down Expand Up @@ -393,7 +398,7 @@ protected function check041(array $field, MarcReader $marc): void
} else {
$this->warn(
"041: Subfield _$code, $data ($chk),"
. " is not valid."
. ' is not valid.'
);
}
}
Expand Down Expand Up @@ -463,7 +468,7 @@ protected function check043(array $field, MarcReader $marc): void
protected function check245(array $field, MarcReader $marc): void
{
if (!$marc->getSubfields($field, 'a')) {
$this->warn("245: Must have a subfield _a.");
$this->warn('245: Must have a subfield _a.');
}

// Convert subfields to array and set flags indicating which subfields are
Expand All @@ -481,11 +486,11 @@ protected function check245(array $field, MarcReader $marc): void
// (LCRI 1.0C, Nov. 2003)
$lastChar = substr($subfields[count($subfields) - 1]['data'], -1);
if (!in_array($lastChar, ['.', '?', '!'])) {
$this->warn("245: Must end with . (period).");
$this->warn('245: Must end with . (period).');
} elseif ($lastChar != '.') {
$this->warn(
"245: MARC21 allows ? or ! as final punctuation but LCRI 1.0C, Nov."
. " 2003 (LCPS 1.7.1 for RDA records), requires period."
'245: MARC21 allows ? or ! as final punctuation but LCRI 1.0C, Nov.'
. ' 2003 (LCPS 1.7.1 for RDA records), requires period.'
);
}

Expand All @@ -494,15 +499,15 @@ protected function check245(array $field, MarcReader $marc): void
if (isset($hasSubfields['6'])) {
// make sure there are at least 2 subfields
if (count($subfields) < 2) {
$this->warn("245: May have too few subfields.");
$this->warn('245: May have too few subfields.');
} else {
$first = $subfields[0]['code'];
$second = $subfields[1]['code'];
if ($first != '6') {
$this->warn("245: First subfield must be _6, but it is $first");
} elseif ($second != 'a') {
$this->warn(
"245: First subfield after subfield _6 must be _a, but it "
'245: First subfield after subfield _6 must be _a, but it '
. "is _$second"
);
}
Expand All @@ -526,12 +531,12 @@ protected function check245(array $field, MarcReader $marc): void
$i > 0
&& !preg_match('/\s\/$/', $subfields[$i - 1]['data'])
) {
$this->warn("245: Subfield _c must be preceded by /");
$this->warn('245: Subfield _c must be preceded by /');
}
// 245 subfield c initials should not have space
if (preg_match('/\b\w\. \b\w\./', $current['data'])) {
$this->warn(
"245: Subfield _c initials should not have a space."
'245: Subfield _c initials should not have a space.'
);
}
break;
Expand All @@ -550,8 +555,8 @@ protected function check245(array $field, MarcReader $marc): void
&& !preg_match('/ [:;=]$/', $subfields[$i - 1]['data'])
) {
$this->warn(
"245: Subfield _b should be preceded by space-colon, "
. "space-semicolon, or space-equals sign."
'245: Subfield _b should be preceded by space-colon, '
. 'space-semicolon, or space-equals sign.'
);
}
}
Expand All @@ -567,7 +572,7 @@ protected function check245(array $field, MarcReader $marc): void
$prev = $subfields[$i - 1]['data'];
if ($i > 0 && !preg_match('/(\S$)|(\-\- $)/', $prev)) {
$this->warn(
"245: Subfield _h should not be preceded by space."
'245: Subfield _h should not be preceded by space.'
);
}
// report error if subfield 'h' does not start with open square
Expand All @@ -576,7 +581,7 @@ protected function check245(array $field, MarcReader $marc): void
$data = $current['data'];
if (!preg_match('/^\[\w*\s*\w*\]/', $data)) {
$this->warn(
"245: Subfield _h must have matching square brackets,"
'245: Subfield _h must have matching square brackets,'
. " $data."
);
}
Expand All @@ -594,7 +599,7 @@ protected function check245(array $field, MarcReader $marc): void
$prev = $subfields[$i - 1]['data'];
if (!preg_match('/(\S\.$)|(\-\- \.$)/', $prev)) {
$this->warn(
"245: Subfield _n must be preceded by . (period)."
'245: Subfield _n must be preceded by . (period).'
);
}
}
Expand All @@ -616,16 +621,16 @@ protected function check245(array $field, MarcReader $marc): void
&& !preg_match('/(\S,$)|(\-\- ,$)/', $prev['data'])
) {
$this->warn(
"245: Subfield _p must be preceded by , (comma) "
. "when it follows subfield _n."
'245: Subfield _p must be preceded by , (comma) '
. 'when it follows subfield _n.'
);
} elseif (
$prev['code'] != 'n'
&& !preg_match('/(\S\.$)|(\-\- \.$)/', $prev['data'])
) {
$this->warn(
"245: Subfield _p must be preceded by . (period)"
. " when it follows a subfield other than _n."
'245: Subfield _p must be preceded by . (period)'
. ' when it follows a subfield other than _n.'
);
}
}
Expand Down Expand Up @@ -744,7 +749,7 @@ protected function checkArticle(array $field, MarcReader $marc): void
}

if (!is_numeric($ind)) {
$this->warn($tagNo . ": Non-filing indicator is non-numeric");
$this->warn($tagNo . ': Non-filing indicator is non-numeric');
return;
}

Expand All @@ -754,7 +759,7 @@ protected function checkArticle(array $field, MarcReader $marc): void
// warn about out-of-range skip indicators (note: this feature is an
// addition to the PHP code; it is not ported directly from MARC::Lint).
if ($ind > strlen($title)) {
$this->warn($tagNo . ": Non-filing indicator is out of range");
$this->warn($tagNo . ': Non-filing indicator is out of range');
return;
}

Expand Down Expand Up @@ -837,7 +842,7 @@ protected function parseRules()
$currentGroup = [];
}
} else {
$currentGroup[] = preg_replace("/\s+/", " ", $currentLine);
$currentGroup[] = preg_replace("/\s+/", ' ', $currentLine);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/MarcReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@

namespace VuFind\Marc;

use function in_array;
use function intval;
use function is_array;
use function is_string;

/**
* MARC record reader class.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Serialization/AbstractSerializationFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

namespace VuFind\Marc\Serialization;

use function call_user_func;

/**
* Abstract base class for serialization format support classes.
*
Expand Down
4 changes: 4 additions & 0 deletions src/Serialization/Iso2709.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

namespace VuFind\Marc\Serialization;

use function array_slice;
use function is_array;
use function strlen;

/**
* ISO2709 exchange format support class.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Serialization/MarcInJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

use pcrov\JsonReader\JsonReader;

use function is_array;
use function strlen;

/**
* MARC-in-JSON format support class.
*
Expand Down
9 changes: 7 additions & 2 deletions src/Serialization/MarcXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@

namespace VuFind\Marc\Serialization;

use function array_slice;
use function count;
use function is_string;
use function strlen;

/**
* MARCXML format support class.
*
Expand Down Expand Up @@ -179,7 +184,7 @@ public static function toString(array $record): string
$xml->openMemory();
$xml->setIndent(true);
$xml->startDocument('1.0', 'UTF-8');
$xml->startElementNs(null, 'collection', "http://www.loc.gov/MARC21/slim");
$xml->startElementNs(null, 'collection', 'http://www.loc.gov/MARC21/slim');
$xml->writeAttribute(
'xmlns:xsi',
'http://www.w3.org/2001/XMLSchema-instance'
Expand Down Expand Up @@ -255,7 +260,7 @@ protected static function loadXML(string $xml): \SimpleXMLElement
$saveUseErrors = libxml_use_internal_errors(true);
try {
libxml_clear_errors();
$doc = \simplexml_load_string(
$doc = simplexml_load_string(
$xml,
\SimpleXMLElement::class,
LIBXML_COMPACT
Expand Down
4 changes: 2 additions & 2 deletions tests/MarcReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function testEmptyFieldInMarcXmlSerialization()
*/
public function testEmptySubfieldInMarcXmlSerialization()
{
// $marc = "00047 00037 245000900000\x1e \x1faFoo\x1f\x1e\x1d";
// $marc = "00047 00037 245000900000\x1e \x1faFoo\x1f\x1e\x1d";
$input = <<<EOT
<collection xmlns="http://www.loc.gov/MARC21/slim">
<record>
Expand Down Expand Up @@ -547,7 +547,7 @@ public function testFieldFiltering()
*/
public function testInvalidDataArray()
{
$this->expectExceptionMessage("Invalid data array format provided");
$this->expectExceptionMessage('Invalid data array format provided');
new MarcReader([]);
}

Expand Down
Loading

0 comments on commit 36563c6

Please sign in to comment.