auto fixes

This commit is contained in:
Dennis Eichhorn 2023-08-30 11:53:16 +00:00
parent 447efca623
commit 4469789af4
34 changed files with 290 additions and 318 deletions

View File

@ -141,7 +141,7 @@ final class DBSCAN
{
$this->clusters[$c][] = $point;
$this->clusteredPoints[] = $point;
$nPoint = reset($neighbors);
$nPoint = \reset($neighbors);
while ($nPoint) {
$neighbors2 = $this->findNeighbors($nPoint, $epsilon);
@ -159,7 +159,7 @@ final class DBSCAN
$this->clusteredPoints[] = $nPoint;
}
$nPoint = next($neighbors);
$nPoint = \next($neighbors);
}
}
@ -242,7 +242,7 @@ final class DBSCAN
if (Polygon::isPointInPolygon(
[
'x' => \reset($point->coordinates),
'y' => \end($point->coordinates)
'y' => \end($point->coordinates),
],
$hull
) <= 0

View File

@ -33,6 +33,4 @@ class IdleTime
public int $interval = 0;
public int $duration = 0; // in seconds
}

View File

@ -29,6 +29,4 @@ class Machine
public MachineType $type;
public array $idle = [];
}

View File

@ -144,6 +144,4 @@ final class ScheduleQueue
{
unset($this->queue[$id]);
}
}

View File

@ -9,7 +9,6 @@
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*
*/
declare(strict_types=1);

View File

@ -9,7 +9,6 @@
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*
*/
declare(strict_types=1);

View File

@ -9,7 +9,6 @@
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*
*/
declare(strict_types=1);

View File

