Skip to content

Commit 601870d

Browse files
committed
Updated the enums
They are now compatible with PHP 8.2 enum types. Fully tested and working.
1 parent aaed76d commit 601870d

28 files changed

+1441
-1409
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=8.1.0"
15+
"php": ">=8.2.0"
1616
},
1717
"require-dev": {
1818
"ext-ds": "*",

source/LupeTrader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ public static function slowstochrsi(
212212
int $rsi_period = 14,
213213
int $fastK_Period = 5,
214214
int $slowK_Period = 3,
215-
int $slowK_MAType = MovingAverageType::SMA,
215+
int $slowK_MAType = MovingAverageType::SMA->value,
216216
int $slowD_Period = 3,
217-
int $slowD_MAType = MovingAverageType::SMA
217+
int $slowD_MAType = MovingAverageType::SMA->value
218218
): array {
219219
$real = \array_values($real);
220220
$endIdx = count($real) - 1;

source/LupeTraderFriendly.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public static function slowStochasticRelativeStrengthIndex(
2626
int $rsi_period = 14,
2727
int $fastK_Period = 5,
2828
int $slowK_Period = 3,
29-
int $slowK_MAType = MovingAverageType::SMA,
29+
int $slowK_MAType = MovingAverageType::SMA->value,
3030
int $slowD_Period = 3,
31-
int $slowD_MAType = MovingAverageType::SMA
31+
int $slowD_MAType = MovingAverageType::SMA->value
3232
): array {
3333
return LupeTrader::slowstochrsi($real, $rsi_period, $fastK_Period, $slowK_Period, $slowK_MAType, $slowD_Period, $slowD_MAType);
3434
}

source/TALib/Core/Core.php

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* The goal is that this library can be used by those whom cannot install the PHP Trader extension.
88
*
99
* Below is the copyright information for TA-LIB found in the source code.
10-
*/
11-
12-
/* TA-LIB Copyright (c) 1999-2007, Mario Fortier
10+
*
11+
*
12+
* TA-LIB Copyright (c) 1999-2007, Mario Fortier
1313
* All rights reserved.
1414
*
1515
* Redistribution and use in source and binary forms, with or
@@ -63,7 +63,7 @@ class Core
6363
protected static array $unstablePeriod;
6464
/** @var CandleSetting[] */
6565
protected static array $candleSettings;
66-
public static int $compatibility = Compatibility::Default;
66+
public static int $compatibility = Compatibility::Default->value;
6767

6868
/**
6969
* Core constructor.
@@ -74,31 +74,31 @@ public static function construct(): void
7474
{
7575
static::$candleSettings = [
7676
/* real body is long when it's longer than the average of the 10 previous candles' real body */
77-
new CandleSetting(CandleSettingType::BodyLong, RangeType::RealBody, 10, 1.),
77+
new CandleSetting(CandleSettingType::BodyLong->value, RangeType::RealBody->value, 10, 1.),
7878
/* real body is very long when it's longer than 3 times the average of the 10 previous candles' real body */
79-
new CandleSetting(CandleSettingType::BodyVeryLong, RangeType::RealBody, 10, 3.),
79+
new CandleSetting(CandleSettingType::BodyVeryLong->value, RangeType::RealBody->value, 10, 3.),
8080
/* real body is short when it's shorter than the average of the 10 previous candles' real bodies */
81-
new CandleSetting(CandleSettingType::BodyShort, RangeType::RealBody, 10, 1.),
81+
new CandleSetting(CandleSettingType::BodyShort->value, RangeType::RealBody->value, 10, 1.),
8282
/* real body is like doji's body when it's shorter than 10% the average of the 10 previous candles' high-low range */
83-
new CandleSetting(CandleSettingType::BodyDoji, RangeType::HighLow, 10, 0.1),
83+
new CandleSetting(CandleSettingType::BodyDoji->value, RangeType::HighLow->value, 10, 0.1),
8484
/* shadow is long when it's longer than the real body */
85-
new CandleSetting(CandleSettingType::ShadowLong, RangeType::RealBody, 0, 1.),
85+
new CandleSetting(CandleSettingType::ShadowLong->value, RangeType::RealBody->value, 0, 1.),
8686
/* shadow is very long when it's longer than 2 times the real body */
87-
new CandleSetting(CandleSettingType::ShadowVeryLong, RangeType::RealBody, 0, 2.),
87+
new CandleSetting(CandleSettingType::ShadowVeryLong->value, RangeType::RealBody->value, 0, 2.),
8888
/* shadow is short when it's shorter than half the average of the 10 previous candles' sum of shadows */
89-
new CandleSetting(CandleSettingType::ShadowShort, RangeType::Shadows, 10, 1.),
89+
new CandleSetting(CandleSettingType::ShadowShort->value, RangeType::Shadows->value, 10, 1.),
9090
/* shadow is very short when it's shorter than 10% the average of the 10 previous candles' high-low range */
91-
new CandleSetting(CandleSettingType::ShadowVeryShort, RangeType::HighLow, 10, 0.1),
91+
new CandleSetting(CandleSettingType::ShadowVeryShort->value, RangeType::HighLow->value, 10, 0.1),
9292
/* when measuring distance between parts of candles or width of gaps "near" means "<= 20% of the average of the 5 previous candles' high-low range" */
93-
new CandleSetting(CandleSettingType::Near, RangeType::HighLow, 5, 0.2),
93+
new CandleSetting(CandleSettingType::Near->value, RangeType::HighLow->value, 5, 0.2),
9494
/* when measuring distance between parts of candles or width of gaps "far" means ">= 60% of the average of the 5 previous candles' high-low range" */
95-
new CandleSetting(CandleSettingType::Far, RangeType::HighLow, 5, 0.6),
95+
new CandleSetting(CandleSettingType::Far->value, RangeType::HighLow->value, 5, 0.6),
9696
/* when measuring distance between parts of candles or width of gaps "equal" means "<= 5% of the average of the 5 previous candles' high-low range" */
97-
new CandleSetting(CandleSettingType::Equal, RangeType::HighLow, 5, 0.05),
97+
new CandleSetting(CandleSettingType::Equal->value, RangeType::HighLow->value, 5, 0.05),
9898
];
99-
// Changed to correct array size to avoid the "Uncaught ErrorException: Undefined array key 22"
99+
// Changed to correct array size to avoid the "Uncaught ErrorException: Undefined array key 22"
100100
// static::$unstablePeriod = \array_pad([], UnstablePeriodFunctionID::ALL - 2, 0);
101-
static::$unstablePeriod = \array_pad([], UnstablePeriodFunctionID::ALL, 0);
101+
static::$unstablePeriod = \array_pad([], UnstablePeriodFunctionID::ALL->value, 0);
102102
}
103103

