diff --git a/Algorithm/Clustering/DBSCAN.php b/Algorithm/Clustering/DBSCAN.php index 99102d72a..72f3a82fb 100644 --- a/Algorithm/Clustering/DBSCAN.php +++ b/Algorithm/Clustering/DBSCAN.php @@ -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 diff --git a/Algorithm/Clustering/MeanShift.php b/Algorithm/Clustering/MeanShift.php index a9f1a30f3..e299e27be 100644 --- a/Algorithm/Clustering/MeanShift.php +++ b/Algorithm/Clustering/MeanShift.php @@ -160,7 +160,7 @@ final class MeanShift // @todo create an array of noisePoints like in the DBSCAN. That array can be empty or not depending on the bandwidth defined - $this->clusters = $this->groupPoints($shiftPoints); + $this->clusters = $this->groupPoints($shiftPoints); $this->clusterCenters = $shiftPoints; } @@ -215,8 +215,8 @@ final class MeanShift private function groupPoints(array $points) : array { $groupAssignment = []; - $groups = []; - $groupIndex = 0; + $groups = []; + $groupIndex = 0; foreach ($points as $point) { $nearestGroupIndex = $this->findNearestGroup($point, $groups); diff --git a/Algorithm/JobScheduling/v2/Dependency/IdleTime.php b/Algorithm/JobScheduling/v2/Dependency/IdleTime.php index 8b9aa93a0..6cba29aae 100644 --- a/Algorithm/JobScheduling/v2/Dependency/IdleTime.php +++ b/Algorithm/JobScheduling/v2/Dependency/IdleTime.php @@ -33,6 +33,4 @@ class IdleTime public int $interval = 0; public int $duration = 0; // in seconds - - } diff --git a/Algorithm/JobScheduling/v2/Dependency/Machine.php b/Algorithm/JobScheduling/v2/Dependency/Machine.php index bccc9f8c7..de1c555e4 100644 --- a/Algorithm/JobScheduling/v2/Dependency/Machine.php +++ b/Algorithm/JobScheduling/v2/Dependency/Machine.php @@ -29,6 +29,4 @@ class Machine public MachineType $type; public array $idle = []; - - } diff --git a/Algorithm/JobScheduling/v2/ScheduleQueue.php b/Algorithm/JobScheduling/v2/ScheduleQueue.php index f21f1e0f0..1ed3995b3 100644 --- a/Algorithm/JobScheduling/v2/ScheduleQueue.php +++ b/Algorithm/JobScheduling/v2/ScheduleQueue.php @@ -144,6 +144,4 @@ final class ScheduleQueue { unset($this->queue[$id]); } - - } diff --git a/Algorithm/Optimization/AntColonyOptimization.php b/Algorithm/Optimization/AntColonyOptimization.php index e288c7dc2..dcb71d35c 100644 --- a/Algorithm/Optimization/AntColonyOptimization.php +++ b/Algorithm/Optimization/AntColonyOptimization.php @@ -9,7 +9,6 @@ * @license OMS License 2.0 * @version 1.0.0 * @link https://jingga.app - * */ declare(strict_types=1); diff --git a/Algorithm/Optimization/BeesAlgorithm.php b/Algorithm/Optimization/BeesAlgorithm.php index a102fe272..069f3d8c2 100644 --- a/Algorithm/Optimization/BeesAlgorithm.php +++ b/Algorithm/Optimization/BeesAlgorithm.php @@ -9,7 +9,6 @@ * @license OMS License 2.0 * @version 1.0.0 * @link https://jingga.app - * */ declare(strict_types=1); diff --git a/Algorithm/Optimization/FireflyAlgorithm.php b/Algorithm/Optimization/FireflyAlgorithm.php index 9deb5df0e..c4286c271 100644 --- a/Algorithm/Optimization/FireflyAlgorithm.php +++ b/Algorithm/Optimization/FireflyAlgorithm.php @@ -9,7 +9,6 @@ * @license OMS License 2.0 * @version 1.0.0 * @link https://jingga.app - * */ declare(strict_types=1); diff --git a/Algorithm/Optimization/GeneticOptimization.php b/Algorithm/Optimization/GeneticOptimization.php index 0a3db8125..5c5969e3a 100644 --- a/Algorithm/Optimization/GeneticOptimization.php +++ b/Algorithm/Optimization/GeneticOptimization.php @@ -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); diff --git a/Algorithm/Optimization/HarmonySearch.php b/Algorithm/Optimization/HarmonySearch.php index 04380666c..74a36486a 100644 --- a/Algorithm/Optimization/HarmonySearch.php +++ b/Algorithm/Optimization/HarmonySearch.php @@ -9,7 +9,6 @@ * @license OMS License 2.0 * @version 1.0.0 * @link https://jingga.app - * */ declare(strict_types=1); diff --git a/Algorithm/Optimization/IntelligentWaterDrops.php b/Algorithm/Optimization/IntelligentWaterDrops.php index 90eab147b..283b689f6 100644 --- a/Algorithm/Optimization/IntelligentWaterDrops.php +++ b/Algorithm/Optimization/IntelligentWaterDrops.php @@ -9,7 +9,6 @@ * @license OMS License 2.0 * @version 1.0.0 * @link https://jingga.app - * */ declare(strict_types=1); diff --git a/Algorithm/Optimization/SimulatedAnnealing.php b/Algorithm/Optimization/SimulatedAnnealing.php index 44e023e05..b0813f20a 100644 --- a/Algorithm/Optimization/SimulatedAnnealing.php +++ b/Algorithm/Optimization/SimulatedAnnealing.php @@ -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,19 +95,19 @@ 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) ) { $currentGeneration = $newGeneration; - $currentCost = $newCost; + $currentCost = $newCost; } } return [ 'solutions' => $currentGeneration, - 'costs' => $currentCost + 'costs' => $currentCost, ]; } } diff --git a/Algorithm/Optimization/TabuSearch.php b/Algorithm/Optimization/TabuSearch.php index abd08481f..669e4c101 100644 --- a/Algorithm/Optimization/TabuSearch.php +++ b/Algorithm/Optimization/TabuSearch.php @@ -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; diff --git a/Algorithm/Rating/Glicko1.php b/Algorithm/Rating/Glicko1.php index 72368ff40..7fdc7ba47 100644 --- a/Algorithm/Rating/Glicko1.php +++ b/Algorithm/Rating/Glicko1.php @@ -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), ]; } } diff --git a/Algorithm/Rating/Glicko2.php b/Algorithm/Rating/Glicko2.php index 30bab1952..5f2144947 100644 --- a/Algorithm/Rating/Glicko2.php +++ b/Algorithm/Rating/Glicko2.php @@ -124,7 +124,7 @@ final class Glicko2 // Step 1: $g = []; foreach ($oRd as $rd) { - $g[] = 1 / \sqrt(1 + 3 * $rd * $rd / (\M_PI * \M_PI)); + $g[] = 1 / \sqrt(1 + 3 * $rd * $rd / (\M_PI * \M_PI)); } $E = []; diff --git a/Algorithm/Rating/TrueSkill.php b/Algorithm/Rating/TrueSkill.php index 1372f81b7..661b17aa1 100644 --- a/Algorithm/Rating/TrueSkill.php +++ b/Algorithm/Rating/TrueSkill.php @@ -41,7 +41,6 @@ class TrueSkill public function __construct() { - } // Draw margin = epsilon @@ -104,15 +103,15 @@ class TrueSkill private function vDraw(float $t, float $epsilon) : float { $tAbs = \abs($t); - $a = $epsilon - $tAbs; - $b = -$epsilon - $tAbs; + $a = $epsilon - $tAbs; + $b = -$epsilon - $tAbs; - $aPdf = NormalDistribution::getPdf($a, 0.0, 1.0); - $bPdf = NormalDistribution::getPdf($b, 0.0, 1.0); + $aPdf = NormalDistribution::getPdf($a, 0.0, 1.0); + $bPdf = NormalDistribution::getPdf($b, 0.0, 1.0); $numer = $bPdf - $aPdf; - $aCdf = NormalDistribution::getCdf($a, 0.0, 1.0); - $bCdf = NormalDistribution::getCdf($b, 0.0, 1.0); + $aCdf = NormalDistribution::getCdf($a, 0.0, 1.0); + $bCdf = NormalDistribution::getCdf($b, 0.0, 1.0); $denom = $aCdf - $bCdf; return $numer / $denom; @@ -156,28 +155,24 @@ class TrueSkill $v = $this->vDraw($t, $epsilon); return $v * $v - + (($epsilon - $t) * NormalDistribution::getPdf($epsilon - $tAbs, 0.0, 1.0) + ($epsilon + $tAbs) * NormalDistribution::getPdf($epsilon + $tAbs, 0.0, 1.0)) - / (NormalDistribution::getCdf($epsilon - $tAbs, 0.0, 1.0) - NormalDistribution::getCdf(-$epsilon - $tAbs, 0.0, 1.0)); + + (($epsilon - $t) * NormalDistribution::getPdf($epsilon - $tAbs, 0.0, 1.0) + ($epsilon + $tAbs) * NormalDistribution::getPdf($epsilon + $tAbs, 0.0, 1.0)) + / (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() @@ -191,44 +186,37 @@ class TrueSkill // Trunc layer return [ - 'rating_layer' => $ratingLayer, - 'performance_layer' => $ratingLayer, + 'rating_layer' => $ratingLayer, + 'performance_layer' => $ratingLayer, 'team_performance_layer' => $ratingLayer, - 'trunc_layer' => $ratingLayer, + 'trunc_layer' => $ratingLayer, ]; } - public function rating() + public function rating() : void { // Start values - $mu = 25; + $mu = 25; $sigma = $mu / 3; - $beta = $sigma / 2; - $tau = $sigma / 100; + $beta = $sigma / 2; + $tau = $sigma / 100; $Pdraw = 0.1; $alpha = 0.25; // Partial update $sigmaPartial = $sigmaOld * $sigmaNew / \sqrt($alpha * $sigmaOld * $sigmaOld - ($alpha - 1) * $sigmaNew * $sigmaNew); - $muPartial = $muOld * ($alpha - 1) * $sigmaNew * $sigmaNew - $muNew * $alpha * $sigmaOld * $sigmaOld + $muPartial = $muOld * ($alpha - 1) * $sigmaNew * $sigmaNew - $muNew * $alpha * $sigmaOld * $sigmaOld / (($alpha - 1) * $sigmaNew * $sigmaNew - $alpha * $sigmaOld * $sigmaOld); - // New $tau = $pi * $mu; - $P = NormalDistribution::getCdf(($s1 - $s2) / (\sqrt(2) * $beta)); + $P = NormalDistribution::getCdf(($s1 - $s2) / (\sqrt(2) * $beta)); $Delta = $alpha * $beta * \sqrt($pi) * (($y + 1) / 2 - $P); $K = NormalDistribution::getCdf(); - - - - $pi = 1 / ($sigma * $sigma); } - - } diff --git a/Business/Recommendation/BayesianPersonalizedRanking.php b/Business/Recommendation/BayesianPersonalizedRanking.php index 56778436b..8ad29da1a 100644 --- a/Business/Recommendation/BayesianPersonalizedRanking.php +++ b/Business/Recommendation/BayesianPersonalizedRanking.php @@ -28,18 +28,21 @@ 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. // learning_rate controls the step size for updating the latent factors during optimization. // regularization prevents overfitting by adding a penalty for large parameter values. public function __construct(int $numFactors, float $learningRate, float $regularization) { - $this->numFactors = $numFactors; - $this->learningRate = $learningRate; + $this->numFactors = $numFactors; + $this->learningRate = $learningRate; $this->regularization = $regularization; } @@ -55,7 +58,7 @@ final class BayesianPersonalizedRanking public function predict($userId, $itemId) { $userFactor = $this->userFactors[$userId]; $itemFactor = $this->itemFactors[$itemId]; - $score = 0; + $score = 0; for ($i = 0; $i < $this->numFactors; ++$i) { $score += $userFactor[$i] * $itemFactor[$i]; @@ -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(); } @@ -77,17 +80,17 @@ final class BayesianPersonalizedRanking $this->itemFactors[$negItemId] = $this->generateRandomFactors(); } - $userFactor = $this->userFactors[$userId]; + $userFactor = $this->userFactors[$userId]; $posItemFactor = $this->itemFactors[$posItemId]; $negItemFactor = $this->itemFactors[$negItemId]; for ($i = 0; $i < $this->numFactors; ++$i) { - $userFactor[$i] += $this->learningRate * ($posItemFactor[$i] - $negItemFactor[$i]) - $this->regularization * $userFactor[$i]; + $userFactor[$i] += $this->learningRate * ($posItemFactor[$i] - $negItemFactor[$i]) - $this->regularization * $userFactor[$i]; $posItemFactor[$i] += $this->learningRate * $userFactor[$i] - $this->regularization * $posItemFactor[$i]; $negItemFactor[$i] += $this->learningRate * (-$userFactor[$i]) - $this->regularization * $negItemFactor[$i]; } - $this->userFactors[$userId] = $userFactor; + $this->userFactors[$userId] = $userFactor; $this->itemFactors[$posItemId] = $posItemFactor; $this->itemFactors[$negItemId] = $negItemFactor; } diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index 15fa1b015..ab5c88a21 100755 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -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; diff --git a/DataStorage/Session/JWT.php b/DataStorage/Session/JWT.php index a11987303..01f2e2dec 100644 --- a/DataStorage/Session/JWT.php +++ b/DataStorage/Session/JWT.php @@ -35,8 +35,8 @@ final class JWT /** * Create JWT signature part * - * @param string $secret Secret (at least 256 bit) - * @param array{alg:string, typ:string} $header Header + * @param string $secret Secret (at least 256 bit) + * @param array{alg:string, typ:string} $header Header * @param array{sub:string, ?uid:string, ?name:string, iat:string} $payload Payload * * @return string hmac(Header64 . Payload64, secret) @@ -60,8 +60,8 @@ final class JWT /** * Create JWT token * - * @param string $secret Secret (at least 256 bit) - * @param array{alg:string, typ:string} $header Header + * @param string $secret Secret (at least 256 bit) + * @param array{alg:string, typ:string} $header Header * @param array{sub:string, ?uid:string, ?name:string, iat:string} $payload Payload * * @return string Header64 . Payload64 . hmac(Header64 . Payload64, secret) @@ -128,8 +128,8 @@ final class JWT /** * Validate JWT token integrity * - * @param string $secret Secret (at least 256 bit) - * @param string $jwt JWT token [Header64 . Payload64 . hmac(Header64 . Payload64, secret)] + * @param string $secret Secret (at least 256 bit) + * @param string $jwt JWT token [Header64 . Payload64 . hmac(Header64 . Payload64, secret)] * * @return bool * diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index 90f72c528..e80ce2c9e 100755 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -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); } diff --git a/Dispatcher/DispatcherInterface.php b/Dispatcher/DispatcherInterface.php index 76c73c197..772eb6a84 100755 --- a/Dispatcher/DispatcherInterface.php +++ b/Dispatcher/DispatcherInterface.php @@ -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; } diff --git a/Event/EventManager.php b/Event/EventManager.php index c0d267951..ac9cf84e2 100755 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -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' => []]; diff --git a/Math/Functions/Functions.php b/Math/Functions/Functions.php index 10f116510..e2eed8673 100755 --- a/Math/Functions/Functions.php +++ b/Math/Functions/Functions.php @@ -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; diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index b0360a4e7..ade029c5f 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -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 { diff --git a/Math/Numerics/Integration.php b/Math/Numerics/Integration.php index 4628539e1..c46228345 100755 --- a/Math/Numerics/Integration.php +++ b/Math/Numerics/Integration.php @@ -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; diff --git a/Math/Solver/Root/Bisection.php b/Math/Solver/Root/Bisection.php index 3746a15f7..23fd7eaa7 100644 --- a/Math/Solver/Root/Bisection.php +++ b/Math/Solver/Root/Bisection.php @@ -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."); diff --git a/Math/Solver/Root/Illinois.php b/Math/Solver/Root/Illinois.php index c14caa650..90b5d8091 100644 --- a/Math/Solver/Root/Illinois.php +++ b/Math/Solver/Root/Illinois.php @@ -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."); diff --git a/Math/Solver/Root/RegulaFalsi.php b/Math/Solver/Root/RegulaFalsi.php index 180646018..fe9bb9210 100644 --- a/Math/Solver/Root/RegulaFalsi.php +++ b/Math/Solver/Root/RegulaFalsi.php @@ -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."); diff --git a/Math/Statistic/MeasureOfDispersion.php b/Math/Statistic/MeasureOfDispersion.php index 63ceaea2e..e63b1c42f 100755 --- a/Math/Statistic/MeasureOfDispersion.php +++ b/Math/Statistic/MeasureOfDispersion.php @@ -264,7 +264,7 @@ final class MeasureOfDispersion * * @return float * - * @throws ZeroDivisionException This exception is thrown if the size of the x array is less than 2 + * @throws ZeroDivisionException This exception is thrown if the size of the x array is less than 2 * * @since 1.0.0 */ diff --git a/Math/Topology/Kernel2D.php b/Math/Topology/Kernel2D.php index e790ff056..a7a2f3e89 100644 --- a/Math/Topology/Kernel2D.php +++ b/Math/Topology/Kernel2D.php @@ -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; } diff --git a/Math/Topology/MetricsND.php b/Math/Topology/MetricsND.php index 32e90bbe2..587cd8304 100755 --- a/Math/Topology/MetricsND.php +++ b/Math/Topology/MetricsND.php @@ -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]; } diff --git a/Utils/Formatter/HtmlFormatter.php b/Utils/Formatter/HtmlFormatter.php index 199fa91e0..f37eabdf1 100644 --- a/Utils/Formatter/HtmlFormatter.php +++ b/Utils/Formatter/HtmlFormatter.php @@ -40,7 +40,7 @@ class HtmlFormatter $dom->loadHTML($text); $dom->preserveWhiteSpace = false; - $dom->formatOutput = true; + $dom->formatOutput = true; return $dom->saveXML($dom->documentElement); } diff --git a/Utils/Parser/Markdown/Markdown.php b/Utils/Parser/Markdown/Markdown.php index 298013ec5..ac41d0cd0 100755 --- a/Utils/Parser/Markdown/Markdown.php +++ b/Utils/Parser/Markdown/Markdown.php @@ -61,12 +61,12 @@ class Markdown protected function buildFootnoteElement() { $Element = [ - 'name' => 'div', + 'name' => 'div', 'attributes' => ['class' => 'footnotes'], - 'elements' => [ + 'elements' => [ ['name' => 'hr'], [ - 'name' => 'ol', + 'name' => 'ol', 'elements' => [], ], ], @@ -76,7 +76,7 @@ class Markdown foreach ($this->DefinitionData['Footnote'] as $definitionId => $DefinitionData) { - if ( ! isset($DefinitionData['number'])) + if (! isset($DefinitionData['number'])) { continue; } @@ -93,28 +93,28 @@ class Markdown { $backLinkElements[] = ['text' => ' ']; $backLinkElements[] = [ - 'name' => 'a', + 'name' => 'a', 'attributes' => [ - 'href' => "#fnref$number:$definitionId", - 'rev' => 'footnote', + 'href' => "#fnref{$number}:{$definitionId}", + 'rev' => 'footnote', 'class' => 'footnote-backref', ], - 'rawHtml' => '↩', + 'rawHtml' => '↩', 'allowRawHtmlInSafeMode' => true, - 'autobreak' => false, + 'autobreak' => false, ]; } unset($backLinkElements[0]); - $n = \count($textElements) -1; + $n = \count($textElements) - 1; if ($textElements[$n]['name'] === 'p') { $backLinkElements = \array_merge( [ [ - 'rawHtml' => ' ', + 'rawHtml' => ' ', 'allowRawHtmlInSafeMode' => true, ], ], @@ -124,7 +124,7 @@ class Markdown unset($textElements[$n]['name']); $textElements[$n] = [ - 'name' => 'p', + 'name' => 'p', 'elements' => \array_merge( [$textElements[$n]], $backLinkElements @@ -134,15 +134,15 @@ class Markdown else { $textElements[] = [ - 'name' => 'p', - 'elements' => $backLinkElements + 'name' => 'p', + 'elements' => $backLinkElements, ]; } $Element['elements'][1]['elements'][] = [ - 'name' => 'li', + 'name' => 'li', 'attributes' => ['id' => 'fn:'.$definitionId], - 'elements' => \array_merge( + 'elements' => \array_merge( $textElements ), ]; @@ -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; @@ -283,7 +283,7 @@ class Markdown protected function linesElements(array $lines) { - $Elements = []; + $Elements = []; $CurrentBlock = null; foreach ($lines as $line) @@ -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)) { @@ -335,8 +335,8 @@ class Markdown { if ($this->isBlockCompletable($CurrentBlock['type'])) { - $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; - $CurrentBlock = $this->$methodName($CurrentBlock); + $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; + $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)) { @@ -417,8 +417,8 @@ class Markdown if (isset($CurrentBlock['continuable']) && $this->isBlockCompletable($CurrentBlock['type'])) { - $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; - $CurrentBlock = $this->$methodName($CurrentBlock); + $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; + $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'); } # @@ -476,7 +476,7 @@ class Markdown $Block = [ 'element' => [ - 'name' => 'pre', + 'name' => 'pre', 'element' => [ 'name' => 'code', 'text' => $text, @@ -524,16 +524,16 @@ class Markdown return; } - 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,16 +599,16 @@ 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 = [ - 'char' => $marker, + 'char' => $marker, 'openerLength' => $openerLength, - 'element' => [ - 'name' => 'pre', + 'element' => [ + 'name' => 'pre', 'element' => $Element, ], ]; @@ -672,8 +672,8 @@ class Markdown if (\preg_match('/^\[\^(.+?)\]:[ ]?(.*)$/', $Line['text'], $matches)) { $Block = [ - 'label' => $matches[1], - 'text' => $matches[2], + 'label' => $matches[1], + 'text' => $matches[2], 'hidden' => true, ]; @@ -708,8 +708,8 @@ class Markdown protected function blockFootnoteComplete($Block) { $this->DefinitionData['Footnote'][$Block['label']] = [ - 'text' => $Block['text'], - 'count' => null, + 'text' => $Block['text'], + 'count' => null, 'number' => null, ]; @@ -721,13 +721,13 @@ class Markdown protected function blockDefinitionList($Line, $Block) { - if ( ! isset($Block) || $Block['type'] !== 'Paragraph') + if (! isset($Block) || $Block['type'] !== 'Paragraph') { return; } $Element = [ - 'name' => 'dl', + 'name' => 'dl', 'elements' => [], ]; @@ -736,11 +736,11 @@ class Markdown foreach ($terms as $term) { $Element['elements'] []= [ - 'name' => 'dt', + 'name' => 'dt', 'handler' => [ - 'function' => 'lineElements', - 'argument' => $term, - 'destination' => 'elements' + 'function' => 'lineElements', + 'argument' => $term, + '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; @@ -793,11 +793,11 @@ class Markdown unset($Block['dd']); $Block['dd'] = [ - 'name' => 'dd', + 'name' => 'dd', 'handler' => [ - 'function' => 'lineElements', - 'argument' => $text, - 'destination' => 'elements' + 'function' => 'lineElements', + 'argument' => $text, + 'destination' => 'elements', ], ]; @@ -836,16 +836,16 @@ class Markdown $Block = [ 'element' => [ - 'name' => 'h' . $level, + 'name' => 'h' . $level, 'handler' => [ - 'function' => 'lineElements', - 'argument' => $text, + '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]; } @@ -882,15 +882,15 @@ class Markdown $markerWithoutWhitespace = \strstr($matches[1], ' ', true); $Block = [ - 'indent' => $Line['indent'], + 'indent' => $Line['indent'], 'pattern' => $pattern, - 'data' => [ - 'type' => $name, - 'marker' => $matches[1], + 'data' => [ + 'type' => $name, + 'marker' => $matches[1], 'markerType' => ($name === 'ul' ? $markerWithoutWhitespace : \substr($markerWithoutWhitespace, -1)), ], 'element' => [ - 'name' => $name, + 'name' => $name, 'elements' => [], ], ]; @@ -915,12 +915,12 @@ class Markdown } $Block['li'] = [ - 'name' => 'li', + 'name' => 'li', 'handler' => [ - 'function' => 'li', - 'argument' => !empty($matches[3]) ? [$matches[3]] : [], - 'destination' => 'elements' - ] + 'function' => 'li', + 'argument' => !empty($matches[3]) ? [$matches[3]] : [], + 'destination' => 'elements', + ], ]; $Block['element']['elements'] []= & $Block['li']; @@ -965,12 +965,12 @@ class Markdown $Block['indent'] = $Line['indent']; $Block['li'] = [ - 'name' => 'li', + 'name' => 'li', 'handler' => [ - 'function' => 'li', - 'argument' => [$text], - 'destination' => 'elements' - ] + 'function' => 'li', + 'argument' => [$text], + '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'] []= ''; } @@ -1040,12 +1040,12 @@ class Markdown { $Block = [ 'element' => [ - 'name' => 'blockquote', + 'name' => 'blockquote', 'handler' => [ - 'function' => 'linesElements', - 'argument' => (array) $matches[1], + '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,30 +1127,30 @@ 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; # ยป & } $Element = [ - 'name' => 'sup', + 'name' => 'sup', 'attributes' => ['id' => 'fnref'.$this->DefinitionData['Footnote'][$name]['count'].':'.$name], - 'element' => [ - 'name' => 'a', + 'element' => [ + 'name' => 'a', 'attributes' => ['href' => '#fn:'.$name, 'class' => 'footnote-ref'], - 'text' => $this->DefinitionData['Footnote'][$name]['number'], + 'text' => $this->DefinitionData['Footnote'][$name]['number'], ], ]; return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => $Element, ]; } @@ -1178,23 +1178,23 @@ class Markdown } $Block = [ - 'name' => $matches[1], - 'depth' => 0, + 'name' => $matches[1], + 'depth' => 0, 'element' => [ - 'rawHtml' => $Line['text'], + 'rawHtml' => $Line['text'], 'autobreak' => true, ], ]; - $length = \strlen($matches[0]); + $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)) { $Block['closed'] = true; - $Block['void'] = true; + $Block['void'] = true; } } else @@ -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,13 +1317,13 @@ class Markdown protected function blockReference($Line) { - if (strpos($Line['text'], ']') !== false + if (\strpos($Line['text'], ']') !== false && \preg_match('/^\[(.+?)\]:[ ]*+?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $Line['text'], $matches) ) { $id = \strtolower($matches[1]); $Data = [ - 'url' => UriFactory::build($matches[2]), + 'url' => UriFactory::build($matches[2]), 'title' => isset($matches[3]) ? $matches[3] : null, ]; @@ -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; } @@ -1415,12 +1415,12 @@ class Markdown $headerCell = \trim($headerCell); $HeaderElement = [ - 'name' => 'th', + 'name' => 'th', 'handler' => [ - 'function' => 'lineElements', - 'argument' => $headerCell, + '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};", ]; } @@ -1440,8 +1440,8 @@ class Markdown $Block = [ 'alignments' => $alignments, 'identified' => true, - 'element' => [ - 'name' => 'table', + 'element' => [ + 'name' => 'table', 'elements' => [], ], ]; @@ -1451,12 +1451,12 @@ class Markdown ]; $Block['element']['elements'] []= [ - 'name' => 'tbody', + 'name' => 'tbody', 'elements' => [], ]; $Block['element']['elements'][0]['elements'] []= [ - 'name' => 'tr', + 'name' => 'tr', 'elements' => $HeaderElements, ]; @@ -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,21 +1479,21 @@ 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) { $cell = \trim($cell); $Element = [ - 'name' => 'td', + 'name' => 'td', 'handler' => [ - 'function' => 'lineElements', - 'argument' => $cell, + 'function' => 'lineElements', + 'argument' => $cell, 'destination' => 'elements', - ] + ], ]; if (isset($Block['alignments'][$index])) @@ -1507,7 +1507,7 @@ class Markdown } $Element = [ - 'name' => 'tr', + 'name' => 'tr', 'elements' => $Elements, ]; @@ -1524,12 +1524,12 @@ class Markdown protected function paragraph($Line) { return [ - 'type' => 'Paragraph', + 'type' => 'Paragraph', 'element' => [ - 'name' => 'p', + 'name' => 'p', 'handler' => [ - 'function' => 'lineElements', - 'argument' => $Line['text'], + 'function' => 'lineElements', + 'argument' => $Line['text'], 'destination' => 'elements', ], ], @@ -1553,15 +1553,15 @@ class Markdown # protected $InlineTypes = [ - '!' => ['Image'], - '&' => ['SpecialCharacter'], - '*' => ['Emphasis'], - ':' => ['Url'], - '<' => ['UrlTag', 'EmailTag', 'Markup'], - '[' => ['FootnoteMarker', 'Link'], - '_' => ['Emphasis'], - '`' => ['Code'], - '~' => ['Strikethrough'], + '!' => ['Image'], + '&' => ['SpecialCharacter'], + '*' => ['Emphasis'], + ':' => ['Url'], + '<' => ['UrlTag', 'EmailTag', 'Markup'], + '[' => ['FootnoteMarker', 'Link'], + '_' => ['Emphasis'], + '`' => ['Code'], + '~' => ['Strikethrough'], '\\' => ['EscapeSequence'], ]; @@ -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; } @@ -1685,7 +1684,7 @@ class Markdown protected function inlineText($text) { $Inline = [ - 'extent' => \strlen($text), + 'extent' => \strlen($text), 'element' => [], ]; @@ -1703,7 +1702,7 @@ class Markdown foreach ($this->DefinitionData['Abbreviation'] as $abbreviation => $meaning) { $this->currentAbreviation = $abbreviation; - $this->currentMeaning = $meaning; + $this->currentMeaning = $meaning; $Inline['element'] = $this->elementApplyRecursiveDepthFirst( [$this, 'insertAbreviation'], @@ -1725,7 +1724,7 @@ class Markdown $text = \preg_replace('/[ ]*+\n/', ' ', $text); return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ 'name' => 'code', 'text' => $text, @@ -1741,21 +1740,21 @@ 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 [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ - 'name' => 'a', - 'text' => $matches[1], + 'name' => 'a', + 'text' => $matches[1], 'attributes' => [ 'href' => UriFactory::build($url), ], @@ -1766,7 +1765,7 @@ class Markdown protected function inlineEmphasis($Excerpt) { - if ( ! isset($Excerpt['text'][1])) + if (! isset($Excerpt['text'][1])) { return; } @@ -1787,14 +1786,14 @@ class Markdown } return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ - 'name' => $emphasis, + 'name' => $emphasis, 'handler' => [ - 'function' => 'lineElements', - 'argument' => $matches[1], + 'function' => 'lineElements', + 'argument' => $matches[1], 'destination' => 'elements', - ] + ], ], ]; } @@ -1805,14 +1804,14 @@ class Markdown { return [ 'element' => ['rawHtml' => $Excerpt['text'][1]], - 'extent' => 2, + 'extent' => 2, ]; } } protected function inlineImage($Excerpt) { - if ( ! isset($Excerpt['text'][1]) || $Excerpt['text'][1] !== '[') + if (! isset($Excerpt['text'][1]) || $Excerpt['text'][1] !== '[') { return; } @@ -1827,9 +1826,9 @@ class Markdown } $Inline = [ - 'extent' => $Link['extent'] + 1, + 'extent' => $Link['extent'] + 1, 'element' => [ - 'name' => 'img', + 'name' => 'img', 'attributes' => [ 'src' => $Link['element']['attributes']['href'], 'alt' => $Link['element']['handler']['argument'], @@ -1848,15 +1847,15 @@ class Markdown protected function inlineLink($Excerpt) { $Element = [ - 'name' => 'a', + 'name' => 'a', 'handler' => [ - 'function' => 'lineElements', - 'argument' => null, + 'function' => 'lineElements', + 'argument' => null, 'destination' => 'elements', ], 'nonNestables' => ['Url', 'Link'], - 'attributes' => [ - 'href' => null, + 'attributes' => [ + 'href' => null, 'title' => null, ], ]; @@ -1903,19 +1902,19 @@ class Markdown $definition = \strtolower($Element['handler']['argument']); } - if ( ! isset($this->DefinitionData['Reference'][$definition])) + if (! isset($this->DefinitionData['Reference'][$definition])) { return; } $Definition = $this->DefinitionData['Reference'][$definition]; - $Element['attributes']['href'] = $Definition['url']; + $Element['attributes']['href'] = $Definition['url']; $Element['attributes']['title'] = $Definition['title']; } $Link = [ - 'extent' => $extent, + 'extent' => $extent, 'element' => $Element, ]; @@ -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) @@ -1968,12 +1968,12 @@ class Markdown '/\b'.\preg_quote($this->currentAbreviation, '/').'\b/', [ [ - 'name' => 'abbr', + 'name' => 'abbr', 'attributes' => [ 'title' => $this->currentMeaning, ], 'text' => $this->currentAbreviation, - ] + ], ], $Element['text'] ); @@ -1995,7 +1995,7 @@ class Markdown { return [ 'element' => ['rawHtml' => $matches[0]], - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), ]; } @@ -2003,7 +2003,7 @@ class Markdown { return [ 'element' => ['rawHtml' => $matches[0]], - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), ]; } @@ -2011,7 +2011,7 @@ class Markdown { return [ 'element' => ['rawHtml' => $matches[0]], - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), ]; } } @@ -2023,16 +2023,14 @@ class Markdown ) { return [ 'element' => ['rawHtml' => '&' . $matches[1] . ';'], - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), ]; } - - return; } protected function inlineStrikethrough($Excerpt) { - if ( ! isset($Excerpt['text'][1])) + if (! isset($Excerpt['text'][1])) { return; } @@ -2040,14 +2038,14 @@ class Markdown if ($Excerpt['text'][1] === '~' && \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches)) { return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ - 'name' => 'del', + 'name' => 'del', 'handler' => [ - 'function' => 'lineElements', - 'argument' => $matches[1], + 'function' => 'lineElements', + 'argument' => $matches[1], 'destination' => 'elements', - ] + ], ], ]; } @@ -2060,17 +2058,17 @@ 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]; $Inline = [ - 'extent' => \strlen($matches[0][0]), + 'extent' => \strlen($matches[0][0]), 'position' => $matches[0][1], - 'element' => [ - 'name' => 'a', - 'text' => $url, + 'element' => [ + 'name' => 'a', + 'text' => $url, 'attributes' => [ 'href' => UriFactory::build($url), ], @@ -2083,15 +2081,15 @@ 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]; return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ - 'name' => 'a', - 'text' => $url, + 'name' => 'a', + 'text' => $url, 'attributes' => [ 'href' => UriFactory::build($url), ], @@ -2121,7 +2119,7 @@ class Markdown $Element['nonNestables'] = []; } - if (is_string($Element['handler'])) + if (\is_string($Element['handler'])) { $function = $Element['handler']; $argument = $Element['text']; @@ -2130,8 +2128,8 @@ class Markdown } else { - $function = $Element['handler']['function']; - $argument = $Element['handler']['argument']; + $function = $Element['handler']['function']; + $argument = $Element['handler']['argument']; $destination = $Element['handler']['destination']; } @@ -2237,7 +2235,7 @@ class Markdown continue; } - $markup .= " $name=\"".self::escape($value).'"'; + $markup .= " {$name}=\"".self::escape($value).'"'; } } } @@ -2255,7 +2253,7 @@ class Markdown $text = $Element['rawHtml']; $allowRawHtmlInSafeMode = isset($Element['allowRawHtmlInSafeMode']) && $Element['allowRawHtmlInSafeMode']; - $permitRawHtml = !$this->safeMode || $allowRawHtmlInSafeMode; + $permitRawHtml = !$this->safeMode || $allowRawHtmlInSafeMode; } $hasContent = isset($text) || isset($Element['element']) || isset($Element['elements']); @@ -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,11 +2348,11 @@ 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); - $after = \substr($text, $offset + \strlen($matches[0][0])); + $after = \substr($text, $offset + \strlen($matches[0][0])); $newElements[] = ['text' => $before]; @@ -2386,13 +2384,13 @@ class Markdown protected function sanitiseElement(array $Element) { - static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/'; + static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/'; static $safeUrlNameToAtt = [ 'a' => 'href', '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', ]; - } diff --git a/tests/Account/PermissionAbstractTest.php b/tests/Account/PermissionAbstractTest.php index b1d272fa3..253560003 100755 --- a/tests/Account/PermissionAbstractTest.php +++ b/tests/Account/PermissionAbstractTest.php @@ -84,13 +84,13 @@ final class PermissionAbstractTest extends \PHPUnit\Framework\TestCase */ public function testEqualPermissions() : void { - $perm1 = new class() extends PermissionAbstract {}; + $perm1 = new class() extends PermissionAbstract {}; $perm1->unit = 1; $perm1->setPermission(PermissionType::READ); self::assertTrue($perm1->isEqual($perm1)); - $perm2 = new class() extends PermissionAbstract {}; + $perm2 = new class() extends PermissionAbstract {}; $perm2->unit = 1; $perm2->setPermission(PermissionType::CREATE);