From ab3e8e09396dc9e30a31723be31165a6594be100 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 2 Apr 2024 21:40:48 +0000 Subject: [PATCH] template fixes + bug fixes + style fixes --- Algorithm/Rating/TrueSkill.php | 18 ------------------ .../BayesianPersonalizedRanking.php | 8 ++++---- DataStorage/Database/Mapper/ReadMapper.php | 13 +++++++++++++ Math/Matrix/Matrix.php | 4 ++-- Uri/UriFactory.php | 6 ++++++ Utils/Barcode/TwoDAbstract.php | 11 +++++++++++ Utils/ColorUtils.php | 6 +++--- Utils/Parser/Markdown/Markdown.php | 2 +- .../Database/DataMapperAbstractTest.php | 10 +++++----- tests/Module/ModuleAbstractTest.php | 6 +++--- tests/Stdlib/Base/AddressTest.php | 17 ++++++++--------- tests/Stdlib/Graph/NodeTest.php | 1 - tests/Utils/ArrayUtilsTest.php | 1 - tests/Utils/TaskSchedule/ScheduleTest.php | 1 - 14 files changed, 56 insertions(+), 48 deletions(-) diff --git a/Algorithm/Rating/TrueSkill.php b/Algorithm/Rating/TrueSkill.php index 592f895d0..396840e9f 100644 --- a/Algorithm/Rating/TrueSkill.php +++ b/Algorithm/Rating/TrueSkill.php @@ -226,37 +226,22 @@ class TrueSkill / (NormalDistribution::getCdf($epsilon - $tAbs, 0.0, 1.0) - NormalDistribution::getCdf(-$epsilon - $tAbs, 0.0, 1.0)); } - /** - * - */ private function buildRatingLayer() : void { } - /** - * - */ private function buildPerformanceLayer() : void { } - /** - * - */ private function buildTeamPerformanceLayer() : void { } - /** - * - */ private function buildTruncLayer() : void { } - /** - * - */ private function factorGraphBuilders() { // Rating layer @@ -275,9 +260,6 @@ class TrueSkill ]; } - /** - * - */ public function rating() : void { // Start values diff --git a/Business/Recommendation/BayesianPersonalizedRanking.php b/Business/Recommendation/BayesianPersonalizedRanking.php index 83842dc50..95c40af1d 100644 --- a/Business/Recommendation/BayesianPersonalizedRanking.php +++ b/Business/Recommendation/BayesianPersonalizedRanking.php @@ -40,12 +40,12 @@ final class BayesianPersonalizedRanking /** * Constructor. * - * @param int $numFactors Determines the dimensionality of the latent factor space. - * @param float $learningRate Controls the step size for updating the latent factors during optimization. - * @param float $regularization Prevents over-fitting by adding a penalty for large parameter values. + * @param int $numFactors determines the dimensionality of the latent factor space + * @param float $learningRate controls the step size for updating the latent factors during optimization + * @param float $regularization prevents over-fitting by adding a penalty for large parameter values * * @since 1.0.0 - */ + */ public function __construct(int $numFactors, float $learningRate, float $regularization) { $this->numFactors = $numFactors; diff --git a/DataStorage/Database/Mapper/ReadMapper.php b/DataStorage/Database/Mapper/ReadMapper.php index 5a742cd93..7fde06e06 100755 --- a/DataStorage/Database/Mapper/ReadMapper.php +++ b/DataStorage/Database/Mapper/ReadMapper.php @@ -1336,4 +1336,17 @@ final class ReadMapper extends DataMapperAbstract } } } + + public function paginate(string $member, string $ptype, mixed $offset) : self + { + if ($ptype === 'p') { + $this->where($member, $offset ?? 0, '<'); + } elseif ($ptype === 'n') { + $this->where($member, $offset ?? 0, '>'); + } else { + $this->where($member, 0, '>'); + } + + return $this; + } } diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index 494512c83..122a2171b 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -852,8 +852,8 @@ class Matrix implements \ArrayAccess, \Iterator } $eig = new EigenvalueDecomposition($this); - $v = $eig->getV(); - $d = $eig->getD(); + $v = $eig->getV(); + $d = $eig->getD(); $vInv = $v->inverse(); diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 5c777e8be..dbeeeb232 100755 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -228,6 +228,12 @@ final class UriFactory ); */ + // @feature Implement whitelisting/blacklisting for {?} + // Currently it copies all parameters + // Ideally you could use + // {?+para1,para2} for whitelisting + // {?-para1,para2} for blacklisting + if (\stripos($url, '?') === false && ($pos = \stripos($url, '&')) !== false) { $url = \substr_replace($url, '?', $pos, 1); } diff --git a/Utils/Barcode/TwoDAbstract.php b/Utils/Barcode/TwoDAbstract.php index e826aefc6..d80e5ab24 100755 --- a/Utils/Barcode/TwoDAbstract.php +++ b/Utils/Barcode/TwoDAbstract.php @@ -57,6 +57,10 @@ abstract class TwoDAbstract extends CodeAbstract */ protected function createImage(array $codeArray) : mixed { + if (empty($codeArray)) { + return null; + } + $dimensions = $this->calculateDimensions($codeArray); $image = \imagecreate($dimensions['width'], $dimensions['height']); @@ -115,6 +119,13 @@ abstract class TwoDAbstract extends CodeAbstract */ private function calculateDimensions(array $codeArray) : array { + if (empty($codeArray)) { + return [ + 'width' => 0, + 'height' => 0, + ]; + } + $matrixDimension = \max(\count($codeArray), \count(\reset($codeArray))); $imageDimension = \max($this->dimension['width'], $this->dimension['width']); diff --git a/Utils/ColorUtils.php b/Utils/ColorUtils.php index 38f4c3254..582087e79 100755 --- a/Utils/ColorUtils.php +++ b/Utils/ColorUtils.php @@ -110,9 +110,9 @@ final class ColorUtils public static function approximateColorDistance(array $rgb1, array $rgb2) : float { $rMean = (int) (($rgb1['r'] + $rgb2['r']) / 2); - $r = ($rgb2['r'] - $rgb1['r']); - $g = ($rgb2['g'] - $rgb1['g']); - $b = ($rgb2['b'] - $rgb1['b']); + $r = ($rgb2['r'] - $rgb1['r']); + $g = ($rgb2['g'] - $rgb1['g']); + $b = ($rgb2['b'] - $rgb1['b']); return \sqrt( (((512 + $rMean) * $r * $r) >> 8) diff --git a/Utils/Parser/Markdown/Markdown.php b/Utils/Parser/Markdown/Markdown.php index ac84d96d2..c1b191fa0 100755 --- a/Utils/Parser/Markdown/Markdown.php +++ b/Utils/Parser/Markdown/Markdown.php @@ -4576,7 +4576,7 @@ class Markdown } $permitRawHtml = false; - $text = null; + $text = null; if (isset($element['text'])) { $text = $element['text']; diff --git a/tests/DataStorage/Database/DataMapperAbstractTest.php b/tests/DataStorage/Database/DataMapperAbstractTest.php index 7a60d9f05..9dddefc75 100755 --- a/tests/DataStorage/Database/DataMapperAbstractTest.php +++ b/tests/DataStorage/Database/DataMapperAbstractTest.php @@ -288,7 +288,7 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase public function testGetAll() : void { BaseModelMapper::create()->execute($this->model); - self::assertCount(1, BaseModelMapper::getAll()->execute()); + self::assertCount(1, BaseModelMapper::getAll()->executeGetArray()); } public function testGetYield() : void @@ -303,7 +303,7 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase public function testGetFor() : void { $id = BaseModelMapper::create()->execute($this->model); - $for = ManyToManyDirectModelMapper::getAll()->where('to', $id)->execute(); + $for = ManyToManyDirectModelMapper::getAll()->where('to', $id)->executeGetArray(); self::assertEquals( \reset($this->model->hasManyDirect)->string, @@ -337,7 +337,7 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase $model2->datetime = new \DateTime('now'); $id2 = BaseModelMapper::create()->execute($model2); - $newest = BaseModelMapper::getAll()->sort('id', OrderType::DESC)->limit(1)->execute(); + $newest = BaseModelMapper::getAll()->sort('id', OrderType::DESC)->limit(1)->executeGetArray(); self::assertEquals($id2, \reset($newest)->id); } @@ -393,7 +393,7 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase BaseModelMapper::create()->execute($model2); BaseModelMapper::create()->execute($model3); - $found = BaseModelMapper::getAll()->where('string', '%sir%' , 'LIKE')->execute(); + $found = BaseModelMapper::getAll()->where('string', '%sir%' , 'LIKE')->executeGetArray(); self::assertCount(2, $found); self::assertEquals($model2->string, \reset($found)->string); self::assertEquals($model3->string, \end($found)->string); @@ -455,7 +455,7 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase $cond3->base = $id2; ConditionalMapper::create()->execute($cond3); - $found = BaseModelMapper::getAll()->with('conditional')->where('conditional/language', 'de')->execute(); + $found = BaseModelMapper::getAll()->with('conditional')->where('conditional/language', 'de')->executeGetArray(); self::assertCount(2, $found); self::assertEquals($model1->string, \reset($found)->string); self::assertEquals($model2->string, \end($found)->string); diff --git a/tests/Module/ModuleAbstractTest.php b/tests/Module/ModuleAbstractTest.php index 0098f95e7..a23848002 100755 --- a/tests/Module/ModuleAbstractTest.php +++ b/tests/Module/ModuleAbstractTest.php @@ -407,7 +407,7 @@ final class ModuleAbstractTest extends \PHPUnit\Framework\TestCase $this->dbSetup(); $this->module->create(); - self::assertCount(1, BaseModelMapper::getAll()->execute()); + self::assertCount(1, BaseModelMapper::getAll()->executeGetArray()); $this->dbTeardown(); } @@ -419,7 +419,7 @@ final class ModuleAbstractTest extends \PHPUnit\Framework\TestCase $this->dbSetup(); $this->module->createMultiple(); - self::assertCount(2, BaseModelMapper::getAll()->execute()); + self::assertCount(2, BaseModelMapper::getAll()->executeGetArray()); $this->dbTeardown(); } @@ -447,7 +447,7 @@ final class ModuleAbstractTest extends \PHPUnit\Framework\TestCase $this->module->create(); self::assertCount(1, BaseModelMapper::getAll()->execute()); $this->module->delete(); - self::assertCount(0, BaseModelMapper::getAll()->execute()); + self::assertCount(0, BaseModelMapper::getAll()->executeGetArray()); $this->dbTeardown(); } diff --git a/tests/Stdlib/Base/AddressTest.php b/tests/Stdlib/Base/AddressTest.php index c8cb8a6be..bd5dc5696 100755 --- a/tests/Stdlib/Base/AddressTest.php +++ b/tests/Stdlib/Base/AddressTest.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace phpOMS\tests\Stdlib\Base; use phpOMS\Stdlib\Base\Address; -use phpOMS\Stdlib\Base\Location; /** * @internal @@ -39,8 +38,8 @@ final class AddressTest extends \PHPUnit\Framework\TestCase public function testDefault() : void { $expected = [ - 'fao' => '', - 'name' => '', + 'fao' => '', + 'name' => '', 'postal' => '', 'city' => '', 'country' => 'XX', @@ -69,8 +68,8 @@ final class AddressTest extends \PHPUnit\Framework\TestCase public function testArray() : void { $expected = [ - 'fao' => 'fao', - 'name' => '', + 'fao' => 'fao', + 'name' => '', 'postal' => '', 'city' => '', 'country' => 'XX', @@ -80,7 +79,7 @@ final class AddressTest extends \PHPUnit\Framework\TestCase 'lon' => 0.0, ]; - $this->address->fao = 'fao'; + $this->address->fao = 'fao'; self::assertEquals($expected, $this->address->toArray()); } @@ -90,8 +89,8 @@ final class AddressTest extends \PHPUnit\Framework\TestCase public function testJsonSerialize() : void { $expected = [ - 'fao' => 'fao', - 'name' => '', + 'fao' => 'fao', + 'name' => '', 'postal' => '', 'city' => '', 'country' => 'XX', @@ -101,7 +100,7 @@ final class AddressTest extends \PHPUnit\Framework\TestCase 'lon' => 0.0, ]; - $this->address->fao = 'fao'; + $this->address->fao = 'fao'; self::assertEquals($expected, $this->address->jsonSerialize()); } diff --git a/tests/Stdlib/Graph/NodeTest.php b/tests/Stdlib/Graph/NodeTest.php index 5e7c11e06..0162d2801 100755 --- a/tests/Stdlib/Graph/NodeTest.php +++ b/tests/Stdlib/Graph/NodeTest.php @@ -115,7 +115,6 @@ final class NodeTest extends \PHPUnit\Framework\TestCase } /** - * * @bug Directed graphs may return invalid neighbors * https://github.com/Karaka-Management/phpOMS/issues/366 */ diff --git a/tests/Utils/ArrayUtilsTest.php b/tests/Utils/ArrayUtilsTest.php index 7cc044830..eb7338f99 100755 --- a/tests/Utils/ArrayUtilsTest.php +++ b/tests/Utils/ArrayUtilsTest.php @@ -234,7 +234,6 @@ final class ArrayUtilsTest extends \PHPUnit\Framework\TestCase self::assertNull(ArrayUtils::getArg('--testNull', $_SERVER['argv'] ?? [])); } - #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('All array values in an array can be potentiated by a numeric value')] public function test() : void diff --git a/tests/Utils/TaskSchedule/ScheduleTest.php b/tests/Utils/TaskSchedule/ScheduleTest.php index 7099e2897..3712960ef 100755 --- a/tests/Utils/TaskSchedule/ScheduleTest.php +++ b/tests/Utils/TaskSchedule/ScheduleTest.php @@ -32,7 +32,6 @@ final class ScheduleTest extends \PHPUnit\Framework\TestCase self::assertInstanceOf('\phpOMS\Utils\TaskSchedule\TaskAbstract', $job); } - #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('A task can be created from an array and rendered')] public function testCreateJobWithData() : void