-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
3,416 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
{ | ||
"name": "Sebastian Böttger", | ||
"email": "[email protected]", | ||
"homepage": "http://sebastianboettger.net", | ||
"homepage": "https://sebastianboettger.net", | ||
"role": "Developer" | ||
} | ||
], | ||
|
@@ -23,7 +23,7 @@ | |
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Seboettg\\CiteProc\\": "tests/src/" | ||
"Seboettg\\CiteProc\\Test\\": "tests/src/" | ||
} | ||
}, | ||
"require": { | ||
|
@@ -32,7 +32,8 @@ | |
"ext-simplexml": "*", | ||
"ext-json": "*", | ||
"php": ">=7.3", | ||
"ext-mbstring": "*" | ||
"ext-mbstring": "*", | ||
"ext-intl": "*" | ||
}, | ||
"require-dev": { | ||
"php-coveralls/php-coveralls": "^1", | ||
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
|
@@ -23,7 +20,7 @@ abstract class AbstractConstraint implements Constraint | |
protected $match; | ||
|
||
/** | ||
* @var array | ||
* @var ArrayList\ArrayListInterface | ||
*/ | ||
protected $conditionVariables; | ||
|
||
|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/* | ||
* citeproc-php | ||
* | ||
|
@@ -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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/* | ||
* citeproc-php | ||
* | ||
|
@@ -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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/* | ||
* citeproc-php | ||
* | ||
|
@@ -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; | ||
} | ||
|
Oops, something went wrong.