diff --git a/Algorithm/Clustering/AffinityPropagation.php b/Algorithm/Clustering/AffinityPropagation.php index a207374ce..3f0d5b897 100644 --- a/Algorithm/Clustering/AffinityPropagation.php +++ b/Algorithm/Clustering/AffinityPropagation.php @@ -49,12 +49,24 @@ final class AffinityPropagation implements ClusteringInterface private array $availabilityMatrix = []; + /** + * Original points used for clusters + * + * @var PointInterface[] + * @since 1.0.0 + */ private array $points = []; /** - * @param PointInterface[] $points + * Create similarity matrix from points + * + * @param PointInterface[] $points Points to create the similarity matrix for + * + * @return array> + * + * @since 1.0.0 */ - private function createSimilarityMatrix(array $points) + private function createSimilarityMatrix(array $points) : array { $n = \count($points); $coordinates = \count($points[0]->coordinates); @@ -63,7 +75,6 @@ final class AffinityPropagation implements ClusteringInterface $temp = []; for ($i = 0; $i < $n - 1; ++$i) { for ($j = $i + 1; $j < $n; ++$j) { - $sum = 0.0; for ($c = 0; $c < $coordinates; ++$c) { $sum += ($points[$i]->getCoordinate($c) - $points[$j]->getCoordinate($c)) * ($points[$i]->getCoordinate($c) - $points[$j]->getCoordinate($c)); @@ -71,7 +82,7 @@ final class AffinityPropagation implements ClusteringInterface $similarityMatrix[$i][$j] = -$sum; $similarityMatrix[$j][$i] = -$sum; - $temp[] = $similarityMatrix[$i][$j]; + $temp[] = $similarityMatrix[$i][$j]; } } @@ -89,14 +100,24 @@ final class AffinityPropagation implements ClusteringInterface return $similarityMatrix; } + /** + * Generate clusters for points + * + * @param PointInterface[] $points Points to cluster + * @param int $iterations Iterations for cluster generation + * + * @return void + * + * @since 1.0.0 + */ public function generateClusters(array $points, int $iterations = 100) : void { $this->points = $points; - $n = \count($points); + $n = \count($points); - $this->similarityMatrix = $this->createSimilarityMatrix($points); + $this->similarityMatrix = $this->createSimilarityMatrix($points); $this->responsibilityMatrix = clone $this->similarityMatrix; - $this->availabilityMatrix = clone $this->similarityMatrix; + $this->availabilityMatrix = clone $this->similarityMatrix; for ($c = 0; $c < $iterations; ++$c) { for ($i = 0; $i < $n; ++$i) { @@ -127,7 +148,7 @@ final class AffinityPropagation implements ClusteringInterface $sum += \max(0.0, $this->responsibilityMatrix[$j][$k]); } - for ($j = $j + 1; $j < $n; ++$j) { + for ($j += 1; $j < $n; ++$j) { $sum += \max(0.0, $this->responsibilityMatrix[$j][$k]); } @@ -164,15 +185,25 @@ final class AffinityPropagation implements ClusteringInterface } } - private function findNearestGroup(array $similarityMatrix, int $point, int $clusterCount) : int + /** + * Find the nearest group for a point + * + * @param array $similarityMatrix Similarity matrix + * @param int $point Point id in the similarity matrix to compare + * + * @return int + * + * @since 1.0.0 + */ + private function findNearestGroup(array $similarityMatrix, int $point) : int { $maxSim = \PHP_INT_MIN; - $group = 0; + $group = 0; foreach ($this->clusterCenters as $c => $_) { if ($similarityMatrix[$point][$c] > $maxSim) { $maxSim = $similarityMatrix[$point][$c]; - $group = $c; + $group = $c; } } @@ -192,7 +223,6 @@ final class AffinityPropagation implements ClusteringInterface $c = $this->findNearestGroup( $similarityMatrix, \count($points) - 1, - \count($this->clusterCenters) ); return $this->clusterCenters[$c]; @@ -207,10 +237,9 @@ final class AffinityPropagation implements ClusteringInterface return $this->clusters; } - $clusterCount = \count($this->clusterCenters); $n = \count($this->points); for ($i = 0; $i < $n; ++$i) { - $group = $this->findNearestGroup($this->points, $i, $clusterCount); + $group = $this->findNearestGroup($this->points, $i); $this->clusters[$group] = $this->points[$i]; } diff --git a/Algorithm/Clustering/AgglomerativeClustering.php b/Algorithm/Clustering/AgglomerativeClustering.php index 46d604c55..428be189d 100644 --- a/Algorithm/Clustering/AgglomerativeClustering.php +++ b/Algorithm/Clustering/AgglomerativeClustering.php @@ -69,13 +69,12 @@ final class AgglomerativeClustering implements ClusteringInterface }; $this->linkage = $linkage ?? function (array $a, array $b, array $distances) { - return AgglomerativeClustering::averageDistanceLinkage($a, $b, $distances); + return self::averageDistanceLinkage($a, $b, $distances); }; } /** * Maximum/Complete-Linkage clustering - * */ public static function maximumDistanceLinkage(array $setA, array $setB, array $distances) : float { @@ -93,7 +92,6 @@ final class AgglomerativeClustering implements ClusteringInterface /** * Minimum/Single-Linkage clustering - * */ public static function minimumDistanceLinkage(array $setA, array $setB, array $distances) : float { @@ -111,7 +109,6 @@ final class AgglomerativeClustering implements ClusteringInterface /** * Unweighted average linkage clustering (UPGMA) - * */ public static function averageDistanceLinkage(array $setA, array $setB, array $distances) : float { @@ -122,6 +119,4 @@ final class AgglomerativeClustering implements ClusteringInterface return $distance / \count($setA) / \count($setB); } - - } diff --git a/Algorithm/Clustering/ClusteringInterface.php b/Algorithm/Clustering/ClusteringInterface.php index 0e8aab348..8da25fb94 100644 --- a/Algorithm/Clustering/ClusteringInterface.php +++ b/Algorithm/Clustering/ClusteringInterface.php @@ -68,4 +68,4 @@ interface ClusteringInterface // Not possible to interface due to different implementations // public function generateClusters(...) : void -} \ No newline at end of file +} diff --git a/Algorithm/Clustering/DivisiveClustering.php b/Algorithm/Clustering/DivisiveClustering.php index 83fe7eea2..aeb7aa0db 100644 --- a/Algorithm/Clustering/DivisiveClustering.php +++ b/Algorithm/Clustering/DivisiveClustering.php @@ -14,8 +14,6 @@ declare(strict_types=1); namespace phpOMS\Algorithm\Clustering; -use phpOMS\Math\Topology\MetricsND; - /** * Clustering points * diff --git a/Algorithm/Clustering/Kmeans.php b/Algorithm/Clustering/Kmeans.php index 58e4691d9..dd85d1d8a 100755 --- a/Algorithm/Clustering/Kmeans.php +++ b/Algorithm/Clustering/Kmeans.php @@ -269,7 +269,7 @@ final class Kmeans implements ClusteringInterface } foreach ($this->points as $point) { - $c = $this->cluster($point); + $c = $this->cluster($point); $this->clusters[$c] = $point; } diff --git a/Algorithm/JobScheduling/Job.php b/Algorithm/JobScheduling/Job.php index 5ccb5af25..caefd9eff 100755 --- a/Algorithm/JobScheduling/Job.php +++ b/Algorithm/JobScheduling/Job.php @@ -57,7 +57,7 @@ class Job implements JobInterface public string $name = ''; /** - * Cosntructor. + * Constructor. * * @param float $value Value of the job * @param \DateTime $start Start time of the job diff --git a/Algorithm/Knapsack/Item.php b/Algorithm/Knapsack/Item.php index 7284916be..cc49c12d1 100755 --- a/Algorithm/Knapsack/Item.php +++ b/Algorithm/Knapsack/Item.php @@ -49,7 +49,7 @@ class Item implements ItemInterface public string $name = ''; /** - * Cosntructor. + * Constructor. * * @param float $value Value of the item * @param float $cost Cost of the item diff --git a/Algorithm/PathFinding/Path.php b/Algorithm/PathFinding/Path.php index fbd6b3f3a..92db7b5d7 100755 --- a/Algorithm/PathFinding/Path.php +++ b/Algorithm/PathFinding/Path.php @@ -54,7 +54,7 @@ class Path private array $expandedNodes = []; /** - * Cosntructor. + * Constructor. * * @param Grid $grid Grid this path belongs to * diff --git a/Algorithm/Rating/Elo.php b/Algorithm/Rating/Elo.php index 127905c25..b16d9d3e6 100644 --- a/Algorithm/Rating/Elo.php +++ b/Algorithm/Rating/Elo.php @@ -78,8 +78,8 @@ final class Elo /** * Calculate an approximated win probability based on elo points. * - * @param int $elo1 Elo of the player we want to calculate the win probability for - * @param int $elo2 Opponent elo + * @param int $elo1 Elo of the player we want to calculate the win probability for + * @param int $elo2 Opponent elo * @param bool $canDraw Is a draw possible? * * @return float diff --git a/Algorithm/Rating/TrueSkill.php b/Algorithm/Rating/TrueSkill.php index ab9c61987..852d1986e 100644 --- a/Algorithm/Rating/TrueSkill.php +++ b/Algorithm/Rating/TrueSkill.php @@ -40,9 +40,13 @@ class TrueSkill public const DEFAULT_DRAW_PROBABILITY = 0.1; private float $mu = 0.0; + private float $sigma = 0.0; + private float $beta = 0.0; + private float $tau = 0.0; + private float $drawProbability = 0.0; public function __construct( @@ -52,25 +56,25 @@ class TrueSkill float $tau = null, float $drawProbability = null) { - $this->mu = $mu ?? self::DEFAULT_MU; - $this->sigma = $sigma ?? self::DEFAULT_SIGMA; - $this->beta = $beta ?? self::DEFAULT_BETA; - $this->tau = $tau ?? self::DEFAULT_TAU; + $this->mu = $mu ?? self::DEFAULT_MU; + $this->sigma = $sigma ?? self::DEFAULT_SIGMA; + $this->beta = $beta ?? self::DEFAULT_BETA; + $this->tau = $tau ?? self::DEFAULT_TAU; $this->drawProbability = $drawProbability ?? self::DEFAULT_DRAW_PROBABILITY; } public function winProbability(array $team1, array $team2, float $drawMargin = 0.0) { $sigmaSum = 0.0; - $mu1 = 0.0; + $mu1 = 0.0; foreach ($team1 as $player) { - $mu1 += $player->mu; + $mu1 += $player->mu; $sigmaSum += $player->sigma * $player->sigma; } $mu2 = 0.0; foreach ($team2 as $player) { - $mu2 += $player->mu; + $mu2 += $player->mu; $sigmaSum += $player->sigma * $player->sigma; } diff --git a/Api/Address/Validation.php b/Api/Address/Validation.php index 3f1481777..fa06e7d02 100644 --- a/Api/Address/Validation.php +++ b/Api/Address/Validation.php @@ -1,3 +1,5 @@ setMethod(RequestMethod::GET); - $request->header->set('Content-Type', 'application/json'); + $request->header->set('Content-Type', MimeType::M_JSON); $request->header->set('Accept', '*/*'); $request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password)); @@ -274,14 +275,18 @@ final class DHLInternationalShipping implements ShippingInterface array $data ) : array { - } + /** + * {@inheritdoc} + */ public function cancel(string $shipment, array $packages = []) : bool { - } + /** + * {@inheritdoc} + */ public function track(string $shipment) : array { $base = self::$ENV === 'live' ? self::LIVE_URL : self::SANDBOX2_URL; @@ -302,7 +307,7 @@ final class DHLInternationalShipping implements ShippingInterface $request = new HttpRequest($httpUri); $request->setMethod(RequestMethod::GET); - $request->header->set('accept', 'application/json'); + $request->header->set('accept', MimeType::M_JSON); $request->header->set('dhl-api-key', $this->apiKey); $response = Rest::request($request); @@ -311,7 +316,7 @@ final class DHLInternationalShipping implements ShippingInterface } $shipments = $response->getDataArray('shipments') ?? []; - $tracking = []; + $tracking = []; // @todo add general shipment status (not just for individual packages) @@ -322,9 +327,9 @@ final class DHLInternationalShipping implements ShippingInterface $activities = []; foreach ($package['events'] as $activity) { $activities[] = [ - 'date' => new \DateTime($activity['timestamp']), + 'date' => new \DateTime($activity['timestamp']), 'description' => $activity['description'], - 'location' => [ + 'location' => [ 'address' => [ $activity['location']['address']['streetAddress'], $activity['location']['address']['addressLocality'], @@ -339,7 +344,7 @@ final class DHLInternationalShipping implements ShippingInterface 'code' => $activity['statusCode'], 'statusCode' => $activity['statusCode'], 'description' => $activity['status'], - ] + ], ]; } @@ -358,8 +363,8 @@ final class DHLInternationalShipping implements ShippingInterface 'by' => $package['details']['proofOfDelivery']['familyName'], 'signature' => $package['details']['proofOfDelivery']['signatureUrl'], 'location' => '', - 'date' => $package['details']['proofOfDelivery']['timestamp'] - ] + 'date' => $package['details']['proofOfDelivery']['timestamp'], + ], ]; $tracking[] = $packages; @@ -379,10 +384,20 @@ final class DHLInternationalShipping implements ShippingInterface */ public function label(string $shipment) : array { + return []; } + /** + * Finalize shipments (no further changes possible) + * + * @param string[] $shipment Shipments to finalize + * + * @return bool + * + * @since 1.0.0 + */ public function finalize(array $shipment = []) : bool { - + return true; } -} \ No newline at end of file +} diff --git a/Api/Shipping/DHL/DHLParcelDEShipping.php b/Api/Shipping/DHL/DHLParcelDEShipping.php index e53997cfb..c66f232c4 100644 --- a/Api/Shipping/DHL/DHLParcelDEShipping.php +++ b/Api/Shipping/DHL/DHLParcelDEShipping.php @@ -21,6 +21,7 @@ use phpOMS\Localization\ISO3166CharEnum; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\RequestMethod; use phpOMS\Message\Http\Rest; +use phpOMS\System\MimeType; use phpOMS\Uri\HttpUri; /** @@ -258,7 +259,7 @@ final class DHLParcelDEShipping implements ShippingInterface $request = new HttpRequest(new HttpUri($uri)); $request->setMethod(RequestMethod::GET); - $request->header->set('Accept', 'application/json'); + $request->header->set('Accept', MimeType::M_JSON); $request->header->set('dhl-api-key', $key); $response = Rest::request($request); @@ -312,7 +313,7 @@ final class DHLParcelDEShipping implements ShippingInterface $request = new HttpRequest($httpUri); $request->setMethod(RequestMethod::POST); - $request->header->set('Content-Type', 'application/json'); + $request->header->set('Content-Type', MimeType::M_JSON); $request->header->set('Accept-Language', 'en-US'); $request->header->set('Authorization', 'Basic ' . \base64_encode($this->login . ':' . $this->password)); @@ -320,42 +321,42 @@ final class DHLParcelDEShipping implements ShippingInterface $shipments = [ [ - 'product' => 'V01PAK', // V53WPAK, V53WPAK + 'product' => 'V01PAK', // V53WPAK, V53WPAK 'billingNumber' => $data['costcenter'], // @todo maybe dhl number, check - 'refNo' => $package['id'], - 'shipper' => [ - 'name1' => $sender['name'], - 'addressStreet' => $sender['address'], + 'refNo' => $package['id'], + 'shipper' => [ + 'name1' => $sender['name'], + 'addressStreet' => $sender['address'], 'additionalAddressInformation1' => $sender['address_addition'], - 'postalCode' => $sender['zip'], - 'city' => $sender['city'], - 'country' => ISO3166CharEnum::getBy2Code($sender['country_code']), - 'email' => $sender['email'], - 'phone' => $sender['phone'], + 'postalCode' => $sender['zip'], + 'city' => $sender['city'], + 'country' => ISO3166CharEnum::getBy2Code($sender['country_code']), + 'email' => $sender['email'], + 'phone' => $sender['phone'], ], 'consignee' => [ - 'name1' => $receiver['name'], - 'addressStreet' => $receiver['address'], + 'name1' => $receiver['name'], + 'addressStreet' => $receiver['address'], 'additionalAddressInformation1' => $receiver['address_addition'], - 'postalCode' => $receiver['zip'], - 'city' => $receiver['city'], - 'country' => ISO3166CharEnum::getBy2Code($receiver['country_code']), - 'email' => $receiver['email'], - 'phone' => $receiver['phone'], + 'postalCode' => $receiver['zip'], + 'city' => $receiver['city'], + 'country' => ISO3166CharEnum::getBy2Code($receiver['country_code']), + 'email' => $receiver['email'], + 'phone' => $receiver['phone'], ], 'details' => [ 'dim' => [ - 'uom' => 'mm', + 'uom' => 'mm', 'height' => $package['height'], 'length' => $package['length'], - 'width' => $package['width'], + 'width' => $package['width'], ], 'weight' => [ - 'uom' => 'g', + 'uom' => 'g', 'value' => $package['weight'], ], - ] - ] + ], + ], ]; $request->setData('shipments', $shipments); @@ -368,23 +369,23 @@ final class DHLParcelDEShipping implements ShippingInterface $result = $response->getDataArray('items') ?? []; $labelUri = new HttpUri($result[0]['label']['url']); - $label = $this->label($labelUri->getQuery('token')); + $label = $this->label($labelUri->getQuery('token')); return [ - 'id' => $result[0]['shipmentNo'], + 'id' => $result[0]['shipmentNo'], 'label' => [ 'code' => $result[0]['label']['format'], 'url' => $result[0]['label']['url'], 'data' => $label['data'], ], 'packages' => [ - 'id' => $result[0]['shipmentNo'], + 'id' => $result[0]['shipmentNo'], 'label' => [ 'code' => $result[0]['label']['format'], 'url' => $result[0]['label']['url'], 'data' => $label['data'], - ] - ] + ], + ], ]; } @@ -445,23 +446,23 @@ final class DHLParcelDEShipping implements ShippingInterface $result = $response->getDataArray('items') ?? []; $labelUri = new HttpUri($result[0]['label']['url']); - $label = $this->label($labelUri->getQuery('token')); + $label = $this->label($labelUri->getQuery('token')); return [ - 'id' => $result[0]['shipmentNo'], + 'id' => $result[0]['shipmentNo'], 'label' => [ 'code' => $result[0]['label']['format'], 'url' => $result[0]['label']['url'], 'data' => $label['data'], ], 'packages' => [ - 'id' => $result[0]['shipmentNo'], + 'id' => $result[0]['shipmentNo'], 'label' => [ 'code' => $result[0]['label']['format'], 'url' => $result[0]['label']['url'], 'data' => $label['data'], - ] - ] + ], + ], ]; } @@ -484,7 +485,7 @@ final class DHLParcelDEShipping implements ShippingInterface $request = new HttpRequest($httpUri); $request->setMethod(RequestMethod::GET); - $request->header->set('Content-Type', 'application/pdf'); + $request->header->set('Content-Type', MimeType::M_PDF); $response = Rest::request($request); if ($response->header->status !== 200) { @@ -519,7 +520,7 @@ final class DHLParcelDEShipping implements ShippingInterface $request = new HttpRequest($httpUri); $request->setMethod(RequestMethod::GET); - $request->header->set('accept', 'application/json'); + $request->header->set('accept', MimeType::M_JSON); $request->header->set('dhl-api-key', $this->apiKey); $response = Rest::request($request); @@ -528,7 +529,7 @@ final class DHLParcelDEShipping implements ShippingInterface } $shipments = $response->getDataArray('shipments') ?? []; - $tracking = []; + $tracking = []; // @todo add general shipment status (not just for individual packages) @@ -539,9 +540,9 @@ final class DHLParcelDEShipping implements ShippingInterface $activities = []; foreach ($package['events'] as $activity) { $activities[] = [ - 'date' => new \DateTime($activity['timestamp']), + 'date' => new \DateTime($activity['timestamp']), 'description' => $activity['description'], - 'location' => [ + 'location' => [ 'address' => [ $activity['location']['address']['streetAddress'], $activity['location']['address']['addressLocality'], @@ -556,7 +557,7 @@ final class DHLParcelDEShipping implements ShippingInterface 'code' => $activity['statusCode'], 'statusCode' => $activity['statusCode'], 'description' => $activity['status'], - ] + ], ]; } @@ -575,8 +576,8 @@ final class DHLParcelDEShipping implements ShippingInterface 'by' => $package['details']['proofOfDelivery']['familyName'], 'signature' => $package['details']['proofOfDelivery']['signatureUrl'], 'location' => '', - 'date' => $package['details']['proofOfDelivery']['timestamp'] - ] + 'date' => $package['details']['proofOfDelivery']['timestamp'], + ], ]; $tracking[] = $packages; @@ -615,10 +616,10 @@ final class DHLParcelDEShipping implements ShippingInterface } return [ - 'date' => $response->getDataDateTime('manifestDate'), - 'b64' => $response->getDataArray('manifest')['b64'], - 'zpl2' => $response->getDataArray('manifest')['zpl2'], - 'url' => $response->getDataArray('manifest')['url'], + 'date' => $response->getDataDateTime('manifestDate'), + 'b64' => $response->getDataArray('manifest')['b64'], + 'zpl2' => $response->getDataArray('manifest')['zpl2'], + 'url' => $response->getDataArray('manifest')['url'], 'format' => $response->getDataArray('manifest')['printFormat'], ]; } @@ -644,7 +645,7 @@ final class DHLParcelDEShipping implements ShippingInterface $request = new HttpRequest($httpUri); $request->setMethod(RequestMethod::POST); - $request->header->set('Content-Type', 'application/json'); + $request->header->set('Content-Type', MimeType::M_JSON); $request->header->set('Authorization', 'Basic ' . \base64_encode($this->login . ':' . $this->password)); if (!empty($shipment)) { diff --git a/Api/Shipping/DHL/DHLeCommerceShipping.php b/Api/Shipping/DHL/DHLeCommerceShipping.php index 96ea2041c..2990683f1 100644 --- a/Api/Shipping/DHL/DHLeCommerceShipping.php +++ b/Api/Shipping/DHL/DHLeCommerceShipping.php @@ -15,10 +15,6 @@ declare(strict_types=1); namespace phpOMS\Api\Shipping\DHL; use phpOMS\Api\Shipping\ShippingInterface; -use phpOMS\Message\Http\HttpRequest; -use phpOMS\Message\Http\RequestMethod; -use phpOMS\Message\Http\Rest; -use phpOMS\Uri\HttpUri; /** * Shipment api. @@ -33,4 +29,4 @@ use phpOMS\Uri\HttpUri; */ final class DHLParcelDEShipping implements ShippingInterface { -} \ No newline at end of file +} diff --git a/Api/Shipping/DPD/DPDShipping.php b/Api/Shipping/DPD/DPDShipping.php index 2f1de690c..1c9f36d66 100644 --- a/Api/Shipping/DPD/DPDShipping.php +++ b/Api/Shipping/DPD/DPDShipping.php @@ -15,10 +15,6 @@ declare(strict_types=1); namespace phpOMS\Api\Shipping\DPD; use phpOMS\Api\Shipping\ShippingInterface; -use phpOMS\Message\Http\HttpRequest; -use phpOMS\Message\Http\RequestMethod; -use phpOMS\Message\Http\Rest; -use phpOMS\Uri\HttpUri; /** * Shipment api. @@ -32,4 +28,4 @@ use phpOMS\Uri\HttpUri; */ final class DPDShipping implements ShippingInterface { -} \ No newline at end of file +} diff --git a/Api/Shipping/Fedex/FedexShipping.php b/Api/Shipping/Fedex/FedexShipping.php index 456591645..0f99bac11 100644 --- a/Api/Shipping/Fedex/FedexShipping.php +++ b/Api/Shipping/Fedex/FedexShipping.php @@ -15,10 +15,6 @@ declare(strict_types=1); namespace phpOMS\Api\Shipping\Fedex; use phpOMS\Api\Shipping\ShippingInterface; -use phpOMS\Message\Http\HttpRequest; -use phpOMS\Message\Http\RequestMethod; -use phpOMS\Message\Http\Rest; -use phpOMS\Uri\HttpUri; /** * Shipment api. @@ -31,4 +27,4 @@ use phpOMS\Uri\HttpUri; */ final class FedexShipping implements ShippingInterface { -} \ No newline at end of file +} diff --git a/Api/Shipping/RoyalMail/RoyalMailShipping.php b/Api/Shipping/RoyalMail/RoyalMailShipping.php index 7513a4166..4d6fe0a0d 100644 --- a/Api/Shipping/RoyalMail/RoyalMailShipping.php +++ b/Api/Shipping/RoyalMail/RoyalMailShipping.php @@ -15,10 +15,6 @@ declare(strict_types=1); namespace phpOMS\Api\Shipping\RoyalMail; use phpOMS\Api\Shipping\ShippingInterface; -use phpOMS\Message\Http\HttpRequest; -use phpOMS\Message\Http\RequestMethod; -use phpOMS\Message\Http\Rest; -use phpOMS\Uri\HttpUri; /** * Shipment api. @@ -31,4 +27,4 @@ use phpOMS\Uri\HttpUri; */ final class RoyalMailShipping implements ShippingInterface { -} \ No newline at end of file +} diff --git a/Api/Shipping/ShippingInterface.php b/Api/Shipping/ShippingInterface.php index 6599233eb..871f57c46 100644 --- a/Api/Shipping/ShippingInterface.php +++ b/Api/Shipping/ShippingInterface.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace phpOMS\Api\Shipping; use phpOMS\Message\Http\HttpRequest; -use phpOMS\Message\Http\HttpResponse; /** * Shipping interface. @@ -32,7 +31,7 @@ use phpOMS\Message\Http\HttpResponse; * * @todo implement Sender, Receiver, Package, Transit, Tracking classes for better type hinting instead of arrays * - * @property string $ENV ('live' = live environment, 'test' or 'sandbox' = test environment) + * @property string $ENV ('live' = live environment, 'test' or 'sandbox' = test environment) * @property string $client * @property string $token * @property string $refreshToken @@ -93,7 +92,7 @@ interface ShippingInterface * * @param string $login Login name/email * @param string $password Password - * @param HttpRequest $redirect Redirect request after the user successfully logged in. + * @param HttpRequest $redirect redirect request after the user successfully logged in * * @return int Returns auth status * @@ -131,7 +130,7 @@ interface ShippingInterface * * @param array $sender Sender * @param array $shipFrom Ship from location (sometimes sender != pickup location) - * @param array $recevier Receiver + * @param array $receiver Receiver * @param array $package Package * @param array $data Shipping data * @@ -150,7 +149,7 @@ interface ShippingInterface /** * Cancel shipment. * - * @param string $shipment Shipment id + * @param string $shipment Shipment id * @param string[] $packages Packed ids (if a shipment consists of multiple packages) * * @return bool diff --git a/Api/Shipping/TNT/TNTShipping.php b/Api/Shipping/TNT/TNTShipping.php index 31e5fe039..728c36390 100644 --- a/Api/Shipping/TNT/TNTShipping.php +++ b/Api/Shipping/TNT/TNTShipping.php @@ -15,10 +15,6 @@ declare(strict_types=1); namespace phpOMS\Api\Shipping\TNT; use phpOMS\Api\Shipping\ShippingInterface; -use phpOMS\Message\Http\HttpRequest; -use phpOMS\Message\Http\RequestMethod; -use phpOMS\Message\Http\Rest; -use phpOMS\Uri\HttpUri; /** * Shipment api. @@ -31,4 +27,4 @@ use phpOMS\Uri\HttpUri; */ final class TNTShipping implements ShippingInterface { -} \ No newline at end of file +} diff --git a/Api/Shipping/UPS/UPSShipping.php b/Api/Shipping/UPS/UPSShipping.php index b7dc054d8..ad1f9ef94 100644 --- a/Api/Shipping/UPS/UPSShipping.php +++ b/Api/Shipping/UPS/UPSShipping.php @@ -20,6 +20,7 @@ use phpOMS\Api\Shipping\ShippingInterface; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\RequestMethod; use phpOMS\Message\Http\Rest; +use phpOMS\System\MimeType; use phpOMS\Uri\HttpUri; /** @@ -177,7 +178,7 @@ final class UPSShipping implements ShippingInterface $request = new HttpRequest(new HttpUri($uri)); $request->setMethod(RequestMethod::POST); $request->setData('grant_type', 'client_credentials'); - $request->header->set('Content-Type', 'application/x-www-form-urlencoded'); + $request->header->set('Content-Type', MimeType::M_POST); $request->header->set('x-merchant-id', $client); $request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password)); @@ -255,7 +256,7 @@ final class UPSShipping implements ShippingInterface // Personally I don't see why a redirect is required or even helpful. Will try without it! $request->setData('grant_type', 'authorization_code'); $request->setData('code', $code); - $request->header->set('Content-Type', 'application/x-www-form-urlencoded'); + $request->header->set('Content-Type', MimeType::M_POST); $request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password)); $this->expire = new \DateTime('now'); @@ -306,7 +307,7 @@ final class UPSShipping implements ShippingInterface $request = new HttpRequest(new HttpUri($uri)); $request->setMethod(RequestMethod::POST); - $request->header->set('Content-Type', 'application/x-www-form-urlencoded'); + $request->header->set('Content-Type', MimeType::M_POST); $request->header->set('Authorization', 'Basic ' . \base64_encode($this->login . ':' . $this->password)); $request->setData('grant_type', 'refresh_token'); @@ -367,7 +368,7 @@ final class UPSShipping implements ShippingInterface $request = new HttpRequest(new HttpUri($uri)); $request->setMethod(RequestMethod::POST); - $request->header->set('Content-Type', 'application/json'); + $request->header->set('Content-Type', MimeType::M_JSON); $request->header->set('Authorization', 'Bearer ' . $this->token); $request->header->set('transId', ((string) \microtime(true)) . '-' . \bin2hex(\random_bytes(6))); $request->header->set('transactionSrc', 'jingga'); @@ -402,10 +403,10 @@ final class UPSShipping implements ShippingInterface foreach ($services as $service) { $transits[] = [ - 'serviceLevel' => $service['serviceLevel'], - 'deliveryDate' => new \DateTime($service['deliveryDaye']), + 'serviceLevel' => $service['serviceLevel'], + 'deliveryDate' => new \DateTime($service['deliveryDaye']), 'deliveryDateFrom' => null, - 'deliveryDateTo' => null, + 'deliveryDateTo' => null, ]; } @@ -440,9 +441,9 @@ final class UPSShipping implements ShippingInterface 'SubVersion' => '2205', ], 'Shipment' => [ - 'Description' => $package['description'], + 'Description' => $package['description'], 'DocumentsOnlyIndicator' => '0', - 'Shipper' => [ + 'Shipper' => [ 'Name' => \substr($sender['name'], 0, 35), 'AttentionName' => \substr($sender['fao'], 0, 35), 'CompanyDisplayableName' => \substr($sender['name'], 0, 35), @@ -452,7 +453,7 @@ final class UPSShipping implements ShippingInterface ], 'ShipperNumber' => $sender['number'], 'EMailAddress' => \substr($sender['email'], 0, 50), - 'Address' => [ + 'Address' => [ 'AddressLine' => \substr($sender['address'], 0, 35), 'City' => \substr($sender['city'], 0, 30), 'StateProvinceCode' => \substr($sender['state'], 0, 5), @@ -470,7 +471,7 @@ final class UPSShipping implements ShippingInterface ], 'ShipperNumber' => $receiver['number'], 'EMailAddress' => \substr($receiver['email'], 0, 50), - 'Address' => [ + 'Address' => [ 'AddressLine' => \substr($receiver['address'], 0, 35), 'City' => \substr($receiver['city'], 0, 30), 'StateProvinceCode' => \substr($receiver['state'], 0, 5), @@ -497,7 +498,7 @@ final class UPSShipping implements ShippingInterface 'CostCenter' => \substr($package['costcenter'], 0, 30), 'PackageID' => \substr($package['id'], 0, 30), 'PackageIDBarcodeIndicator' => '1', - 'Package' => [] + 'Package' => [], ], 'LabelSpecification' => [ 'LabelImageFormat' => [ @@ -507,13 +508,13 @@ final class UPSShipping implements ShippingInterface 'LabelStockSize' => [ 'Height' => $data['label_height'], 'Width' => $data['label_width'], - ] + ], ], 'ReceiptSpecification' => [ 'ImageFormat' => [ 'Code' => $data['receipt_code'], 'Description' => \substr($data['receipt_description'], 0, 35), - ] + ], ], ]; @@ -521,13 +522,13 @@ final class UPSShipping implements ShippingInterface foreach ($package['packages'] as $p) { $packages[] = [ 'Description' => \substr($p['description'], 0, 35), - 'Packaging' => [ + 'Packaging' => [ 'Code' => $p['package_code'], - 'Description' => $p['package_description'] + 'Description' => $p['package_description'], ], 'Dimensions' => [ 'UnitOfMeasurement' => [ - 'Code' => $p['package_dim_unit'], // IN or CM or 00 or 01 + 'Code' => $p['package_dim_unit'], // IN or CM or 00 or 01 'Description' => \substr($p['package_dim_unit_description'], 0, 35), ], 'Length' => $p['length'], @@ -547,7 +548,7 @@ final class UPSShipping implements ShippingInterface 'Description' => \substr($p['package_weight_unit_description'], 0, 35), ], 'Weight' => $p['weight'], - ] + ], ]; } @@ -566,7 +567,7 @@ final class UPSShipping implements ShippingInterface ], 'ShipperNumber' => $shipFrom['number'], 'EMailAddress' => \substr($shipFrom['email'], 0, 50), - 'Address' => [ + 'Address' => [ 'AddressLine' => \substr($shipFrom['address'], 0, 35), 'City' => \substr($shipFrom['city'], 0, 30), 'StateProvinceCode' => \substr($shipFrom['state'], 0, 5), @@ -586,7 +587,7 @@ final class UPSShipping implements ShippingInterface $result = $response->getDataArray('ShipmentResponse') ?? []; $shipment = [ - 'id' => $result['ShipmentResults']['ShipmentIdentificationNumber'] ?? '', + 'id' => $result['ShipmentResults']['ShipmentIdentificationNumber'] ?? '', 'costs' => [ 'service' => $result['ShipmentResults']['ShipmentCharges']['BaseServiceCharge']['MonetaryValue'] ?? null, 'transportation' => $result['ShipmentResults']['ShipmentCharges']['TransportationCharges']['MonetaryValue'] ?? null, @@ -598,38 +599,38 @@ final class UPSShipping implements ShippingInterface 'currency' => $result['ShipmentResults']['ShipmentCharges']['TotalCharges']['CurrencyCode'] ?? null, ], 'packages' => [], - 'label' => [ - 'code' => '', - 'url' => $result['ShipmentResults']['LabelURL'] ?? '', + 'label' => [ + 'code' => '', + 'url' => $result['ShipmentResults']['LabelURL'] ?? '', 'barcode' => $result['ShipmentResults']['BarCodeImage'] ?? '', - 'local' => $result['ShipmentResults']['LocalLanguageLabelURL'] ?? '', + 'local' => $result['ShipmentResults']['LocalLanguageLabelURL'] ?? '', 'data' => '', ], 'receipt' => [ 'code' => '', 'url' => $result['ShipmentResults']['ReceiptURL'] ?? '', 'local' => $result['ShipmentResults']['LocalLanguageReceiptURL'] ?? '', - 'data' => '', - ] + 'data' => '', + ], // @todo dangerous goods paper image ]; $packages = []; foreach ($result['ShipmentResults']['Packages'] as $package) { $packages[] = [ - 'id' => $package['TrackingNumber'], + 'id' => $package['TrackingNumber'], 'label' => [ - 'code' => $package['ShippingLabel']['ImageFormat']['Code'], + 'code' => $package['ShippingLabel']['ImageFormat']['Code'], 'url' => '', - 'barcode' => $package['PDF417'], - 'image' => $package['ShippingLabel']['GraphicImage'], - 'browser' => $package['HTMLImage'], - 'data' => '', + 'barcode' => $package['PDF417'], + 'image' => $package['ShippingLabel']['GraphicImage'], + 'browser' => $package['HTMLImage'], + 'data' => '', ], 'receipt' => [ 'code' => $package['ShippingReceipt']['ImageFormat']['Code'], 'image' => $package['ShippingReceipt']['ImageFormat']['GraphicImage'], - ] + ], ]; } @@ -707,9 +708,9 @@ final class UPSShipping implements ShippingInterface $activities = []; foreach ($package['activity'] as $activity) { $activities[] = [ - 'date' => new \DateTime($activity['date'] . ' ' . $activity['time']), + 'date' => new \DateTime($activity['date'] . ' ' . $activity['time']), 'description' => '', - 'location' => [ + 'location' => [ 'address' => [ $activity['location']['address']['addressLine1'], $activity['location']['address']['addressLine2'], @@ -725,7 +726,7 @@ final class UPSShipping implements ShippingInterface 'code' => $activity['status']['code'], 'statusCode' => $activity['status']['statusCode'], 'description' => $activity['status']['description'], - ] + ], ]; } @@ -745,7 +746,7 @@ final class UPSShipping implements ShippingInterface 'signature' => $package['deliveryInformation']['signature'], 'location' => $package['deliveryInformation']['location'], 'date' => '', - ] + ], ]; } diff --git a/Api/Shipping/Usps/UspsShipping.php b/Api/Shipping/Usps/UspsShipping.php index 6627a04ac..165e9cf5c 100644 --- a/Api/Shipping/Usps/UspsShipping.php +++ b/Api/Shipping/Usps/UspsShipping.php @@ -15,10 +15,6 @@ declare(strict_types=1); namespace phpOMS\Api\Shipping\Usps; use phpOMS\Api\Shipping\ShippingInterface; -use phpOMS\Message\Http\HttpRequest; -use phpOMS\Message\Http\RequestMethod; -use phpOMS\Message\Http\Rest; -use phpOMS\Uri\HttpUri; /** * Shipment api. @@ -31,4 +27,4 @@ use phpOMS\Uri\HttpUri; */ final class UspsShipping implements ShippingInterface { -} \ No newline at end of file +} diff --git a/Autoloader.php b/Autoloader.php index da2bf7060..ac9707707 100755 --- a/Autoloader.php +++ b/Autoloader.php @@ -138,6 +138,17 @@ final class Autoloader $class = \ltrim($class, '\\'); $class = \strtr($class, '_\\', '//'); + if (self::$useClassMap) { + $nspacePos = \strpos($class, '/'); + $subclass = $nspacePos === false ? '' : \substr($class, 0, $nspacePos); + + if (isset(self::$classmap[$subclass])) { + $found[] = self::$classmap[$subclass] . $class . '.php'; + + return $found; + } + } + foreach (self::$paths as $path) { if (\is_file($file = $path . $class . '.php')) { $found[] = $file; diff --git a/Business/Marketing/Metrics.php b/Business/Marketing/Metrics.php index f7e2269ab..d42fb077f 100755 --- a/Business/Marketing/Metrics.php +++ b/Business/Marketing/Metrics.php @@ -137,7 +137,7 @@ final class Metrics } /** - * Calculate the profitability of customers based on their purchase behaviour + * Calculate the profitability of customers based on their purchase behavior * * The basis for the calculation is the migration model using a markov chain * diff --git a/Business/Recommendation/ArticleCorrelationAffinity.php b/Business/Recommendation/ArticleCorrelationAffinity.php index b3163add2..10340beef 100644 --- a/Business/Recommendation/ArticleCorrelationAffinity.php +++ b/Business/Recommendation/ArticleCorrelationAffinity.php @@ -37,7 +37,7 @@ final class ArticleCorrelationAffinity private array $affinity = []; /** - * Item order behaviour (when are which items ordered) + * Item order behavior (when are which items ordered) * * In tearms of the pearson correlation these are our random variables * diff --git a/DataStorage/Database/Mapper/MapperType.php b/DataStorage/Database/Mapper/MapperType.php index 158ea6f2c..8fde41f96 100755 --- a/DataStorage/Database/Mapper/MapperType.php +++ b/DataStorage/Database/Mapper/MapperType.php @@ -38,6 +38,13 @@ abstract class MapperType extends Enum public const GET_RANDOM = 11; + // @IMPORTANT All read operations which use column names must have an ID < 12 + // In the read mapper exists a line which checks for < COUNT_MODELS to decide if columns should be selected. + // The reason for this is that **pure** count, sum, ... don't want to select additional column names. + // By doing this we avoid loading all the unwanted columns coming from the `with()` relation. + + // -------------------------------------------- // + public const COUNT_MODELS = 12; public const SUM_MODELS = 13; diff --git a/DataStorage/Database/Mapper/ReadMapper.php b/DataStorage/Database/Mapper/ReadMapper.php index a796c806d..9fc5488da 100755 --- a/DataStorage/Database/Mapper/ReadMapper.php +++ b/DataStorage/Database/Mapper/ReadMapper.php @@ -536,9 +536,14 @@ final class ReadMapper extends DataMapperAbstract public function getQuery(Builder $query = null, array $columns = []) : Builder { $query ??= $this->query ?? new Builder($this->db, true); - $columns = empty($columns) - ? (empty($this->columns) ? $this->mapper::COLUMNS : $this->columns) - : $columns; + + if (empty($columns) && $this->type < MapperType::COUNT_MODELS) { + if (empty($this->columns)) { + $columns = $this->mapper::COLUMNS; + } else { + $columns = $this->columns; + } + } foreach ($columns as $key => $values) { if (\is_string($values) || \is_int($values)) { @@ -731,6 +736,7 @@ final class ReadMapper extends DataMapperAbstract /** @var self $relMapper */ $relMapper = $this->createRelationMapper($rel['mapper']::reader(db: $this->db), $member); $relMapper->depth = $this->depth + 1; + $relMapper->type = $this->type; $query = $relMapper->getQuery( $query, @@ -846,7 +852,7 @@ final class ReadMapper extends DataMapperAbstract } if (empty($value)) { - // @todo find better solution. this was because of a bug with the sales billing list query depth = 4. The address was set (from the client, referral or creator) but then somehow there was a second address element which was all null and null cannot be asigned to a string variable (e.g. country). The problem with this solution is that if the model expects an initialization (e.g. at lest set the elements to null, '', 0 etc.) this is now not done. + // @todo find better solution. this was because of a bug with the sales billing list query depth = 4. The address was set (from the client, referral or creator) but then somehow there was a second address element which was all null and null cannot be assigned to a string variable (e.g. country). The problem with this solution is that if the model expects an initialization (e.g. at lest set the elements to null, '', 0 etc.) this is now not done. $value = $isPrivate ? $refProp->getValue($obj) : $obj->{$member}; } } elseif (isset($this->mapper::BELONGS_TO[$def['internal']])) { @@ -912,10 +918,16 @@ final class ReadMapper extends DataMapperAbstract // @todo How is this allowed? at the bottom we set $obj->hasMany = value. A has many should be always an array?! foreach ($this->mapper::HAS_MANY as $member => $def) { + if (!isset($this->with[$member]) + || !isset($def['column']) // @todo is this required? The code below indicates that this might be stupid + ) { + continue; + } + $column = $def['mapper']::getColumnByMember($def['column'] ?? $member); $alias = $column . '_d' . ($this->depth + 1); - if (!\array_key_exists($alias, $result) || !isset($def['column'])) { + if (!\array_key_exists($alias, $result)) { continue; } @@ -1145,7 +1157,7 @@ final class ReadMapper extends DataMapperAbstract ->where($many['table'] . '.' . $many['self'], '=', $primaryKey); // Cannot use join, because join only works on members and we don't have members for a relation table - // This is why we need to create a "base" query which contians the join on table columns + // This is why we need to create a "base" query which contains the join on table columns $objectMapper->query($query); } @@ -1162,12 +1174,12 @@ final class ReadMapper extends DataMapperAbstract $refProp = $refClass->getProperty($member); $refProp->setValue($obj, !\is_array($objects) && ($many['conditional'] ?? false) === false ? [$many['mapper']::getObjectId($objects) => $objects] - : $objects // if conditional === true the obj will be asigned (e.g. has many localizations but only one is loaded for the model) + : $objects // if conditional === true the obj will be assigned (e.g. has many localizations but only one is loaded for the model) ); } else { $obj->{$member} = !\is_array($objects) && ($many['conditional'] ?? false) === false ? [$many['mapper']::getObjectId($objects) => $objects] - : $objects; // if conditional === true the obj will be asigned (e.g. has many localizations but only one is loaded for the model) + : $objects; // if conditional === true the obj will be assigned (e.g. has many localizations but only one is loaded for the model) } continue; @@ -1244,7 +1256,7 @@ final class ReadMapper extends DataMapperAbstract ->where($many['table'] . '.' . $many['self'], '=', $primaryKey); // Cannot use join, because join only works on members and we don't have members for a relation table - // This is why we need to create a "base" query which contians the join on table columns + // This is why we need to create a "base" query which contains the join on table columns $objectMapper->query($query); } diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index 7980f650a..589741664 100755 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -458,9 +458,11 @@ class Grammar extends GrammarAbstract $expression .= '(' . \rtrim($this->compileWhereQuery($element['column']), ';') . ')'; } - // @todo on doesn't allow values as value (only table column names). This is bad and needs to be fixed! + // @todo on doesn't allow string values as value (only table column names). This is bad and needs to be fixed! + // Other types such as int etc. are kind of possible if (isset($element['value'])) { - $expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileSystem($element['value']); + $expression .= ' ' . \strtoupper($element['operator']) . ' ' + . (\is_string($element['value']) ? $this->compileSystem($element['value']) : $element['value']); } else { $operator = $element['operator'] === '=' ? 'IS' : 'IS NOT'; $expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value']); diff --git a/Image/Kernel.php b/Image/Kernel.php index a2eb1cf39..924fc4388 100755 --- a/Image/Kernel.php +++ b/Image/Kernel.php @@ -125,7 +125,7 @@ final class Kernel /** * Apply kernel matrix * - * @param string $inParth Image file path + * @param string $inPath Image file path * @param string $outPath Image output path * @param array $kernel Kernel matrix * diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index c2b2f01e6..6daf401a3 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -544,7 +544,7 @@ class Matrix implements \ArrayAccess, \Iterator if ($mDim > 10 || $nDim > 10) { // Standard transposed for iteration over rows -> higher cache hit - $transposedMatrixArr = array(); + $transposedMatrixArr = []; for ($k = 0; $k < $mDim; ++$k) { for ($j = 0; $j < $nDim; ++$j) { $transposedMatrixArr[$k][$j] = $matrixArr[$j][$k]; diff --git a/Math/Matrix/Vector.php b/Math/Matrix/Vector.php index 1319fcb86..42eb90985 100755 --- a/Math/Matrix/Vector.php +++ b/Math/Matrix/Vector.php @@ -123,7 +123,6 @@ final class Vector extends Matrix return $dotProduct / ($magnitude1 * $magnitude2); } - /** * Calculate the eucledian dot product * diff --git a/Math/Optimization/Simplex.php b/Math/Optimization/Simplex.php index eaca9d8c6..cd6797040 100644 --- a/Math/Optimization/Simplex.php +++ b/Math/Optimization/Simplex.php @@ -131,7 +131,7 @@ final class Simplex } } - $this->b[$x] /= -$this->A[$x][$y]; + $this->b[$x] /= -$this->A[$x][$y]; $this->A[$x][$y] = 1.0 / $this->A[$x][$y]; for ($i = 0; $i < $this->m; ++$i) { @@ -142,7 +142,7 @@ final class Simplex } } - $this->b[$i] += $this->A[$i][$y] * $this->b[$x]; + $this->b[$i] += $this->A[$i][$y] * $this->b[$x]; $this->A[$i][$y] *= $this->A[$x][$y]; } } @@ -153,7 +153,7 @@ final class Simplex } } - $this->v += $this->c[$y] * $this->b[$x]; + $this->v += $this->c[$y] * $this->b[$x]; $this->c[$y] *= $this->A[$x][$y]; $temp = $this->basic[$x]; @@ -329,7 +329,7 @@ final class Simplex for ($k = 0; $k < $this->n; ++$k) { if ($j === $this->nonbasic[$k]) { $this->c[$k] += $oldC[$j]; - $ok = true; + $ok = true; break; } } @@ -357,10 +357,10 @@ final class Simplex * Solve simplex problem * * @param array> $A Bounding equations - * @param int[]|float[] $b Boundings for equations - * @param int[]|float[] $c Equation to maximize + * @param int[]|float[] $b Boundings for equations + * @param int[]|float[] $c Equation to maximize * - * @return array{0:array, 1:float} + * @return array|array{0:array, 1:float} * * @since 1.0.0 */ @@ -374,6 +374,10 @@ final class Simplex // @todo create minimize $this->m = \count($A); + if ($this->m < 1) { + return []; + } + $this->n = \count(\reset($A)); if ($this->initialize() === -1) { diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index ee15599bc..54b44e816 100755 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -215,6 +215,47 @@ abstract class RequestAbstract implements MessageInterface : new \DateTime((string) $this->data[$key]); } + /** + * Get data. + * + * @param string $key Data key + * + * @return null|\DateTime + * + * @since 1.0.0 + */ + public function getDataDateTimeFromTimestamp(string $key) : ?\DateTime + { + $key = \mb_strtolower($key); + + if (empty($this->data[$key] ?? null)) { + return null; + } + + $dt = new \DateTime(); + $dt->setTimestamp((int) $this->data[$key]); + + return $dt; + } + + /** + * Get data. + * + * @param string $key Data key + * + * @return null|int + * + * @since 1.0.0 + */ + public function getDataTimestampFromDateTime(string $key) : ?int + { + $key = \mb_strtolower($key); + + return empty($this->data[$key] ?? null) + ? null + : \strtotime((string) $this->data[$key]); + } + /** * Get data. * diff --git a/Module/ModuleInfo.php b/Module/ModuleInfo.php index 3da723c1b..be8553623 100755 --- a/Module/ModuleInfo.php +++ b/Module/ModuleInfo.php @@ -40,7 +40,7 @@ final class ModuleInfo /** * Info data. * - * @var array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, description:string, directory:string, dependencies:array, providing:array, load:array}|array + * @var array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, directory:string, dependencies:array, providing:array, load:array}|array * @since 1.0.0 */ private array $info = []; @@ -86,7 +86,7 @@ final class ModuleInfo $contents = \file_get_contents($this->path); - /** @var array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, description:string, directory:string, dependencies:array, providing:array, load:array} $info */ + /** @var array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, directory:string, dependencies:array, providing:array, load:array} $info */ $info = \json_decode($contents === false ? '[]' : $contents, true); $this->info = $info === false ? [] : $info; } @@ -134,7 +134,7 @@ final class ModuleInfo /** * Get info data. * - * @return array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, description:string, directory:string, dependencies:array, providing:array, load:array}|array + * @return array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, directory:string, dependencies:array, providing:array, load:array}|array * * @since 1.0.0 */ diff --git a/Stdlib/Base/Address.php b/Stdlib/Base/Address.php index abf939f18..bcda6fbbe 100755 --- a/Stdlib/Base/Address.php +++ b/Stdlib/Base/Address.php @@ -61,7 +61,7 @@ class Address extends Location */ public function toArray() : array { - return \array_merge ( + return \array_merge( [ 'name' => $this->name, 'fao' => $this->fao, diff --git a/Stdlib/Base/SmartDateTime.php b/Stdlib/Base/SmartDateTime.php index 30b456207..c88516aaf 100755 --- a/Stdlib/Base/SmartDateTime.php +++ b/Stdlib/Base/SmartDateTime.php @@ -115,7 +115,7 @@ class SmartDateTime extends \DateTime $yearNew = (int) $this->format('Y') + $y + $yearChange; $monthNew = (int) $this->format('m') + $m; - $monthNew = $monthNew < 0 + $monthNew = $monthNew <= 0 ? 12 + ($monthNew - 1) % 12 + 1 : ($monthNew - 1) % 12 + 1; @@ -445,4 +445,32 @@ class SmartDateTime extends \DateTime return \abs(($mod < 0 ? 12 + $mod : $mod) % 12) + 1; } + + public static function formatDuration(int $duration) : string + { + $days = \floor($duration / (24 * 3600)); + $hours = \floor(($duration % (24 * 3600)) / 3600); + $minutes = \floor(($duration % 3600) / 60); + $seconds = $duration % 60; + + $result = ''; + + if ($days > 0) { + $result .= \sprintf('%02dd', $days); + } + + if ($hours > 0) { + $result .= \sprintf('%02dh', $hours); + } + + if ($minutes > 0) { + $result .= \sprintf('%02dm', $minutes); + } + + if ($seconds > 0) { + $result .= \sprintf('%02ds', $seconds); + } + + return \rtrim($result, ' '); + } } diff --git a/Stdlib/Tree/Node.php b/Stdlib/Tree/Node.php index c75fa510a..7a6730bec 100644 --- a/Stdlib/Tree/Node.php +++ b/Stdlib/Tree/Node.php @@ -111,8 +111,8 @@ class Node { return [ 'key' => $this->key, - 0 => $this->left?->toArray(), - 1 => $this->right?->toArray(), + 0 => $this->left?->toArray(), + 1 => $this->right?->toArray(), ]; } } diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php index 47e0a14a1..7c50a23fd 100755 --- a/System/File/Ftp/Directory.php +++ b/System/File/Ftp/Directory.php @@ -734,9 +734,8 @@ class Directory extends FileAbstract implements DirectoryInterface } $state = $this->copyNode($to, $overwrite); - $state = $state && $this->deleteNode(); - return $state; + return $state && $this->deleteNode(); } /** diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php index 6b4b80630..d8a2bbd51 100755 --- a/System/File/Ftp/File.php +++ b/System/File/Ftp/File.php @@ -549,9 +549,8 @@ class File extends FileAbstract implements FileInterface } $state = $this->copyNode($to, $overwrite); - $state = $state && $this->deleteNode(); - return $state; + return $state && $this->deleteNode(); } /** diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index ad2a8f97d..f7c8b3c33 100755 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -660,9 +660,8 @@ final class Directory extends FileAbstract implements DirectoryInterface public function moveNode(string $to, bool $overwrite = false) : bool { $state = $this->copyNode($to, $overwrite); - $state = $state && $this->deleteNode(); - return $state; + return $state && $this->deleteNode(); } /** diff --git a/System/File/Local/File.php b/System/File/Local/File.php index ce91410e7..9caaabbdd 100755 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -509,9 +509,8 @@ final class File extends FileAbstract implements FileInterface public function moveNode(string $to, bool $overwrite = false) : bool { $state = $this->copyNode($to, $overwrite); - $state = $state && $this->deleteNode(); - return $state; + return $state && $this->deleteNode(); } /** diff --git a/System/SystemUtils.php b/System/SystemUtils.php index d6ea61740..c079aa00a 100755 --- a/System/SystemUtils.php +++ b/System/SystemUtils.php @@ -213,7 +213,6 @@ final class SystemUtils } $status = \proc_close($resource); - if ($status == -1) { throw new \Exception((string) $stderr); } diff --git a/Uri/HttpUri.php b/Uri/HttpUri.php index 7ecb83ebd..22f6a8822 100755 --- a/Uri/HttpUri.php +++ b/Uri/HttpUri.php @@ -383,9 +383,19 @@ final class HttpUri implements UriInterface $this->query = \array_change_key_case($this->query, \CASE_LOWER); } - public function addQuery(string $key, mixed $value = null) + /** + * Add query parameter + * + * @param string $key Parameter key + * @param mixed $value Value (null = omitted) + * + * @return void + * + * @since 1.0.0 + */ + public function addQuery(string $key, mixed $value = null) : void { - $key = \strtolower($key); + $key = \strtolower($key); $this->query[$key] = $value; $toAdd = (empty($this->queryString) ? '?' : '&') diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 8c9770837..f71d6f8b0 100755 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -14,8 +14,6 @@ declare(strict_types=1); namespace phpOMS\Utils; -use phpOMS\Math\Matrix\Exception\InvalidDimensionException; - /** * Array utils. * diff --git a/Utils/Parser/Markdown/Markdown.php b/Utils/Parser/Markdown/Markdown.php index 62f95f9f2..8aac82a46 100755 --- a/Utils/Parser/Markdown/Markdown.php +++ b/Utils/Parser/Markdown/Markdown.php @@ -292,7 +292,7 @@ class Markdown * @since 1.0.0 */ private const CONTINUABLE = [ - 'Code', 'Comment', 'FencedCode', 'List', 'Quote', 'Table', 'Math', 'Spoiler', 'Checkbox', 'Footnote', 'DefinitionList', 'Markup' + 'Code', 'Comment', 'FencedCode', 'List', 'Quote', 'Table', 'Math', 'Spoiler', 'Checkbox', 'Footnote', 'DefinitionList', 'Markup', ]; /** @@ -302,7 +302,7 @@ class Markdown * @since 1.0.0 */ private const COMPLETABLE = [ - 'Math', 'Spoiler', 'Table', 'Checkbox', 'Footnote', 'Markup', 'Code', 'FencedCode', 'List' + 'Math', 'Spoiler', 'Table', 'Checkbox', 'Footnote', 'Markup', 'Code', 'FencedCode', 'List', ]; /** @@ -598,7 +598,7 @@ class Markdown // Add footnotes if (isset($this->definitionData['Footnote'])) { $element = $this->buildFootnoteElement(); - $html .= "\n" . $this->element($element); + $html .= "\n" . $this->element($element); } return $this->decodeToCTagFromHash($html); // Unescape the ToC tag @@ -935,7 +935,7 @@ class Markdown protected function inlineUrl(array $excerpt) : ?array { if (!($this->options['links'] ?? true) - || $this->urlsLinked !== true || !\str_starts_with($excerpt['text'], '://') + || !$this->urlsLinked || !\str_starts_with($excerpt['text'], '://') || \strpos($excerpt['context'], 'http') === false || \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $excerpt['context'], $matches, \PREG_OFFSET_CAPTURE) !== 1 ) { @@ -1276,27 +1276,27 @@ class Markdown return [ 'extent' => \strlen($matches[0]), 'element' => [ - 'name' => 'span', + 'name' => 'span', 'attributes' => [ - 'class' => 'spoiler' + 'class' => 'spoiler', ], 'elements' => [ [ - 'name' => 'input', + 'name' => 'input', 'attributes' => [ - 'type' => 'checkbox' - ] + 'type' => 'checkbox', + ], ], [ 'name' => 'span', 'text' => $matches[1], - ] - ] + ], + ], ], ]; } - /** + /** * Handle keystrokes * * @param array{text:string, context:string, before:string} $excerpt Inline data @@ -1307,7 +1307,7 @@ class Markdown */ protected function inlineKeystrokes(array $excerpt) : ?array { - if (!str_starts_with($excerpt['text'], '[[') + if (!\str_starts_with($excerpt['text'], '[[') || \preg_match('/^(? \preg_replace('/.*\?v=([^\&\]]*).*/', 'https://www.youtube.com/embed/$1', $url), - 'frameborder' => '0', - 'allow' => 'autoplay', + 'src' => \preg_replace('/.*\?v=([^\&\]]*).*/', 'https://www.youtube.com/embed/$1', $url), + 'frameborder' => '0', + 'allow' => 'autoplay', 'allowfullscreen' => '', - 'sandbox' => 'allow-same-origin allow-scripts allow-forms' + 'sandbox' => 'allow-same-origin allow-scripts allow-forms', ]; break; case 'vimeo': - $element = 'iframe'; + $element = 'iframe'; $attributes = [ - 'src' => \preg_replace('/(?:https?:\/\/(?:[\w]{3}\.|player\.)*vimeo\.com(?:[\/\w:]*(?:\/videos)?)?\/([0-9]+)[^\s]*)/', 'https://player.vimeo.com/video/$1', $url), - 'frameborder' => '0', - 'allow' => 'autoplay', + 'src' => \preg_replace('/(?:https?:\/\/(?:[\w]{3}\.|player\.)*vimeo\.com(?:[\/\w:]*(?:\/videos)?)?\/([0-9]+)[^\s]*)/', 'https://player.vimeo.com/video/$1', $url), + 'frameborder' => '0', + 'allow' => 'autoplay', 'allowfullscreen' => '', - 'sandbox' => 'allow-same-origin allow-scripts allow-forms' + 'sandbox' => 'allow-same-origin allow-scripts allow-forms', ]; break; case 'dailymotion': - $element = 'iframe'; + $element = 'iframe'; $attributes = [ - 'src' => $url, - 'frameborder' => '0', - 'allow' => 'autoplay', + 'src' => $url, + 'frameborder' => '0', + 'allow' => 'autoplay', 'allowfullscreen' => '', - 'sandbox' => 'allow-same-origin allow-scripts allow-forms' + 'sandbox' => 'allow-same-origin allow-scripts allow-forms', ]; break; default: $element = 'video'; $attributes = [ - 'src' => UriFactory::build($url), - 'controls' => '' + 'src' => UriFactory::build($url), + 'controls' => '', ]; } return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ - 'name' => $element, - 'text' => $matches[1], - 'attributes' => $attributes + 'name' => $element, + 'text' => $matches[1], + 'attributes' => $attributes, ], ]; } elseif ($audio) { return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ - 'name' => 'audio', - 'text' => $matches[1], + 'name' => 'audio', + 'text' => $matches[1], 'attributes' => [ - 'src' => UriFactory::build($url), - 'controls' => '' - ] + 'src' => UriFactory::build($url), + 'controls' => '', + ], ], ]; } @@ -1448,16 +1448,16 @@ class Markdown } return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ - 'name' => 'div', - 'text' => '', + 'name' => 'div', + 'text' => '', 'attributes' => [ - 'id' => 'i' . \bin2hex(\random_bytes(4)), - 'class' => 'map', + 'id' => 'i' . \bin2hex(\random_bytes(4)), + 'class' => 'map', 'data-lat' => $lat, 'data-lon' => $lon, - ] + ], ], ]; } @@ -1487,7 +1487,7 @@ class Markdown $address = $matches[5]; return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ 'name' => 'div', //'text' => '', @@ -1496,28 +1496,28 @@ class Markdown ], 'elements' => [ [ - 'name' => 'span', - 'text' => $name, + 'name' => 'span', + 'text' => $name, 'attributes' => ['class' => 'addressWidget-name'], ], [ - 'name' => 'span', - 'text' => $address, + 'name' => 'span', + 'text' => $address, 'attributes' => ['class' => 'addressWidget-address'], ], [ - 'name' => 'span', - 'text' => $zip, + 'name' => 'span', + 'text' => $zip, 'attributes' => ['class' => 'addressWidget-zip'], ], [ - 'name' => 'span', - 'text' => $city, + 'name' => 'span', + 'text' => $city, 'attributes' => ['class' => 'addressWidget-city'], ], [ - 'name' => 'span', - 'text' => $country, + 'name' => 'span', + 'text' => $country, 'attributes' => ['class' => 'addressWidget-country'], ], ], @@ -1578,11 +1578,10 @@ class Markdown case 'linkedin': $src = 'Resources/icons/company/linkedin.svg'; break; - } return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ 'name' => 'a', //'text' => '', @@ -1592,17 +1591,17 @@ class Markdown ], 'elements' => [ [ - 'name' => 'img', + 'name' => 'img', 'attributes' => [ 'class' => 'contactWidget-icon', - 'src' => $src + 'src' => $src, ], ], [ - 'name' => 'span', - 'text' => $matches[2], + 'name' => 'span', + 'text' => $matches[2], 'attributes' => ['class' => 'contactWidget-contact'], - ] + ], ], ], @@ -1638,14 +1637,14 @@ class Markdown } return [ - 'extent' => \strlen($matches[0]), + 'extent' => \strlen($matches[0]), 'element' => [ - 'name' => 'progress', - 'text' => '', + 'name' => 'progress', + 'text' => '', 'attributes' => [ 'value' => $value, - 'max' => '100', - ] + 'max' => '100', + ], ], ]; } @@ -1789,7 +1788,7 @@ class Markdown || ($state && !\preg_match('/^(? 2, + 'extent' => 2, 'element' => [ 'rawHtml' => $excerpt['text'][1], ], @@ -1968,7 +1967,7 @@ class Markdown ], ]; - if (preg_match('/[ #]*{(' . $this->regexAttribute . '+)}[ ]*$/', $block['element']['handler']['argument'], $matches, \PREG_OFFSET_CAPTURE)) { + if (\preg_match('/[ #]*{(' . $this->regexAttribute . '+)}[ ]*$/', $block['element']['handler']['argument'], $matches, \PREG_OFFSET_CAPTURE)) { $attributeString = $matches[1][0]; $block['element']['attributes'] = $this->parseAttributeData($attributeString); @@ -2038,8 +2037,7 @@ class Markdown $matches[1] = \substr($matches[1], 0, -$contentIndent); $matches[3] = \str_repeat(' ', $contentIndent) . $matches[3]; - } - elseif ($contentIndent === 0) { + } elseif ($contentIndent === 0) { $matches[1] .= ' '; } @@ -2108,7 +2106,6 @@ class Markdown return null; } - return [ 'element' => [ 'name' => 'blockquote', @@ -2690,7 +2687,7 @@ class Markdown 'element' => [ 'name' => 'details', 'element' => [ - 'text' => '', + 'text' => '', 'elements' => [ [ 'name' => 'summary', @@ -2699,9 +2696,9 @@ class Markdown [ 'name' => 'span', // @todo check if without span possible 'text' => '', - ] + ], ], - ] + ], ], ]; } @@ -3153,8 +3150,12 @@ class Markdown // - [Header3](#Header3) // - [Header2-2](#Header2-2) // ... - $this->contentsListString .= \str_repeat(' ', $this->firstHeadLevel - 1 > $level ? 1 : $level - ($this->firstHeadLevel - 1)) - . ' - ' . '[' . $text . '](#' . $id . ')' . \PHP_EOL; + $this->contentsListString .= \str_repeat( + ' ', + $this->firstHeadLevel - 1 > $level + ? 1 + : $level - ($this->firstHeadLevel - 1) + ) . ' - [' . $text . '](#' . $id . ")\n"; } /** @@ -3179,15 +3180,17 @@ class Markdown $newStr = $str; - if ($count = $this->anchorDuplicates[$str]) { - $newStr .= '-' . $count; + if (($count = $this->anchorDuplicates[$str]) === 0) { + return $newStr; + } - // increment until conversion doesn't produce new duplicates anymore - if (isset($this->anchorDuplicates[$newStr])) { - $newStr = $this->incrementAnchorId($str); - } else { - $this->anchorDuplicates[$newStr] = 0; - } + $newStr .= '-' . $count; + + // increment until conversion doesn't produce new duplicates anymore + if (isset($this->anchorDuplicates[$newStr])) { + $newStr = $this->incrementAnchorId($str); + } else { + $this->anchorDuplicates[$newStr] = 0; } return $newStr; @@ -3491,7 +3494,7 @@ class Markdown 'attributes' => ['href' => '#fn:' . $name, 'class' => 'footnote-ref'], 'text' => $this->definitionData['Footnote'][$name]['number'], ], - ] + ], ]; } @@ -3559,8 +3562,7 @@ class Markdown return $inline; } - foreach ($this->definitionData['Abbreviation'] as $abbreviation => $meaning) - { + foreach ($this->definitionData['Abbreviation'] as $abbreviation => $meaning) { $this->currentAbreviation = $abbreviation; $this->currentMeaning = $meaning; @@ -4725,7 +4727,7 @@ class Markdown /** * Sanitize url in attribute * - * @param array $element Element to sanitize + * @param array $element Element to sanitize * @param string $attribute Attribute to sanitize * * @return array diff --git a/Utils/StringUtils.php b/Utils/StringUtils.php index 1b63a8df1..c36bb6673 100755 --- a/Utils/StringUtils.php +++ b/Utils/StringUtils.php @@ -288,9 +288,7 @@ final class StringUtils } } - $result = \rtrim($result, $delim); - - return $result; + return \rtrim($result, $delim); } /** diff --git a/preload.php b/preload.php index 6f719dcad..9d94e5a8e 100755 --- a/preload.php +++ b/preload.php @@ -4,7 +4,7 @@ * * PHP Version 8.1 * - * @package Karaka + * @package Jingga * @copyright Dennis Eichhorn * @license OMS License 2.0 * @version 1.0.0 diff --git a/tests/Algorithm/Frequency/AprioriTest.php b/tests/Algorithm/Frequency/AprioriTest.php index 7501f6b5a..fe998058b 100644 --- a/tests/Algorithm/Frequency/AprioriTest.php +++ b/tests/Algorithm/Frequency/AprioriTest.php @@ -29,20 +29,20 @@ final class AprioriTest extends \PHPUnit\Framework\TestCase { self::assertEquals( [ - 'theta' => 2, - 'epsilon' => 2, - 'epsilon:theta' => 0, - 'beta' => 4, - 'beta:theta' => 2, - 'beta:epsilon' => 2, - 'beta:epsilon:theta' => 0, - 'alpha' => 4, - 'alpha:theta' => 2, - 'alpha:epsilon' => 2, - 'alpha:epsilon:theta' => 0, - 'alpha:beta' => 4, - 'alpha:beta:theta' => 2, - 'alpha:beta:epsilon' => 2, + 'theta' => 2, + 'epsilon' => 2, + 'epsilon:theta' => 0, + 'beta' => 4, + 'beta:theta' => 2, + 'beta:epsilon' => 2, + 'beta:epsilon:theta' => 0, + 'alpha' => 4, + 'alpha:theta' => 2, + 'alpha:epsilon' => 2, + 'alpha:epsilon:theta' => 0, + 'alpha:beta' => 4, + 'alpha:beta:theta' => 2, + 'alpha:beta:epsilon' => 2, 'alpha:beta:epsilon:theta' => 0, ], Apriori::apriori([ @@ -55,20 +55,20 @@ final class AprioriTest extends \PHPUnit\Framework\TestCase self::assertEquals( [ - '4' => 5, - '3' => 3, - '3:4' => 3, - '2' => 5, - '2:4' => 4, - '2:3' => 2, - '2:3:4' => 2, - '1' => 3, - '1:4' => 2, - '1:3' => 1, - '1:3:4' => 1, - '1:2' => 3, - '1:2:4' => 2, - '1:2:3' => 1, + '4' => 5, + '3' => 3, + '3:4' => 3, + '2' => 5, + '2:4' => 4, + '2:3' => 2, + '2:3:4' => 2, + '1' => 3, + '1:4' => 2, + '1:3' => 1, + '1:3:4' => 1, + '1:2' => 3, + '1:2:4' => 2, + '1:2:3' => 1, '1:2:3:4' => 1, ], Apriori::apriori([ diff --git a/tests/Algorithm/Graph/DependencyResolverTest.php b/tests/Algorithm/Graph/DependencyResolverTest.php index f503f4a0d..eeab355b6 100644 --- a/tests/Algorithm/Graph/DependencyResolverTest.php +++ b/tests/Algorithm/Graph/DependencyResolverTest.php @@ -31,8 +31,7 @@ final class DependencyResolverTest extends \PHPUnit\Framework\TestCase */ public function testResolveCircular() : void { - self::assertEquals( - null, + self::assertNull( DependencyResolver::resolve([0 => [1, 2], 1 => [0, 2], 2 => []]) ); } diff --git a/tests/Application/Testapp/info.json b/tests/Application/Testapp/info.json index d079e1e00..96bc7c4f2 100755 --- a/tests/Application/Testapp/info.json +++ b/tests/Application/Testapp/info.json @@ -14,7 +14,6 @@ "name": "Jingga", "website": "jingga.app" }, - "description": "The administration module.", "directory": "Admin", "providing": { "Navigation": "*", diff --git a/tests/Application/info-test.json b/tests/Application/info-test.json index bb4cc9cba..8b8fe302f 100755 --- a/tests/Application/info-test.json +++ b/tests/Application/info-test.json @@ -14,7 +14,6 @@ "name": "Jingga", "website": "jingga.app" }, - "description": "The administration module.", "directory": "Admin", "providing": { "Navigation": "*" diff --git a/tests/Business/Recommendation/BayesianPersonalizedRankingTest.php b/tests/Business/Recommendation/BayesianPersonalizedRankingTest.php index 880c78a1c..f8ed76a2e 100644 --- a/tests/Business/Recommendation/BayesianPersonalizedRankingTest.php +++ b/tests/Business/Recommendation/BayesianPersonalizedRankingTest.php @@ -14,8 +14,6 @@ declare(strict_types=1); namespace phpOMS\tests\Business\Recommendation; -use phpOMS\Business\Recommendation\BayesianPersonalizedRanking; - /** * @testdox phpOMS\tests\Business\Recommendation\BayesianPersonalizedRankingTest: Article affinity/correlation * diff --git a/tests/DataStorage/Database/TestModel/BaseModelMapper.php b/tests/DataStorage/Database/TestModel/BaseModelMapper.php index 28a735696..6a7030a4d 100755 --- a/tests/DataStorage/Database/TestModel/BaseModelMapper.php +++ b/tests/DataStorage/Database/TestModel/BaseModelMapper.php @@ -25,23 +25,23 @@ class BaseModelMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'test_base_id' => ['name' => 'test_base_id', 'type' => 'int', 'internal' => 'id'], - 'test_base_string' => ['name' => 'test_base_string', 'type' => 'string', 'internal' => 'string', 'autocomplete' => true], + 'test_base_id' => ['name' => 'test_base_id', 'type' => 'int', 'internal' => 'id'], + 'test_base_string' => ['name' => 'test_base_string', 'type' => 'string', 'internal' => 'string', 'autocomplete' => true], 'test_base_compress' => ['name' => 'test_base_compress', 'type' => 'compress', 'internal' => 'compress',], - 'test_base_pstring' => ['name' => 'test_base_pstring', 'type' => 'pstring', 'internal' => 'pstring', 'private' => true], - 'test_base_int' => ['name' => 'test_base_int', 'type' => 'int', 'internal' => 'int'], - 'test_base_bool' => ['name' => 'test_base_bool', 'type' => 'bool', 'internal' => 'bool'], - 'test_base_null' => ['name' => 'test_base_null', 'type' => 'int', 'internal' => 'null'], - 'test_base_float' => ['name' => 'test_base_float', 'type' => 'float', 'internal' => 'float'], - 'test_base_json' => ['name' => 'test_base_json', 'type' => 'Json', 'internal' => 'json'], - 'test_base_json_serializable' => ['name' => 'test_base_json_serializable', 'type' => 'Json', 'internal' => 'jsonSerializable'], - 'test_base_serializable' => ['name' => 'test_base_serializable', 'type' => 'Serializable', 'internal' => 'serializable'], - 'test_base_datetime' => ['name' => 'test_base_datetime', 'type' => 'DateTime', 'internal' => 'datetime'], - 'test_base_datetime_null' => ['name' => 'test_base_datetime_null', 'type' => 'DateTime', 'internal' => 'datetime_null'], - 'test_base_owns_one_self' => ['name' => 'test_base_owns_one_self', 'type' => 'int', 'internal' => 'ownsOneSelf'], - 'test_base_belongs_to_one' => ['name' => 'test_base_belongs_to_one', 'type' => 'int', 'internal' => 'belongsToOne'], - 'test_base_owns_onep_self' => ['name' => 'test_base_owns_onep_self', 'type' => 'int', 'internal' => 'ownsOneSelfPrivate', 'private' => true], - 'test_base_belongs_top_one' => ['name' => 'test_base_belongs_top_one', 'type' => 'int', 'internal' => 'belongsToOnePrivate', 'private' => true], + 'test_base_pstring' => ['name' => 'test_base_pstring', 'type' => 'pstring', 'internal' => 'pstring', 'private' => true], + 'test_base_int' => ['name' => 'test_base_int', 'type' => 'int', 'internal' => 'int'], + 'test_base_bool' => ['name' => 'test_base_bool', 'type' => 'bool', 'internal' => 'bool'], + 'test_base_null' => ['name' => 'test_base_null', 'type' => 'int', 'internal' => 'null'], + 'test_base_float' => ['name' => 'test_base_float', 'type' => 'float', 'internal' => 'float'], + 'test_base_json' => ['name' => 'test_base_json', 'type' => 'Json', 'internal' => 'json'], + 'test_base_json_serializable' => ['name' => 'test_base_json_serializable', 'type' => 'Json', 'internal' => 'jsonSerializable'], + 'test_base_serializable' => ['name' => 'test_base_serializable', 'type' => 'Serializable', 'internal' => 'serializable'], + 'test_base_datetime' => ['name' => 'test_base_datetime', 'type' => 'DateTime', 'internal' => 'datetime'], + 'test_base_datetime_null' => ['name' => 'test_base_datetime_null', 'type' => 'DateTime', 'internal' => 'datetime_null'], + 'test_base_owns_one_self' => ['name' => 'test_base_owns_one_self', 'type' => 'int', 'internal' => 'ownsOneSelf'], + 'test_base_belongs_to_one' => ['name' => 'test_base_belongs_to_one', 'type' => 'int', 'internal' => 'belongsToOne'], + 'test_base_owns_onep_self' => ['name' => 'test_base_owns_onep_self', 'type' => 'int', 'internal' => 'ownsOneSelfPrivate', 'private' => true], + 'test_base_belongs_top_one' => ['name' => 'test_base_belongs_top_one', 'type' => 'int', 'internal' => 'belongsToOnePrivate', 'private' => true], ]; /** @@ -112,7 +112,7 @@ class BaseModelMapper extends DataMapperFactory 'table' => 'test_has_many_rel_relationsp', 'external' => 'test_has_many_rel_relationsp_src', 'self' => 'test_has_many_rel_relationsp_dest', - 'private' => true + 'private' => true, ], ]; diff --git a/tests/Math/Optimization/SimplexTest.php b/tests/Math/Optimization/SimplexTest.php index b4e043149..ca9c1be16 100644 --- a/tests/Math/Optimization/SimplexTest.php +++ b/tests/Math/Optimization/SimplexTest.php @@ -32,7 +32,7 @@ final class SimplexTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta( [ [11.333333, 3.333333, 0.0, 11.666667, 0.0], - 21.333333 + 21.333333, ], $simplex->solve( [ @@ -53,7 +53,7 @@ final class SimplexTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta( [ [1.0, 0.0, 0.0, 0.0], - 5.0 + 5.0, ], $simplex->solve( [ @@ -73,7 +73,7 @@ final class SimplexTest extends \PHPUnit\Framework\TestCase self::assertEquals( [ [-2, -2, -2, -2, -2], - \INF + \INF, ], $simplex->solve( [ @@ -92,7 +92,7 @@ final class SimplexTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta( [ [-1, -1, -1, -1], - \INF + \INF, ], $simplex->solve( [ diff --git a/tests/Message/RequestAbstractTest.php b/tests/Message/RequestAbstractTest.php index ff90f68c0..79c996aa7 100755 --- a/tests/Message/RequestAbstractTest.php +++ b/tests/Message/RequestAbstractTest.php @@ -128,8 +128,8 @@ final class RequestAbstractTest extends \PHPUnit\Framework\TestCase public function testDataBoolInputOutput() : void { $this->request->setData('asdf', 1); - self::assertEquals(true, $this->request->getDataBool('asdf')); - self::assertEquals(true, $this->request->getData('asdf', 'bool')); + self::assertTrue($this->request->getDataBool('asdf')); + self::assertTrue($this->request->getData('asdf', 'bool')); } /** @@ -163,10 +163,10 @@ final class RequestAbstractTest extends \PHPUnit\Framework\TestCase */ public function testInvalidDataTypeInputOutput() : void { - self::assertEquals(null, $this->request->getDataString('a')); - self::assertEquals(null, $this->request->getDataBool('a')); - self::assertEquals(null, $this->request->getDataInt('a')); - self::assertEquals(null, $this->request->getDataFloat('a')); - self::assertEquals(null, $this->request->getDataDateTime('a')); + self::assertNull($this->request->getDataString('a')); + self::assertNull($this->request->getDataBool('a')); + self::assertNull($this->request->getDataInt('a')); + self::assertNull($this->request->getDataFloat('a')); + self::assertNull($this->request->getDataDateTime('a')); } } diff --git a/tests/Message/ResponseAbstractTest.php b/tests/Message/ResponseAbstractTest.php index b5b7bcb83..87530523b 100755 --- a/tests/Message/ResponseAbstractTest.php +++ b/tests/Message/ResponseAbstractTest.php @@ -104,8 +104,8 @@ final class ResponseAbstractTest extends \PHPUnit\Framework\TestCase public function testDataBoolInputOutput() : void { $this->response->set('asdf', 1); - self::assertEquals(true, $this->response->getDataBool('asdf')); - self::assertEquals(true, $this->response->getData('asdf', 'bool')); + self::assertTrue($this->response->getDataBool('asdf')); + self::assertTrue($this->response->getData('asdf', 'bool')); } /** @@ -154,10 +154,10 @@ final class ResponseAbstractTest extends \PHPUnit\Framework\TestCase */ public function testInvalidDataTypeInputOutput() : void { - self::assertEquals(null, $this->response->getDataString('a')); - self::assertEquals(null, $this->response->getDataBool('a')); - self::assertEquals(null, $this->response->getDataInt('a')); - self::assertEquals(null, $this->response->getDataFloat('a')); - self::assertEquals(null, $this->response->getDataDateTime('a')); + self::assertNull($this->response->getDataString('a')); + self::assertNull($this->response->getDataBool('a')); + self::assertNull($this->response->getDataInt('a')); + self::assertNull($this->response->getDataFloat('a')); + self::assertNull($this->response->getDataDateTime('a')); } } diff --git a/tests/Module/info-test.json b/tests/Module/info-test.json index daf851593..92998de85 100755 --- a/tests/Module/info-test.json +++ b/tests/Module/info-test.json @@ -14,7 +14,6 @@ "name": "Jingga", "website": "jingga.app" }, - "description": "The administration module.", "directory": "Admin", "dependencies": [], "providing": { diff --git a/tests/Stdlib/Tree/BinarySearchTreeTest.php b/tests/Stdlib/Tree/BinarySearchTreeTest.php index 8c6d5a6b3..73276be49 100644 --- a/tests/Stdlib/Tree/BinarySearchTreeTest.php +++ b/tests/Stdlib/Tree/BinarySearchTreeTest.php @@ -41,31 +41,31 @@ final class BinarySearchTreeTest extends \PHPUnit\Framework\TestCase self::assertEquals( [ 'key' => 'D', - 0 => [ + 0 => [ 'key' => 'A', - 0 => null, - 1 => null + 0 => null, + 1 => null, ], 1 => [ 'key' => 'I', - 0 => null, - 1 => [ + 0 => null, + 1 => [ 'key' => 'N', - 0 => null, - 1 => [ + 0 => null, + 1 => [ 'key' => 'O', - 0 => null, - 1 => [ + 0 => null, + 1 => [ 'key' => 'S', - 0 => [ + 0 => [ 'key' => 'R', - 0 => null, - 1 => null + 0 => null, + 1 => null, ], 1 => [ 'key' => 'U', - 0 => null, - 1 => null + 0 => null, + 1 => null, ], ], ], @@ -112,32 +112,32 @@ final class BinarySearchTreeTest extends \PHPUnit\Framework\TestCase self::assertEquals( [ 'key' => 'D', - 0 => [ + 0 => [ 'key' => 'A', - 0 => null, - 1 => null + 0 => null, + 1 => null, ], 1 => [ 'key' => 'N', - 0 => null, - 1 => [ + 0 => null, + 1 => [ 'key' => 'O', - 0 => null, - 1 => [ + 0 => null, + 1 => [ 'key' => 'U', - 0 => [ + 0 => [ 'key' => 'R', - 0 => null, - 1 => [ + 0 => null, + 1 => [ 'key' => 'T', - 0 => null, - 1 => null - ] + 0 => null, + 1 => null, + ], ], 1 => [ 'key' => 'Z', - 0 => null, - 1 => null + 0 => null, + 1 => null, ], ], ], diff --git a/tests/Utils/Parser/Document/DocumentWriterTest.php b/tests/Utils/Parser/Document/DocumentWriterTest.php index b447f4164..a6814807c 100644 --- a/tests/Utils/Parser/Document/DocumentWriterTest.php +++ b/tests/Utils/Parser/Document/DocumentWriterTest.php @@ -26,7 +26,7 @@ final class DocumentWriterTest extends \PHPUnit\Framework\TestCase { public function testParsing() : void { - $doc = IOFactory::load(__DIR__ . '/data/Word.docx'); + $doc = IOFactory::load(__DIR__ . '/data/Word.docx'); $writer = new DocumentWriter($doc); $pdf = $writer->toPdfString(__DIR__ . '/data/WordMpdf.pdf'); diff --git a/tests/Utils/Parser/Markdown/MarkdownTest.php b/tests/Utils/Parser/Markdown/MarkdownTest.php index 8a5b1c3a8..50db61079 100755 --- a/tests/Utils/Parser/Markdown/MarkdownTest.php +++ b/tests/Utils/Parser/Markdown/MarkdownTest.php @@ -47,7 +47,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testSafeMode() : void { - $parser = new Markdown(); + $parser = new Markdown(); $parser->safeMode = true; self::assertEquals( @@ -60,8 +60,8 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase { $parser = new Markdown([ 'tables' => [ - 'tablespan' => true - ] + 'tablespan' => true, + ], ]); self::assertEquals( @@ -73,7 +73,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testMap() : void { $parser = new Markdown([ - 'map' => true + 'map' => true, ]); self::assertLessThan(9, @@ -87,7 +87,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testContact() : void { $parser = new Markdown([ - 'contact' => true + 'contact' => true, ]); self::assertEquals( @@ -99,7 +99,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testTypographer() : void { $parser = new Markdown([ - 'typographer' => true + 'typographer' => true, ]); self::assertEquals( @@ -111,7 +111,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testAddress() : void { $parser = new Markdown([ - 'address' => true + 'address' => true, ]); self::assertEquals( @@ -123,7 +123,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testProgress() : void { $parser = new Markdown([ - 'progress' => true + 'progress' => true, ]); self::assertEquals( @@ -135,7 +135,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testEmbed() : void { $parser = new Markdown([ - 'embeding' => true + 'embeding' => true, ]); self::assertEquals( @@ -147,7 +147,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testMath() : void { $parser = new Markdown([ - 'math' => true + 'math' => true, ]); self::assertEquals( @@ -159,7 +159,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testTOC() : void { $parser = new Markdown([ - 'toc' => true + 'toc' => true, ]); $parser->text(\file_get_contents(__DIR__ . '/manualdata/toc.md')); @@ -172,7 +172,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase public function testSpoiler() : void { $parser = new Markdown([ - 'spoiler' => true + 'spoiler' => true, ]); self::assertEquals( diff --git a/tests/Utils/Parser/Presentation/PresentationWriterTest.php b/tests/Utils/Parser/Presentation/PresentationWriterTest.php index 9979dabd7..eb4d87a60 100644 --- a/tests/Utils/Parser/Presentation/PresentationWriterTest.php +++ b/tests/Utils/Parser/Presentation/PresentationWriterTest.php @@ -16,8 +16,8 @@ namespace phpOMS\tests\Utils\Parser\Presentation; include_once __DIR__ . '/../../../Autoloader.php'; -use phpOMS\Utils\Parser\Presentation\PresentationWriter; use PhpOffice\PhpPresentation\IOFactory; +use phpOMS\Utils\Parser\Presentation\PresentationWriter; /** * @internal @@ -31,7 +31,7 @@ final class PresentationWriterTest extends \PHPUnit\Framework\TestCase $writer = new PresentationWriter($presentation); self::assertTrue( - abs(\strlen(\file_get_contents(__DIR__ . '/data/Powerpoint.html')) + \abs(\strlen(\file_get_contents(__DIR__ . '/data/Powerpoint.html')) - \strlen($writer->renderHtml())) < 100 ); } diff --git a/tests/Utils/Parser/Spreadsheet/SpreadsheetWriterTest.php b/tests/Utils/Parser/Spreadsheet/SpreadsheetWriterTest.php index 301e5275a..c8a869868 100644 --- a/tests/Utils/Parser/Spreadsheet/SpreadsheetWriterTest.php +++ b/tests/Utils/Parser/Spreadsheet/SpreadsheetWriterTest.php @@ -26,7 +26,7 @@ final class SpreadsheetWriterTest extends \PHPUnit\Framework\TestCase { public function testParsing() : void { - $sheet = IOFactory::load(__DIR__ . '/data/Excel.xlsx'); + $sheet = IOFactory::load(__DIR__ . '/data/Excel.xlsx'); $writer = new SpreadsheetWriter($sheet); $pdf = $writer->toPdfString(__DIR__ . '/data/ExcelMpdf.pdf');