Skip to content

Commit

Permalink
build.xml with a couple of php-ca-fixer targets, php-cs-fixer fixes a…
Browse files Browse the repository at this point in the history
…nd other code style fixes in addition to a couple of minor bug fixes revealed by code inspections.
  • Loading branch information
EreMaijala committed Aug 11, 2015
1 parent 113095c commit 2d18aa9
Show file tree
Hide file tree
Showing 48 changed files with 3,178 additions and 1,628 deletions.
32 changes: 32 additions & 0 deletions build.xml
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="RecordManager" basedir="." default="main">
<property name="tmp" value="/tmp" />
<property name="package" value="${phing.project.name}" override="true" />
<property name="builddir" value="${tmp}/build/${phing.project.name}" override="true" />
<property name="srcdir" value="${project.basedir}" override="true" />
<property name="php-cs-fixers" value="no_blank_lines_before_namespaces,function_call_space,trailing_spaces,unused_use,lowercase_keywords,encoding,parenthesis,php_closing_tag,visibility,duplicate_semicolon,extra_empty_lines,no_blank_lines_after_class_opening,no_empty_lines_after_phpdocs,operators_spaces,spaces_before_semicolon,ternary_spaces,concat_with_spaces,short_array_syntax,phpdoc_no_access,remove_leading_slash_use" />

<!-- Main Target -->
<target name="main" description="main target">
</target>

<!-- Continuous Integration Tasks -->
<target name="ci-tasks" description="continuous integration tasks">
<!-- Call standard tasks -->
<phingcall target="phpcs"/>
<phingcall target="php-cs-fixer-dryrun"/>
</target>

<!-- PHP CodeSniffer -->
<target name="phpcs">
<exec command="phpcs --standard=PEAR --extensions=php" escape="false" />
</target>

