diff --git a/Algorithm/Knapsack/Continuous.php b/Algorithm/Knapsack/Continuous.php index cf6a5adf7..cd804914c 100644 --- a/Algorithm/Knapsack/Continuous.php +++ b/Algorithm/Knapsack/Continuous.php @@ -35,6 +35,21 @@ final class Continuous { } + /** + * Comparing items + * + * @param Item[] $a Item + * @param Item[] $b Item + * + * @return int + * + * @since 1.0.0 + */ + private static function continuousComparator(array $a, array $b) : int + { + return $b['item']->getValue() / $b['item']->getCost() <=> $a['item']->getValue() / $a['item']->getCost(); + } + /** * Fill the backpack with items * @@ -47,9 +62,7 @@ final class Continuous */ public static function solve(array $items, BackpackInterface $backpack) : BackpackInterface { - \usort($items, function($a, $b) { - return $a['item']->getValue() / $a['item']->getCost() < $b['item']->getValue() / $b['item']->getCost(); - }); + \usort($items, ['self', 'continuousComparator']); $availableSpace = $backpack->getMaxCost(); diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 9203fac40..fb6891159 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -363,11 +363,13 @@ class DataMapperAbstract implements DataMapperInterface public static function clear() : void { // clear parent and objects - if (static::class === self::$parentMapper) { - self::$parentMapper = null; - self::$conditionals = []; - self::$relations = RelationType::ALL; + if (static::class !== self::$parentMapper) { + return; } + + self::$parentMapper = null; + self::$conditionals = []; + self::$relations = RelationType::ALL; } /**