104104
public static function setUnstablePeriod(int $functionID, int $unstablePeriod): void
@@ -129,13 +129,13 @@ protected static function double(int $size): array
129129
protected static function validateStartEndIndexes(int $startIdx, int $endIdx): int
130130
{
131131
if ($startIdx < 0) {
132-
return ReturnCode::OutOfRangeStartIndex;
132+
return ReturnCode::OutOfRangeStartIndex->value;
133133
}
134134
if (($endIdx < 0) || ($endIdx < $startIdx)) {
135-
return ReturnCode::OutOfRangeEndIndex;
135+
return ReturnCode::OutOfRangeEndIndex->value;
136136
}
137137

138-
return ReturnCode::Success;
138+
return ReturnCode::Success->value;
139139
}
140140

141141
protected static function TA_INT_PO(
@@ -161,9 +161,9 @@ protected static function TA_INT_PO(
161161
$optInFastPeriod = $tempInteger;
162162
}
163163
$ReturnCode = OverlapStudies::movingAverage($startIdx, $endIdx, $inReal, $optInFastPeriod, $optInMethod_2, $outBegIdx2, $outNbElement2, $tempBuffer);
164-
if ($ReturnCode === ReturnCode::Success) {
164+
if ($ReturnCode === ReturnCode::Success->value) {
165165
$ReturnCode = OverlapStudies::movingAverage($startIdx, $endIdx, $inReal, $optInSlowPeriod, $optInMethod_2, $outBegIdx1, $outNbElement1, $outReal);
166-
if ($ReturnCode === ReturnCode::Success) {
166+
if ($ReturnCode === ReturnCode::Success->value) {
167167
$tempInteger = $outBegIdx1 - $outBegIdx2;
168168
if ($doPercentageOutput) {
169169
for ($i = 0, $j = $tempInteger; $i < $outNbElement1; $i++, $j++) {
@@ -183,7 +183,7 @@ protected static function TA_INT_PO(
183183
$outNBElement = $outNbElement1;
184184
}
185185
}
186-
if ($ReturnCode !== ReturnCode::Success) {
186+
if ($ReturnCode !== ReturnCode::Success->value) {
187187
$outBegIdx = 0;
188188
$outNBElement = 0;
189189
}
@@ -242,21 +242,21 @@ protected static function TA_INT_MACD(
242242
$outBegIdx = 0;
243243
$outNBElement = 0;
244244

245-
return ReturnCode::Success;
245+
return ReturnCode::Success->value;
246246
}
247247
$tempInteger = ($endIdx - $startIdx) + 1 + $lookbackSignal;
248248
$fastEMABuffer = static::double($tempInteger);
249249
$slowEMABuffer = static::double($tempInteger);
250250
$tempInteger = $startIdx - $lookbackSignal;
251251
$ReturnCode = static::TA_INT_EMA($tempInteger, $endIdx, $inReal, $optInSlowPeriod, $k1, $outBegIdx1, $outNbElement1, $slowEMABuffer);
252-
if ($ReturnCode !== ReturnCode::Success) {
252+
if ($ReturnCode !== ReturnCode::Success->value) {
253253
$outBegIdx = 0;
254254
$outNBElement = 0;
255255

256256
return $ReturnCode;
257257
}
258258
$ReturnCode = static::TA_INT_EMA($tempInteger, $endIdx, $inReal, $optInFastPeriod, $k2, $outBegIdx2, $outNbElement2, $fastEMABuffer);
259-
if ($ReturnCode !== ReturnCode::Success) {
259+
if ($ReturnCode !== ReturnCode::Success->value) {
260260
$outBegIdx = 0;
261261
$outNBElement = 0;
262262

@@ -269,15 +269,15 @@ protected static function TA_INT_MACD(
269269
$outBegIdx = 0;
270270
$outNBElement = 0;
271271

272-
return (ReturnCode::InternalError);
272+
return ReturnCode::InternalError->value;
273273
}
274274
for ($i = 0; $i < $outNbElement1; $i++) {
275275
$fastEMABuffer[$i] -= $slowEMABuffer[$i];
276276
}
277277
//System::arraycopy($fastEMABuffer, $lookbackSignal, $outMACD, 0, ($endIdx - $startIdx) + 1);
278278
$outMACD = \array_slice($fastEMABuffer, $lookbackSignal, ($endIdx - $startIdx) + 1);
279279
$ReturnCode = static::TA_INT_EMA(0, $outNbElement1 - 1, $fastEMABuffer, $optInSignalPeriod_2, (2.0 / ((double)($optInSignalPeriod_2 + 1))), $outBegIdx2, $outNbElement2, $outMACDSignal);
280-
if ($ReturnCode !== ReturnCode::Success) {
280+
if ($ReturnCode !== ReturnCode::Success->value) {
281281
$outBegIdx = 0;
282282
$outNBElement = 0;
283283

@@ -289,7 +289,7 @@ protected static function TA_INT_MACD(
289289
$outBegIdx = $startIdx;
290290
$outNBElement = $outNbElement2;
291291

292-
return ReturnCode::Success;
292+
return ReturnCode::Success->value;
293293
}
294294

295295
protected static function TA_INT_EMA(int $startIdx, int $endIdx, $inReal, int $optInTimePeriod, float $optInK_1, int &$outBegIdx, int &$outNBElement, array &$outReal): int
@@ -304,10 +304,10 @@ protected static function TA_INT_EMA(int $startIdx, int $endIdx, $inReal, int $o
304304
$outBegIdx = 0;
305305
$outNBElement = 0;
306306

307-
return ReturnCode::Success;
307+
return ReturnCode::Success->value;
308308
}
309309
$outBegIdx = $startIdx;
310-
if ((static::$compatibility) === Compatibility::Default) {
310+
if ((static::$compatibility) === Compatibility::Default->value) {
311311
$today = $startIdx - $lookbackTotal;
312312
$i = $optInTimePeriod;
313313
$tempReal = 0.0;
@@ -330,7 +330,7 @@ protected static function TA_INT_EMA(int $startIdx, int $endIdx, $inReal, int $o
330330
}
331331
$outNBElement = $outIdx;
332332

333-
return ReturnCode::Success;
333+
return ReturnCode::Success->value;
334334
}
335335

336336
protected static function TA_INT_SMA(int $startIdx, int $endIdx, array $inReal, int $optInTimePeriod, int &$outBegIdx, int &$outNBElement, array &$outReal): int
@@ -345,7 +345,7 @@ protected static function TA_INT_SMA(int $startIdx, int $endIdx, array $inReal,
345345
$outBegIdx = 0;
346346
$outNBElement = 0;
347347

348-
return ReturnCode::Success;
348+
return ReturnCode::Success->value;
349349
}
350350
$periodTotal = 0;
351351
$trailingIdx = $startIdx - $lookbackTotal;
@@ -365,7 +365,7 @@ protected static function TA_INT_SMA(int $startIdx, int $endIdx, array $inReal,
365365
$outNBElement = $outIdx;
366366
$outBegIdx = $startIdx;
367367

368-
return ReturnCode::Success;
368+
return ReturnCode::Success->value;
369369
}
370370

371371
protected static function TA_INT_stddev_using_precalc_ma(array $inReal, array $inMovAvg, int $inMovAvgBegIdx, int $inMovAvgNbElement, int $timePeriod, array &$output): int
@@ -399,7 +399,7 @@ protected static function TA_INT_stddev_using_precalc_ma(array $inReal, array $i
399399
}
400400
}
401401

402-
return ReturnCode::Success;
402+
return ReturnCode::Success->value;
403403
}
404404

405405
protected static function TA_INT_VAR(int $startIdx, int $endIdx, array $inReal, int $optInTimePeriod, int &$outBegIdx, int &$outNBElement, array &$outReal): int
@@ -414,7 +414,7 @@ protected static function TA_INT_VAR(int $startIdx, int $endIdx, array $inReal,
414414
$outBegIdx = 0;
415415
$outNBElement = 0;
416416

417-
return ReturnCode::Success;
417+
return ReturnCode::Success->value;
418418
}
419419
$periodTotal1 = 0;
420420
$periodTotal2 = 0;
@@ -445,6 +445,6 @@ protected static function TA_INT_VAR(int $startIdx, int $endIdx, array $inReal,
445445
$outNBElement = $outIdx;
446446
$outBegIdx = $startIdx;
447447

448-
return ReturnCode::Success;
448+
return ReturnCode::Success->value;
449449
}
450450
}

0 commit comments

Comments
 (0)