<!-- php-cs-fixer (first task applies fixes, second task simply checks if they are needed) -->
<target name="php-cs-fixer">
<exec command="php-cs-fixer fix ${srcdir} --fixers=${php-cs-fixers} --verbose" passthru="true" escape="false" />
</target>
<target name="php-cs-fixer-dryrun">
<exec command="php-cs-fixer fix ${srcdir} --fixers=${php-cs-fixers} --dry-run --verbose --diff" passthru="true" escape="false" checkreturn="true" />
</target>
</project>
16 changes: 10 additions & 6 deletions classes/BaseRecord.php
Expand Up @@ -49,7 +49,8 @@ class BaseRecord
* Constructor
*
* @param string $data Metadata
* @param string $oaiID Record ID received from OAI-PMH (or empty string for file import)
* @param string $oaiID Record ID received from OAI-PMH (or empty string for
* file import)
* @param string $source Source ID
* @param string $idPrefix Record ID prefix
*/
Expand Down Expand Up @@ -154,9 +155,11 @@ public function mergeComponentParts($componentParts)
* Return record title
*
* @param bool $forFiling Whether the title is to be used in filing
* (e.g. sorting, non-filing characters should be removed)
* (e.g. sorting, non-filing characters should be removed)
*
* @return string
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getTitle($forFiling = false)
{
Expand Down Expand Up @@ -240,7 +243,7 @@ public function getMainAuthor()
*/
public function getUniqueIDs()
{
return array();
return [];
}

/**
Expand All @@ -250,7 +253,7 @@ public function getUniqueIDs()
*/
public function getISBNs()
{
return array();
return [];
}

/**
Expand All @@ -260,7 +263,7 @@ public function getISBNs()
*/
public function getISSNs()
{
return array();
return [];
}

/**
Expand Down Expand Up @@ -348,7 +351,8 @@ protected function getDriverParam($parameter, $default = true)
{
global $configArray;

if (!isset($configArray['dataSourceSettings'][$this->source]['driverParams'])) {
if (!isset($configArray['dataSourceSettings'][$this->source]['driverParams'])
) {
return $default;
}
$iniValues = parse_ini_string(
Expand Down
50 changes: 22 additions & 28 deletions classes/DcRecord.php
Expand Up @@ -25,7 +25,6 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://github.com/KDK-Alli/RecordManager
*/

require_once 'BaseRecord.php';
require_once 'MetadataUtils.php';

Expand All @@ -48,7 +47,8 @@ class DcRecord extends BaseRecord
* Constructor
*
* @param string $data Metadata
* @param string $oaiID Record ID received from OAI-PMH (or empty string for file import)
* @param string $oaiID Record ID received from OAI-PMH (or empty string for
* file import)
* @param string $source Source ID
* @param string $idPrefix Record ID prefix
*/
Expand All @@ -68,7 +68,6 @@ public function __construct($data, $oaiID, $source, $idPrefix)
* Return record ID (local)
*
* @return string
* @access public
*/
public function getID()
{
Expand All @@ -79,7 +78,6 @@ public function getID()
* Serialize the record for storing in the database
*
* @return string
* @access public
*/
public function serialize()
{
Expand All @@ -90,7 +88,6 @@ public function serialize()
* Serialize the record into XML for export
*
* @return string
* @access public
*/
public function toXML()
{
Expand All @@ -101,20 +98,21 @@ public function toXML()
* Return fields to be indexed in Solr
*
* @return string[]
* @access public
*/
public function toSolrArray()
{
$data = array();
$data = [];

$doc = $this->doc;
$data['ctrlnum'] = (string)$doc->recordID;
$data['fullrecord'] = $doc->asXML();

// allfields
$allFields = array();
$allFields = [];
foreach ($doc->children() as $tag => $field) {
$allFields[] = MetadataUtils::stripTrailingPunctuation(trim((string)$field));
$allFields[] = MetadataUtils::stripTrailingPunctuation(
trim((string)$field)
);
}
$data['allfields'] = $allFields;

Expand All @@ -126,17 +124,21 @@ public function toSolrArray()
(string)$doc->language
),
function ($value) {
return preg_match('/^[a-z]{2,3}$/', $value) && $value != 'zxx' && $value != 'und';
return preg_match('/^[a-z]{2,3}$/', $value) && $value != 'zxx'
&& $value != 'und';
}
)
);

$data['format'] = (string)$doc->type;
$data['author'] = MetadataUtils::stripTrailingPunctuation((string)$doc->creator);
$data['author'] = MetadataUtils::stripTrailingPunctuation(
(string)$doc->creator
);
$data['author-letter'] = $data['author'];
$data['author2'] = $this->getValues('contributor');

$data['title'] = $data['title_full'] = MetadataUtils::stripTrailingPunctuation(trim((string)$doc->title));
$data['title'] = $data['title_full']
= MetadataUtils::stripTrailingPunctuation(trim((string)$doc->title));
$titleParts = explode(' : ', $data['title'], 2);
if (!empty($titleParts)) {
$data['title_short'] = $titleParts[0];
Expand All @@ -146,7 +148,8 @@ function ($value) {
}
$data['title_sort'] = $this->getTitle(true);

$data['publisher'] = MetadataUtils::stripTrailingPunctuation((string)$doc->publisher);
$data['publisher']
= MetadataUtils::stripTrailingPunctuation((string)$doc->publisher);
$data['publishDate'] = $this->getPublicationYear();

$data['isbn'] = $this->getISBNs();
Expand Down Expand Up @@ -175,7 +178,6 @@ function ($value) {
* Dedup: Return full title (for debugging purposes only)
*
* @return string
* @access public
*/
public function getFullTitle()
{
Expand All @@ -185,15 +187,13 @@ public function getFullTitle()
/**
* Dedup: Return record title
*
* @param bool $forFiling Whether the title is to be used in filing (e.g. sorting, non-filing characters should be removed)
* @param bool $forFiling Whether the title is to be used in filing
* (e.g. sorting, non-filing characters should be removed)
*
* @return string
* @access public
*/
public function getTitle($forFiling = false)
{
global $configArray;

$title = trim((string)$this->doc->title);
$title = MetadataUtils::stripTrailingPunctuation($title);
if ($forFiling) {
Expand All @@ -210,7 +210,6 @@ public function getTitle($forFiling = false)
* Dedup: Return main author (format: Last, First)
*
* @return string
* @access public
*/
public function getMainAuthor()
{
Expand All @@ -221,11 +220,10 @@ public function getMainAuthor()
* Dedup: Return ISBNs in ISBN-13 format without dashes
*
* @return string[]
* @access public
*/
public function getISBNs()
{
$arr = array();
$arr = [];
foreach ($this->doc->identifier as $identifier) {
$identifier = str_replace('-', '', $identifier);
if (!preg_match('{([0-9]{9,12}[0-9xX])}', $identifier, $matches)) {
Expand All @@ -246,7 +244,6 @@ public function getISBNs()
* Dedup: Return series ISSN
*
* @return string
* @access public
*/
public function getSeriesISSN()
{
Expand All @@ -257,7 +254,6 @@ public function getSeriesISSN()
* Dedup: Return series numbering
*
* @return string
* @access public
*/
public function getSeriesNumbering()
{
Expand All @@ -268,7 +264,6 @@ public function getSeriesNumbering()
* Dedup: Return format from predefined values
*
* @return string
* @access public
*/
public function getFormat()
{
Expand All @@ -279,7 +274,6 @@ public function getFormat()
* Dedup: Return publication year (four digits only)
*
* @return string
* @access public
*/
public function getPublicationYear()
{
Expand All @@ -288,13 +282,13 @@ public function getPublicationYear()
return (string)$date;
}
}
return '';
}

/**
* Dedup: Return page count (number only)
*
* @return string
* @access public
*/
public function getPageCount()
{
Expand All @@ -306,11 +300,11 @@ public function getPageCount()
*
* @param string $tag XML tag to get
*
* @return multitype:string
* @return array
*/
protected function getValues($tag)
{
$values = array();
$values = [];
foreach ($this->doc->{$tag} as $value) {
$values[] = MetadataUtils::stripTrailingPunctuation((string)$value);
}
Expand Down

0 comments on commit 2d18aa9

Please sign in to comment.