Skip to content

Commit

Permalink
Merge branch 'release/2.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
seboettg committed May 23, 2022
2 parents b6478c9 + e162a8b commit 209be3f
Show file tree
Hide file tree
Showing 57 changed files with 3,416 additions and 327 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ Add the following lines to your `composer.json` file in order to add required pr
{
"type": "package",
"package": {
"name": "citation-style-language/styles-distribution",
"name": "citation-style-language/styles",
"version":"1.0.0",
"source": {
"type": "git",
"url": "https://github.com/citation-style-language/styles-distribution.git",
"url": "https://github.com/citation-style-language/styles.git",
"reference": "master"
}
}
}
],
"require": {
"citation-style-language/locales":"@dev",
"citation-style-language/styles-distribution":"@dev",
"citation-style-language/styles":"@dev",
"seboettg/citeproc-php": "^2"
}
}
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"name": "Sebastian Böttger",
"email": "[email protected]",
"homepage": "http://sebastianboettger.net",
"homepage": "https://sebastianboettger.net",
"role": "Developer"
}
],
Expand All @@ -23,7 +23,7 @@
},
"autoload-dev": {
"psr-4": {
"Seboettg\\CiteProc\\": "tests/src/"
"Seboettg\\CiteProc\\Test\\": "tests/src/"
}
},
"require": {
Expand All @@ -32,7 +32,8 @@
"ext-simplexml": "*",
"ext-json": "*",
"php": ">=7.3",
"ext-mbstring": "*"
"ext-mbstring": "*",
"ext-intl": "*"
},
"require-dev": {
"php-coveralls/php-coveralls": "^1",
Expand All @@ -41,18 +42,17 @@
"phpmd/phpmd": "^2.8"
},
"suggest": {
"ext-intl": "*",
"symfony/polyfill-mbstring": "^1.10"
"symfony/polyfill-mbstring": "^1.10"
},
"scripts": {
"post-install-cmd": [
"./install.sh styles-distribution",
"./install.sh styles",
"./install.sh locales",
"@compile-test-cases",
"chmod +x vendor/bin/phpunit"
],
"post-update-cmd": [
"./install.sh styles-distribution",
"./install.sh styles",
"./install.sh locales",
"@compile-test-cases",
"chmod +x vendor/bin/phpunit"
Expand Down
78 changes: 46 additions & 32 deletions src/Constraint/AbstractConstraint.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?php /** @noinspection PhpUnused */
<?php
declare(strict_types=1);
/*
* citeproc-php: AbstractConstraint.php
* User: Sebastian Böttger <[email protected]>
* created at 26.10.19, 14:12
* @link http://github.com/seboettg/citeproc-php for the source repository
* @copyright Copyright (c) 2019 Sebastian Böttger.
* @license https://opensource.org/licenses/MIT
*/

namespace Seboettg\CiteProc\Constraint;

use Seboettg\Collection\ArrayList;
use stdClass;

/**
* Class AbstractConstraint
* @package Seboettg\CiteProc\Constraint
* @noinspection PhpUnused
*/
abstract class AbstractConstraint implements Constraint
{

Expand All @@ -23,7 +20,7 @@ abstract class AbstractConstraint implements Constraint
protected $match;

/**
* @var array
* @var ArrayList\ArrayListInterface
*/
protected $conditionVariables;

Expand All @@ -32,53 +29,70 @@ abstract class AbstractConstraint implements Constraint
* @param stdClass $data;
* @return bool
*/
abstract protected function matchForVariable($variable, $data);
abstract protected function matchForVariable(string $variable, stdClass $data): bool;

/**
* Variable constructor.
* @param string $value
* @param string $variableValues
* @param string $match
*/
/** @noinspection PhpUnused */
public function __construct($value, $match = "any")
public function __construct(string $variableValues, string $match = "any")
{
$this->conditionVariables = explode(" ", $value);
$this->conditionVariables = new ArrayList(...explode(" ", $variableValues));
$this->match = $match;
}

/**
* @param $value
* @param stdClass $data
* @param int|null $citationNumber
* @return bool
*/
public function validate($value, $citationNumber = null)
public function validate(stdClass $data, int $citationNumber = null): bool
{
switch ($this->match) {
case Constraint::MATCH_ALL:
return $this->matchAll($value);
return $this->matchAll($data);
case Constraint::MATCH_NONE:
return !$this->matchAny($value); //no match for any value
return $this->matchNone($data); //no match for any value
case Constraint::MATCH_ANY:
default:
return $this->matchAny($value);
return $this->matchAny($data);
}
}

private function matchAny($value)
private function matchAny(stdClass $data): bool
{
$conditionMatched = false;
foreach ($this->conditionVariables as $variable) {
$conditionMatched |= $this->matchForVariable($variable, $value);
}
return (bool)$conditionMatched;
return $this->conditionVariables
->map(function (string $conditionVariable) use ($data) {
return $this->matchForVariable($conditionVariable, $data);
})
->filter(function (bool $match) {
return $match === true;
})
->count() > 0;
}

private function matchAll($value)
private function matchAll(stdClass $data): bool
{
$conditionMatched = true;
foreach ($this->conditionVariables as $variable) {
$conditionMatched &= $this->matchForVariable($variable, $value);
}
return (bool)$conditionMatched;
return $this->conditionVariables
->map(function (string $conditionVariable) use ($data) {
return $this->matchForVariable($conditionVariable, $data);
})
->filter(function (bool $match) {
return $match === true;
})
->count() === $this->conditionVariables->count();
}

private function matchNone(stdClass $data): bool
{
return $this->conditionVariables
->map(function (string $conditionVariable) use ($data) {
return $this->matchForVariable($conditionVariable, $data);
})
->filter(function (bool $match) {
return $match === false;
})
->count() === $this->conditionVariables->count();
}
}
9 changes: 6 additions & 3 deletions src/Constraint/Constraint.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* citeproc-php
*
Expand All @@ -9,6 +10,8 @@

namespace Seboettg\CiteProc\Constraint;

use stdClass;

/**
* Interface ConstraintInterface
* @package Seboettg\CiteProc\Constraint
Expand All @@ -25,9 +28,9 @@ interface Constraint
const MATCH_ALL = "all";

/**
* @param $value
* @param null $citationNumber
* @param stdClass $data
* @param int|null $citationNumber
* @return bool
*/
public function validate($value, $citationNumber = null);
public function validate(stdClass $data, int $citationNumber = null): bool;
}
14 changes: 5 additions & 9 deletions src/Constraint/Disambiguate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* citeproc-php
*
Expand All @@ -9,27 +10,22 @@

namespace Seboettg\CiteProc\Constraint;

use stdClass;

/**
* Class Disambiguate
* When set to “true” (the only allowed value), the element content is only rendered if it disambiguates two otherwise
* identical citations. This attempt at disambiguation is only made when all other disambiguation methods have failed
* to uniquely identify the target source.
*
* @package Seboettg\CiteProc\Constraint
*
* @author Sebastian Böttger <[email protected]>
*
*/
/** @noinspection PhpUnused */
class Disambiguate implements Constraint
{
/**
* @codeCoverageIgnore
* @param $value
* @param stdClass $data
* @param int|null $citationNumber
* @return bool
*/
public function validate($value, $citationNumber = null)
public function validate(stdClass $data, $citationNumber = null): bool
{
return false;
}
Expand Down
13 changes: 2 additions & 11 deletions src/Constraint/Factory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* citeproc-php
*
Expand All @@ -12,24 +13,14 @@
use Seboettg\CiteProc\Exception\ClassNotFoundException;
use function Seboettg\CiteProc\ucfirst;

/**
* Class Factory
* @package Seboettg\CiteProc\Constraint
*
* @author Sebastian Böttger <[email protected]>
*/
class Factory extends \Seboettg\CiteProc\Util\Factory
{
const NAMESPACE_CONSTRAINTS = "Seboettg\\CiteProc\\Constraint\\";

/**
* @param string $name
* @param string $value
* @param string $match
* @return mixed
* @throws ClassNotFoundException
*/
public static function createConstraint(string $name, string $value, string $match)
public static function createConstraint(string $name, string $value, string $match): Constraint
{
$parts = explode("-", $name);
$className = implode("", array_map(function ($part) {
Expand Down
5 changes: 3 additions & 2 deletions src/Constraint/IsNumeric.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* citeproc-php
*
Expand Down Expand Up @@ -29,7 +30,7 @@ class IsNumeric extends AbstractConstraint
* @param stdClass $data
* @return bool
*/
protected function matchForVariable($variable, $data)
protected function matchForVariable(string $variable, stdClass $data): bool
{
if (isset($data->{$variable})) {
return $this->parseValue($data->{$variable});
Expand All @@ -46,7 +47,7 @@ protected function matchForVariable($variable, $data)
* @param $evalValue
* @return bool
*/
private function parseValue($evalValue)
private function parseValue($evalValue): bool
{
if (is_numeric($evalValue)) {
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/Constraint/IsUncertainDate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* citeproc-php
*
Expand Down Expand Up @@ -28,7 +29,7 @@ class IsUncertainDate extends AbstractConstraint
* @param stdClass $data ;
* @return bool
*/
protected function matchForVariable($variable, $data)
protected function matchForVariable(string $variable, stdClass $data): bool
{
if (!empty($data->{$variable})) {
if (isset($data->{$variable}->{'circa'})) {
Expand Down
8 changes: 5 additions & 3 deletions src/Constraint/Jurisdiction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* citeproc-php
*
Expand All @@ -9,22 +10,23 @@

namespace Seboettg\CiteProc\Constraint;

use stdClass;

/**
* Class Jurisdiction
* @package Seboettg\CiteProc\Constraint
*
* @author Sebastian Böttger <[email protected]>
*/
/** @noinspection PhpUnused */
class Jurisdiction implements Constraint
{
/**
* @codeCoverageIgnore
* @param $value
* @param stdClass $data
* @param int|null $citationNumber
* @return bool
*/
public function validate($value, $citationNumber = null)
public function validate(stdClass $data, int $citationNumber = null): bool
{
return false;
}
Expand Down
Loading

0 comments on commit 209be3f

Please sign in to comment.