Skip to content

Commit

Permalink
template fixes + bug fixes + style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Eichhorn committed Apr 2, 2024
1 parent 61f44bc commit ab3e8e0
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 48 deletions.
18 changes: 0 additions & 18 deletions Algorithm/Rating/TrueSkill.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,37 +226,22 @@ private function wDraw(float $t, float $epsilon) : float
/ (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
Expand All @@ -275,9 +260,6 @@ private function factorGraphBuilders()
];
}

/**
*
*/
public function rating() : void
{
// Start values
Expand Down
8 changes: 4 additions & 4 deletions Business/Recommendation/BayesianPersonalizedRanking.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions DataStorage/Database/Mapper/ReadMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1336,4 +1336,17 @@ public function hasManyRelations(object $obj) : bool
}
}
}

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;
}
}
4 changes: 2 additions & 2 deletions Math/Matrix/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,8 @@ public function exp() : self
}

$eig = new EigenvalueDecomposition($this);
$v = $eig->getV();
$d = $eig->getD();
$v = $eig->getV();
$d = $eig->getD();

$vInv = $v->inverse();

Expand Down
6 changes: 6 additions & 0 deletions Uri/UriFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ private static function unique(string $url) : string
);
*/

// @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);
}
Expand Down
11 changes: 11 additions & 0 deletions Utils/Barcode/TwoDAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ abstract public function generateCodeArray() : array;
*/
protected function createImage(array $codeArray) : mixed
{
if (empty($codeArray)) {
return null;
}

$dimensions = $this->calculateDimensions($codeArray);
$image = \imagecreate($dimensions['width'], $dimensions['height']);

Expand Down Expand Up @@ -115,6 +119,13 @@ protected function createImage(array $codeArray) : mixed
*/
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']);

Expand Down
6 changes: 3 additions & 3 deletions Utils/ColorUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public static function colorDistance(array $rgb1, array $rgb2) : float
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)
Expand Down
2 changes: 1 addition & 1 deletion Utils/Parser/Markdown/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -4576,7 +4576,7 @@ protected function element(array $element) : string
}

$permitRawHtml = false;
$text = null;
$text = null;

if (isset($element['text'])) {
$text = $element['text'];
Expand Down
10 changes: 5 additions & 5 deletions tests/DataStorage/Database/DataMapperAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function testGetRaw() : void
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
Expand All @@ -303,7 +303,7 @@ public function testGetYield() : void
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,
Expand Down Expand Up @@ -337,7 +337,7 @@ public function testGetNewest() : void
$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);
}

Expand Down Expand Up @@ -393,7 +393,7 @@ public function testFind() : void
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);
Expand Down Expand Up @@ -455,7 +455,7 @@ public function testWithConditional() : void
$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);
Expand Down
6 changes: 3 additions & 3 deletions tests/Module/ModuleAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public function testModelCreate() : void
$this->dbSetup();

$this->module->create();
self::assertCount(1, BaseModelMapper::getAll()->execute());
self::assertCount(1, BaseModelMapper::getAll()->executeGetArray());

$this->dbTeardown();
}
Expand All @@ -419,7 +419,7 @@ public function testModelsCreate() : void
$this->dbSetup();

$this->module->createMultiple();
self::assertCount(2, BaseModelMapper::getAll()->execute());
self::assertCount(2, BaseModelMapper::getAll()->executeGetArray());

$this->dbTeardown();
}
Expand Down Expand Up @@ -447,7 +447,7 @@ public function testModelDelete() : void
$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();
}
Expand Down
17 changes: 8 additions & 9 deletions tests/Stdlib/Base/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace phpOMS\tests\Stdlib\Base;

use phpOMS\Stdlib\Base\Address;
use phpOMS\Stdlib\Base\Location;

/**
* @internal
Expand All @@ -39,8 +38,8 @@ protected function setUp() : void
public function testDefault() : void
{
$expected = [
'fao' => '',
'name' => '',
'fao' => '',
'name' => '',
'postal' => '',
'city' => '',
'country' => 'XX',
Expand Down Expand Up @@ -69,8 +68,8 @@ public function testFAOInputOutput() : void
public function testArray() : void
{
$expected = [
'fao' => 'fao',
'name' => '',
'fao' => 'fao',
'name' => '',
'postal' => '',
'city' => '',
'country' => 'XX',
Expand All @@ -80,7 +79,7 @@ public function testArray() : void
'lon' => 0.0,
];

$this->address->fao = 'fao';
$this->address->fao = 'fao';

self::assertEquals($expected, $this->address->toArray());
}
Expand All @@ -90,8 +89,8 @@ public function testArray() : void
public function testJsonSerialize() : void
{
$expected = [
'fao' => 'fao',
'name' => '',
'fao' => 'fao',
'name' => '',
'postal' => '',
'city' => '',
'country' => 'XX',
Expand All @@ -101,7 +100,7 @@ public function testJsonSerialize() : void
'lon' => 0.0,
];

$this->address->fao = 'fao';
$this->address->fao = 'fao';

self::assertEquals($expected, $this->address->jsonSerialize());
}
Expand Down
1 change: 0 additions & 1 deletion tests/Stdlib/Graph/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public function testNodeRelation() : void
}

/**
*
* @bug Directed graphs may return invalid neighbors
* https://github.com/Karaka-Management/phpOMS/issues/366
*/
Expand Down
1 change: 0 additions & 1 deletion tests/Utils/ArrayUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ public function testInvalidArgGet() : void
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
Expand Down
1 change: 0 additions & 1 deletion tests/Utils/TaskSchedule/ScheduleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function testDefault() : void
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
Expand Down

0 comments on commit ab3e8e0

Please sign in to comment.