@ -9,7 +9,6 @@
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*
*/
declare(strict_types=1);
@ -108,7 +107,7 @@ class GeneticOptimization
$parameterCount = \count(\reset($population));
// Genetic Algorithm Loop
for ($generation = 0; $generation < $generations; $generation++) {
for ($generation = 0; $generation < $generations; ++$generation) {
$fitnessScores = [];
foreach ($population as $parameters) {
$fitnessScores[] = ($fitness)($parameters);
@ -116,7 +115,7 @@ class GeneticOptimization
// Select parents for crossover based on fitness scores
$parents = [];
for ($i = 0; $i < $populationSize; $i++) {
for ($i = 0; $i < $populationSize; ++$i) {
do {
$parentIndex1 = \array_rand($population);
$parentIndex2 = \array_rand($population);

View File

@ -9,7 +9,6 @@
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*
*/
declare(strict_types=1);

View File

@ -9,7 +9,6 @@
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*
*/
declare(strict_types=1);

View File

@ -9,7 +9,6 @@
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*
*/
declare(strict_types=1);
@ -77,7 +76,7 @@ class SimulatedAnnealing
*
* @since 1.0.0
*/
function optimize(
public function optimize(
array $space,
int $initialTemperature,
\Closure $costFunction,
@ -96,7 +95,7 @@ class SimulatedAnnealing
$newCost = ($costFunction)($newGeneration);
$temperature = $initialTemperature * pow($coolingRate, $i);
$temperature = $initialTemperature * \pow($coolingRate, $i);
if ($newCost < $currentCost
|| \mt_rand() / \mt_getrandmax() < \exp(($currentCost - $newCost) / $temperature)
@ -108,7 +107,7 @@ class SimulatedAnnealing
return [
'solutions' => $currentGeneration,
'costs' => $currentCost
'costs' => $currentCost,
];
}
}

View File

@ -9,7 +9,6 @@
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*
*/
declare(strict_types=1);
@ -97,7 +96,7 @@ class TabuSearch
}
}
if (\is_null($bestNeighbor)) {
if ($bestNeighbor === null) {
break;
}
@ -108,7 +107,6 @@ class TabuSearch
$currentSolution = $bestNeighbor;
if (($score = ($fitness)($bestNeighbor)) > $bestFitness) {
$bestSolution = $bestNeighbor;
$bestFitness = $score;

View File

@ -166,7 +166,7 @@ final class Glicko1
return [
'elo' => (int) \max((int) $r, $this->MIN_ELO),
'rd' => (int) \max($RD_, $this->MIN_RD)
'rd' => (int) \max($RD_, $this->MIN_RD),
];
}
}

View File

@ -41,7 +41,6 @@ class TrueSkill
public function __construct()
{
}
// Draw margin = epsilon
@ -160,24 +159,20 @@ class TrueSkill
/ (NormalDistribution::getCdf($epsilon - $tAbs, 0.0, 1.0) - NormalDistribution::getCdf(-$epsilon - $tAbs, 0.0, 1.0));
}
private function buildRatingLayer()
private function buildRatingLayer() : void
{
}
private function buildPerformanceLayer()
private function buildPerformanceLayer() : void
{
}
private function buildTeamPerformanceLayer()
private function buildTeamPerformanceLayer() : void
{
}
private function buildTruncLayer()
private function buildTruncLayer() : void
{
}
private function factorGraphBuilders()
@ -198,7 +193,7 @@ class TrueSkill
];
}
public function rating()
public function rating() : void
{
// Start values
$mu = 25;
@ -214,7 +209,6 @@ class TrueSkill
$muPartial = $muOld * ($alpha - 1) * $sigmaNew * $sigmaNew - $muNew * $alpha * $sigmaOld * $sigmaOld
/ (($alpha - 1) * $sigmaNew * $sigmaNew - $alpha * $sigmaOld * $sigmaOld);
// New
$tau = $pi * $mu;
@ -223,12 +217,6 @@ class TrueSkill
$K = NormalDistribution::getCdf();
$pi = 1 / ($sigma * $sigma);
}
}

View File

@ -28,10 +28,13 @@ namespace phpOMS\Business\Recommendation;
final class BayesianPersonalizedRanking
{
private int $numFactors;
private float $learningRate;
private float $regularization;
private array $userFactors = [];
private array $itemFactors = [];
// num_factors determines the dimensionality of the latent factor space.
@ -64,7 +67,7 @@ final class BayesianPersonalizedRanking
return $score;
}
public function updateFactors($userId, $posItemId, $negItemId) {
public function updateFactors($userId, $posItemId, $negItemId) : void {
if (!isset($this->userFactors[$userId])) {
$this->userFactors[$userId] = $this->generateRandomFactors();
}

View File

@ -14,7 +14,6 @@ declare(strict_types=1);
namespace phpOMS\DataStorage\Session;
use phpOMS\DataStorage\LockException;
use phpOMS\Log\FileLogger;
use phpOMS\Message\RequestAbstract;
use phpOMS\Session\JWT;

View File

@ -61,7 +61,7 @@ final class Dispatcher implements DispatcherInterface
/**
* {@inheritdoc}
*/
public function dispatch(array | string | Callable $controller, mixed ...$data) : array
public function dispatch(array | string | callable $controller, mixed ...$data) : array
{
$views = [];
$data = \array_values($data);
@ -172,7 +172,7 @@ final class Dispatcher implements DispatcherInterface
*
* @since 1.0.0
*/
private function dispatchClosure(Callable $controller, array $data = null) : mixed
private function dispatchClosure(callable $controller, array $data = null) : mixed
{
return $data === null ? $controller($this->app) : $controller($this->app, ...$data);
}

View File

@ -36,5 +36,5 @@ interface DispatcherInterface
*
* @since 1.0.0
*/
public function dispatch(array | string | Callable $controller, mixed ...$data) : array;
public function dispatch(array | string | callable $controller, mixed ...$data) : array;
}

View File

@ -70,7 +70,7 @@ final class EventManager implements \Countable
/**
* {@inheritdoc}
*/
public function dispatch(array | string | Callable $func, mixed ...$data) : array
public function dispatch(array | string | callable $func, mixed ...$data) : array
{
if (!\is_callable($func)) {
return [];
@ -144,7 +144,7 @@ final class EventManager implements \Countable
*
* @since 1.0.0
*/
public function attach(string $group, string | Callable $callback, bool $remove = false, bool $reset = false) : bool
public function attach(string $group, string | callable $callback, bool $remove = false, bool $reset = false) : bool
{
if (!isset($this->callbacks[$group])) {
$this->callbacks[$group] = ['remove' => $remove, 'reset' => $reset, 'callbacks' => []];

View File

@ -256,7 +256,7 @@ final class Functions
-1.624290004647e-6,1.303655835580e-6,1.5626441722e-8,-8.5238095915e-8,
6.529054439e-9,5.059343495e-9,-9.91364156e-10,-2.27365122e-10,
9.6467911e-11, 2.394038e-12,-6.886027e-12,8.94487e-13, 3.13092e-13,
-1.12708e-13,3.81e-16,7.106e-15,-1.523e-15,-9.4e-17,1.21e-16,-2.8e-17
-1.12708e-13,3.81e-16,7.106e-15,-1.523e-15,-9.4e-17,1.21e-16,-2.8e-17,
];
/**
@ -322,7 +322,7 @@ final class Functions
$dd = $tmp;
}
return $t * \exp(-$z * $z + 0.5*(self::ERF_COF[0] + $ty * $d) - $dd);
return $t * \exp(-$z * $z + 0.5 * (self::ERF_COF[0] + $ty * $d) - $dd);
}
/**
@ -343,8 +343,8 @@ final class Functions
}
$pp = ($p < 1.0) ? $p : 2. - $p;
$t = sqrt(-2. * \log($pp / 2.));
$x = -0.70711 * ((2.30753 + $t * 0.27061)/(1. + $t * (0.99229 + $t * 0.04481)) - $t);
$t = \sqrt(-2. * \log($pp / 2.));
$x = -0.70711 * ((2.30753 + $t * 0.27061) / (1. + $t * (0.99229 + $t * 0.04481)) - $t);
for ($j = 0; $j < 2; ++$j) {
$err = self::getErfc($x) - $pp;

View File

@ -845,9 +845,9 @@ class Matrix implements \ArrayAccess, \Iterator
if ($this->isDiagonal()) {
$matrix = [];
for ($i = 0; $i < $this->m; $i++) {
for ($i = 0; $i < $this->m; ++$i) {
$row = [];
for ($j = 0; $j < $this->m; $j++) {
for ($j = 0; $j < $this->m; ++$j) {
if ($i === $j) {
$row[] = \pow($this->matrix[$i][$j], $exponent);
} else {

View File

@ -37,7 +37,7 @@ final class Integration
*
* @since 1.0.0
*/
public static function intLeftRect(float $from, float $to, float $n, Callable $func) : float
public static function intLeftRect(float $from, float $to, float $n, callable $func) : float
{
$h = ($to - $from) / $n;
$sum = 0.0;
@ -61,7 +61,7 @@ final class Integration
*
* @since 1.0.0
*/
public static function intRightRect(float $from, float $to, float $n, Callable $func) : float
public static function intRightRect(float $from, float $to, float $n, callable $func) : float
{
$h = ($to - $from) / $n;
$sum = 0.0;
@ -85,7 +85,7 @@ final class Integration
*
* @since 1.0.0
*/
public static function intMiddleRect(float $from, float $to, float $n, Callable $func) : float
public static function intMiddleRect(float $from, float $to, float $n, callable $func) : float
{
$h = ($to - $from) / $n;
$sum = 0.0;
@ -109,7 +109,7 @@ final class Integration
*
* @since 1.0.0
*/
public static function intTrapezium(float $from, float $to, float $n, Callable $func) : float
public static function intTrapezium(float $from, float $to, float $n, callable $func) : float
{
$h = ($to - $from) / $n;
$sum = $func($from) + $func($to);
@ -133,7 +133,7 @@ final class Integration
*
* @since 1.0.0
*/
public static function intSimpson(float $from, float $to, float $n, Callable $func) : float
public static function intSimpson(float $from, float $to, float $n, callable $func) : float
{
$h = ($to - $from) / $n;
$sum1 = 0.0;

View File

@ -48,7 +48,7 @@ final class Bisection
*
* @since 1.0.0
*/
public static function root(Callable $func, float $a, float $b, int $maxIterations = 100) : float
public static function root(callable $func, float $a, float $b, int $maxIterations = 100) : float
{
if ($func($a) * $func($b) >= 0) {
throw new \Exception("Function values at endpoints must have opposite signs.");

View File

@ -48,7 +48,7 @@ final class Illinois
*
* @since 1.0.0
*/
public static function root(Callable $func, float $a, float $b, int $maxIterations = 100) : float
public static function root(callable $func, float $a, float $b, int $maxIterations = 100) : float
{
if ($func($a) * $func($b) >= 0) {
throw new \Exception("Function values at endpoints must have opposite signs.");

View File

@ -48,7 +48,7 @@ final class RegulaFalsi
*
* @since 1.0.0
*/
public static function root(Callable $func, float $a, float $b, int $maxIterations = 100) : float
public static function root(callable $func, float $a, float $b, int $maxIterations = 100) : float
{
if ($func($a) * $func($b) >= 0) {
throw new \Exception("Function values at endpoints must have opposite signs.");

View File

@ -65,7 +65,7 @@ final class Kernels2D
public static function triangularKernel(float $distance, float $bandwidth) : float
{
return \abs($distance) <= $bandwidth / 2
? 1 - abs($distance) / ($bandwidth / 2)
? 1 - \abs($distance) / ($bandwidth / 2)
: 0.0;
}

View File

@ -112,7 +112,7 @@ final class MetricsND
}
$dotProduct = 0;
for ($i = 0; $i < \count($a); $i++) {
for ($i = 0; $i < \count($a); ++$i) {
$dotProduct += $a[$i] * $b[$i];
}

View File

@ -76,7 +76,7 @@ class Markdown
foreach ($this->DefinitionData['Footnote'] as $definitionId => $DefinitionData)
{
if ( ! isset($DefinitionData['number']))
if (! isset($DefinitionData['number']))
{
continue;
}
@ -95,7 +95,7 @@ class Markdown
$backLinkElements[] = [
'name' => 'a',
'attributes' => [
'href' => "#fnref$number:$definitionId",
'href' => "#fnref{$number}:{$definitionId}",
'rev' => 'footnote',
'class' => 'footnote-backref',
],
@ -107,7 +107,7 @@ class Markdown
unset($backLinkElements[0]);
$n = \count($textElements) -1;
$n = \count($textElements) - 1;
if ($textElements[$n]['name'] === 'p')
{
@ -135,7 +135,7 @@ class Markdown
{
$textElements[] = [
'name' => 'p',
'elements' => $backLinkElements
'elements' => $backLinkElements,
];
}
@ -200,7 +200,7 @@ class Markdown
protected bool $urlsLinked = true;
function setSafeMode($safeMode)
public function setSafeMode($safeMode)
{
$this->safeMode = (bool) $safeMode;
@ -209,7 +209,7 @@ class Markdown
public bool $safeMode = false;
function setStrictMode($strictMode)
public function setStrictMode($strictMode)
{
$this->strictMode = (bool) $strictMode;
@ -302,7 +302,7 @@ class Markdown
while (($beforeTab = \strstr($line, "\t", true)) !== false)
{
$shortage = 4 - mb_strlen($beforeTab, 'utf-8') % 4;
$shortage = 4 - \mb_strlen($beforeTab, 'utf-8') % 4;
$line = $beforeTab
. \str_repeat(' ', $shortage)
@ -323,7 +323,7 @@ class Markdown
if (isset($CurrentBlock['continuable']))
{
$methodName = 'block' . $CurrentBlock['type'] . 'Continue';
$Block = $this->$methodName($Line, $CurrentBlock);
$Block = $this->{$methodName}($Line, $CurrentBlock);
if (isset($Block))
{
@ -336,7 +336,7 @@ class Markdown
if ($this->isBlockCompletable($CurrentBlock['type']))
{
$methodName = 'block' . $CurrentBlock['type'] . 'Complete';
$CurrentBlock = $this->$methodName($CurrentBlock);
$CurrentBlock = $this->{$methodName}($CurrentBlock);
}
}
}
@ -362,13 +362,13 @@ class Markdown
foreach ($blockTypes as $blockType)
{
$Block = $this->{"block$blockType"}($Line, $CurrentBlock);
$Block = $this->{"block{$blockType}"}($Line, $CurrentBlock);
if (isset($Block))
{
$Block['type'] = $blockType;
if ( ! isset($Block['identified']))
if (! isset($Block['identified']))
{
if (isset($CurrentBlock))
{
@ -418,7 +418,7 @@ class Markdown
if (isset($CurrentBlock['continuable']) && $this->isBlockCompletable($CurrentBlock['type']))
{
$methodName = 'block' . $CurrentBlock['type'] . 'Complete';
$CurrentBlock = $this->$methodName($CurrentBlock);
$CurrentBlock = $this->{$methodName}($CurrentBlock);
}
# ~
@ -435,7 +435,7 @@ class Markdown
protected function extractElement(array $Component)
{
if ( ! isset($Component['element']))
if (! isset($Component['element']))
{
if (isset($Component['markup']))
{
@ -452,12 +452,12 @@ class Markdown
protected function isBlockContinuable($Type)
{
return method_exists($this, 'block' . $Type . 'Continue');
return \method_exists($this, 'block' . $Type . 'Continue');
}
protected function isBlockCompletable($Type)
{
return method_exists($this, 'block' . $Type . 'Complete');
return \method_exists($this, 'block' . $Type . 'Complete');
}
#
@ -524,7 +524,7 @@ class Markdown
return;
}
if (strpos($Line['text'], '<!--') === 0)
if (\strpos($Line['text'], '<!--') === 0)
{
$Block = [
'element' => [
@ -533,7 +533,7 @@ class Markdown
],
];
if (strpos($Line['text'], '-->') !== false)
if (\strpos($Line['text'], '-->') !== false)
{
$Block['closed'] = true;
}
@ -551,7 +551,7 @@ class Markdown
$Block['element']['rawHtml'] .= "\n" . $Line['body'];
if (strpos($Line['text'], '-->') !== false)
if (\strpos($Line['text'], '-->') !== false)
{
$Block['closed'] = true;
}
@ -575,7 +575,7 @@ class Markdown
$infostring = \trim(\substr($Line['text'], $openerLength), "\t ");
if (strpos($infostring, '`') !== false)
if (\strpos($infostring, '`') !== false)
{
return;
}
@ -599,9 +599,9 @@ class Markdown
* U+000A LINE FEED (LF), U+000C FORM FEED (FF), and
* U+000D CARRIAGE RETURN (CR).
*/
$language = \substr($infostring, 0, strcspn($infostring, " \t\n\f\r"));
$language = \substr($infostring, 0, \strcspn($infostring, " \t\n\f\r"));
$Element['attributes'] = ['class' => "language-$language"];
$Element['attributes'] = ['class' => "language-{$language}"];
}
$Block = [
@ -721,7 +721,7 @@ class Markdown
protected function blockDefinitionList($Line, $Block)
{
if ( ! isset($Block) || $Block['type'] !== 'Paragraph')
if (! isset($Block) || $Block['type'] !== 'Paragraph')
{
return;
}
@ -740,7 +740,7 @@ class Markdown
'handler' => [
'function' => 'lineElements',
'argument' => $term,
'destination' => 'elements'
'destination' => 'elements',
],
];
}
@ -777,7 +777,7 @@ class Markdown
unset($Block['interrupted']);
}
$text = \substr($Line['body'], min($Line['indent'], 4));
$text = \substr($Line['body'], \min($Line['indent'], 4));
$Block['dd']['handler']['argument'] .= "\n" . $text;
@ -797,7 +797,7 @@ class Markdown
'handler' => [
'function' => 'lineElements',
'argument' => $text,
'destination' => 'elements'
'destination' => 'elements',
],
];
@ -841,11 +841,11 @@ class Markdown
'function' => 'lineElements',
'argument' => $text,
'destination' => 'elements',
]
],
],
];
if ($Block !== null && \preg_match('/[ #]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['handler']['argument'], $matches, PREG_OFFSET_CAPTURE))
if ($Block !== null && \preg_match('/[ #]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['handler']['argument'], $matches, \PREG_OFFSET_CAPTURE))
{
$attributeString = $matches[1][0];
@ -870,7 +870,7 @@ class Markdown
if ($contentIndent >= 5)
{
$contentIndent -= 1;
--$contentIndent;
$matches[1] = \substr($matches[1], 0, -$contentIndent);
$matches[3] = \str_repeat(' ', $contentIndent) . $matches[3];
}
@ -919,8 +919,8 @@ class Markdown
'handler' => [
'function' => 'li',
'argument' => !empty($matches[3]) ? [$matches[3]] : [],
'destination' => 'elements'
]
'destination' => 'elements',
],
];
$Block['element']['elements'] []= & $Block['li'];
@ -969,8 +969,8 @@ class Markdown
'handler' => [
'function' => 'li',
'argument' => [$text],
'destination' => 'elements'
]
'destination' => 'elements',
],
];
$Block['element']['elements'] []= & $Block['li'];
@ -1005,7 +1005,7 @@ class Markdown
return $Block;
}
if ( ! isset($Block['interrupted']))
if (! isset($Block['interrupted']))
{
$text = \preg_replace('/^[ ]{0,'.$requiredIndent.'}+/', '', $Line['body']);
@ -1021,7 +1021,7 @@ class Markdown
{
foreach ($Block['element']['elements'] as &$li)
{
if (end($li['handler']['argument']) !== '')
if (\end($li['handler']['argument']) !== '')
{
$li['handler']['argument'] []= '';
}
@ -1045,7 +1045,7 @@ class Markdown
'function' => 'linesElements',
'argument' => (array) $matches[1],
'destination' => 'elements',
]
],
],
];
@ -1067,7 +1067,7 @@ class Markdown
return $Block;
}
if ( ! isset($Block['interrupted']))
if (! isset($Block['interrupted']))
{
$Block['element']['handler']['argument'] []= $Line['text'];
@ -1082,7 +1082,7 @@ class Markdown
{
$marker = $Line['text'][0];
if (\substr_count($Line['text'], $marker) >= 3 && \rtrim($Line['text'], " $marker") === '')
if (\substr_count($Line['text'], $marker) >= 3 && \rtrim($Line['text'], " {$marker}") === '')
{
$Block = [
'element' => [
@ -1099,7 +1099,7 @@ class Markdown
protected function blockSetextHeader($Line, array $Block = null)
{
if ( ! isset($Block) || $Block['type'] !== 'Paragraph' || isset($Block['interrupted']))
if (! isset($Block) || $Block['type'] !== 'Paragraph' || isset($Block['interrupted']))
{
return;
}
@ -1109,7 +1109,7 @@ class Markdown
$Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2';
}
if ($Block !== null && \preg_match('/[ ]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['handler']['argument'], $matches, PREG_OFFSET_CAPTURE))
if ($Block !== null && \preg_match('/[ ]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['handler']['argument'], $matches, \PREG_OFFSET_CAPTURE))
{
$attributeString = $matches[1][0];
@ -1127,14 +1127,14 @@ class Markdown
{
$name = $matches[1];
if ( ! isset($this->DefinitionData['Footnote'][$name]))
if (! isset($this->DefinitionData['Footnote'][$name]))
{
return;
}
$this->DefinitionData['Footnote'][$name]['count'] ++;
++$this->DefinitionData['Footnote'][$name]['count'];
if ( ! isset($this->DefinitionData['Footnote'][$name]['number']))
if (! isset($this->DefinitionData['Footnote'][$name]['number']))
{
$this->DefinitionData['Footnote'][$name]['number'] = ++ $this->footnoteCount; # » &
}
@ -1189,7 +1189,7 @@ class Markdown
$length = \strlen($matches[0]);
$remainder = \substr($Line['text'], $length);
if (trim($remainder) === '')
if (\trim($remainder) === '')
{
if (isset($matches[2]) || \in_array($matches[1], $this->voidElements))
{
@ -1222,14 +1222,14 @@ class Markdown
if (\preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open
{
$Block['depth'] ++;
++$Block['depth'];
}
if (\preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close
{
if ($Block['depth'] > 0)
{
$Block['depth'] --;
--$Block['depth'];
}
else
{
@ -1250,7 +1250,7 @@ class Markdown
protected function blockMarkupComplete($Block)
{
if ( ! isset($Block['void']))
if (! isset($Block['void']))
{
$Block['element']['rawHtml'] = $this->processTag($Block['element']['rawHtml']);
}
@ -1261,12 +1261,12 @@ class Markdown
protected function processTag($elementMarkup) # recursive
{
# http://stackoverflow.com/q/1148928/200145
libxml_use_internal_errors(true);
\libxml_use_internal_errors(true);
$DOMDocument = new \DOMDocument();
# http://stackoverflow.com/q/11309194/200145
$elementMarkup = mb_convert_encoding($elementMarkup, 'HTML-ENTITIES', 'UTF-8');
$elementMarkup = \mb_convert_encoding($elementMarkup, 'HTML-ENTITIES', 'UTF-8');
# http://stackoverflow.com/q/4879946/200145
$DOMDocument->loadHTML($elementMarkup);
@ -1317,7 +1317,7 @@ class Markdown
protected function blockReference($Line)
{
if (strpos($Line['text'], ']') !== false
if (\strpos($Line['text'], ']') !== false
&& \preg_match('/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $Line['text'], $matches)
) {
$id = \strtolower($matches[1]);
@ -1342,7 +1342,7 @@ class Markdown
protected function blockTable($Line, array $Block = null)
{
if ( ! isset($Block) || $Block['type'] !== 'Paragraph' || isset($Block['interrupted']))
if (! isset($Block) || $Block['type'] !== 'Paragraph' || isset($Block['interrupted']))
{
return;
}
@ -1405,7 +1405,7 @@ class Markdown
$headerCells = \explode('|', $header);
if (count($headerCells) !== \count($alignments))
if (\count($headerCells) !== \count($alignments))
{
return;
}
@ -1420,7 +1420,7 @@ class Markdown
'function' => 'lineElements',
'argument' => $headerCell,
'destination' => 'elements',
]
],
];
if (isset($alignments[$index]))
@ -1428,7 +1428,7 @@ class Markdown
$alignment = $alignments[$index];
$HeaderElement['attributes'] = [
'style' => "text-align: $alignment;",
'style' => "text-align: {$alignment};",
];
}
@ -1470,7 +1470,7 @@ class Markdown
return;
}
if (count($Block['alignments']) === 1 || $Line['text'][0] === '|' || \strpos($Line['text'], '|'))
if (\count($Block['alignments']) === 1 || $Line['text'][0] === '|' || \strpos($Line['text'], '|'))
{
$Elements = [];
@ -1479,9 +1479,9 @@ class Markdown
$row = \trim($row);
$row = \trim($row, '|');
preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]++`|`)++/', $row, $matches);
\preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]++`|`)++/', $row, $matches);
$cells = array_slice($matches[0], 0, \count($Block['alignments']));
$cells = \array_slice($matches[0], 0, \count($Block['alignments']));
foreach ($cells as $index => $cell)
{
@ -1493,7 +1493,7 @@ class Markdown
'function' => 'lineElements',
'argument' => $cell,
'destination' => 'elements',
]
],
];
if (isset($Block['alignments'][$index]))
@ -1609,9 +1609,9 @@ class Markdown
continue;
}
$Inline = $this->{"inline$inlineType"}($Excerpt);
$Inline = $this->{"inline{$inlineType}"}($Excerpt);
if ( ! isset($Inline))
if (! isset($Inline))
{
continue;
}
@ -1625,14 +1625,13 @@ class Markdown
# sets a default inline position
if ( ! isset($Inline['position']))
if (! isset($Inline['position']))
{
$Inline['position'] = $markerPosition;
}
# cause the new element to 'inherit' our non nestables
$Inline['element']['nonNestables'] = isset($Inline['element']['nonNestables'])
? \array_merge($Inline['element']['nonNestables'], $nonNestables)
: $nonNestables
@ -1669,7 +1668,7 @@ class Markdown
foreach ($Elements as &$Element)
{
if ( ! isset($Element['autobreak']))
if (! isset($Element['autobreak']))
{
$Element['autobreak'] = false;
}
@ -1741,14 +1740,14 @@ class Markdown
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@'
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
if (strpos($Excerpt['text'], '>') !== false
&& \preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt['text'], $matches)
if (\strpos($Excerpt['text'], '>') !== false
&& \preg_match("/^<((mailto:)?{$commonMarkEmail})>/i", $Excerpt['text'], $matches)
){
$url = $matches[1];
if ( ! isset($matches[2]))
if (! isset($matches[2]))
{
$url = "mailto:$url";
$url = "mailto:{$url}";
}
return [
@ -1766,7 +1765,7 @@ class Markdown
protected function inlineEmphasis($Excerpt)
{
if ( ! isset($Excerpt['text'][1]))
if (! isset($Excerpt['text'][1]))
{
return;
}
@ -1794,7 +1793,7 @@ class Markdown
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
]
],
],
];
}
@ -1812,7 +1811,7 @@ class Markdown
protected function inlineImage($Excerpt)
{
if ( ! isset($Excerpt['text'][1]) || $Excerpt['text'][1] !== '[')
if (! isset($Excerpt['text'][1]) || $Excerpt['text'][1] !== '[')
{
return;
}
@ -1903,7 +1902,7 @@ class Markdown
$definition = \strtolower($Element['handler']['argument']);
}
if ( ! isset($this->DefinitionData['Reference'][$definition]))
if (! isset($this->DefinitionData['Reference'][$definition]))
{
return;
}
@ -1935,7 +1934,7 @@ class Markdown
{
$Data = [];
$attributes = preg_split('/[ ]+/', $attributeString, - 1, PREG_SPLIT_NO_EMPTY);
$attributes = \preg_split('/[ ]+/', $attributeString, - 1, \PREG_SPLIT_NO_EMPTY);
foreach ($attributes as $attribute)
{
@ -1951,13 +1950,14 @@ class Markdown
if (isset($classes))
{
$Data['class'] = implode(' ', $classes);
$Data['class'] = \implode(' ', $classes);
}
return $Data;
}
private $currentAbreviation;
private $currentMeaning;
protected function insertAbreviation(array $Element)
@ -1973,7 +1973,7 @@ class Markdown
'title' => $this->currentMeaning,
],
'text' => $this->currentAbreviation,
]
],
],
$Element['text']
);
@ -2026,13 +2026,11 @@ class Markdown
'extent' => \strlen($matches[0]),
];
}
return;
}
protected function inlineStrikethrough($Excerpt)
{
if ( ! isset($Excerpt['text'][1]))
if (! isset($Excerpt['text'][1]))
{
return;
}
@ -2047,7 +2045,7 @@ class Markdown
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
]
],
],
];
}
@ -2060,8 +2058,8 @@ class Markdown
return;
}
if (strpos($Excerpt['context'], 'http') !== false
&& \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)
if (\strpos($Excerpt['context'], 'http') !== false
&& \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt['context'], $matches, \PREG_OFFSET_CAPTURE)
) {
$url = $matches[0][0];
@ -2083,7 +2081,7 @@ class Markdown
protected function inlineUrlTag($Excerpt)
{
if (strpos($Excerpt['text'], '>') !== false && \preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt['text'], $matches))
if (\strpos($Excerpt['text'], '>') !== false && \preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt['text'], $matches))
{
$url = $matches[1];
@ -2121,7 +2119,7 @@ class Markdown
$Element['nonNestables'] = [];
}
if (is_string($Element['handler']))
if (\is_string($Element['handler']))
{
$function = $Element['handler'];
$argument = $Element['text'];
@ -2237,7 +2235,7 @@ class Markdown
continue;
}
$markup .= " $name=\"".self::escape($value).'"';
$markup .= " {$name}=\"".self::escape($value).'"';
}
}
}
@ -2328,8 +2326,8 @@ class Markdown
{
$Elements = $this->linesElements($lines);
if ( ! \in_array('', $lines)
&& isset($Elements[0]) && isset($Elements[0]['name'])
if (! \in_array('', $lines)
&& isset($Elements[0], $Elements[0]['name'])
&& $Elements[0]['name'] === 'p'
) {
unset($Elements[0]['name']);
@ -2350,7 +2348,7 @@ class Markdown
{
$newElements = [];
while (\preg_match($regexp, $text, $matches, PREG_OFFSET_CAPTURE))
while (\preg_match($regexp, $text, $matches, \PREG_OFFSET_CAPTURE))
{
$offset = (int) $matches[0][1];
$before = \substr($text, 0, $offset);
@ -2392,7 +2390,7 @@ class Markdown
'img' => 'src',
];
if ( ! isset($Element['name']))
if (! isset($Element['name']))
{
unset($Element['attributes']);
return $Element;
@ -2403,12 +2401,12 @@ class Markdown
$Element = $this->filterUnsafeUrlInAttribute($Element, $safeUrlNameToAtt[$Element['name']]);
}
if ( ! empty($Element['attributes']))
if (! empty($Element['attributes']))
{
foreach ($Element['attributes'] as $att => $val)
{
# filter out badly parsed attribute
if ( ! \preg_match($goodAttribute, $att))
if (! \preg_match($goodAttribute, $att))
{
unset($Element['attributes'][$att]);
}
@ -2444,7 +2442,7 @@ class Markdown
protected static function escape($text, $allowQuotes = false)
{
return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8');
return \htmlspecialchars($text, $allowQuotes ? \ENT_NOQUOTES : \ENT_QUOTES, 'UTF-8');
}
protected static function striAtStart($string, $needle)
@ -2461,7 +2459,7 @@ class Markdown
}
}
static function instance($name = 'default')
public static function instance($name = 'default')
{
if (isset(self::$instances[$name]))
{
@ -2487,7 +2485,7 @@ class Markdown
# Read-Only
protected array $specialCharacters = [
'\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', '~'
'\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', '~',
];
protected array $StrongRegex = [
@ -2517,5 +2515,4 @@ class Markdown
'var', 'span',
'wbr', 'time',
];
}