Commit graph

75 commits

Author SHA1 Message Date
Bruce Wells
1b8d71d953
Php unit10 (#124)
* Static PHPUnit providers
* Limit PHP upgrades till new PHP version is tested
* Upgrade PHPUnit config schema
2023-03-21 11:10:06 -04:00
Fatih Kızmaz
3a18c7d47f
Added Not(!) logical operator and median function with tests. (#121) 2022-12-26 10:35:27 -05:00
Bruce Wells
7704ba918f
Drop php74 (#120)
* PHPStan Level 6

* Drop PHP 7.4 support

* Add PHPStan badge to readme

* Code style cleanup
2022-12-21 18:52:18 -05:00
Bruce Wells
c59f4cd153
Php8.2 (#119)
* PHP 8.2 Support
* Code style fixes
* Specify precision of 16 for tests
* Remove PHPStan testing due to PHP version differences
* Update actions to latest versions
* Updated tests to avoid hard coded values
* Enhanced error reporting for tests
2022-12-08 11:15:34 -05:00
madman-81
9538001a42
Throw an IncorrectNumberOfFunctionParametersException if a function gets more arguments than it supports (#117)
* Throw an IncorrectNumberOfFunctionParametersException if a function gets more arguments than it supports

* Update CustomFunction.php

Code Style

Co-authored-by: Bruce Wells <brucekwells@gmail.com>
2022-08-04 08:07:41 -04:00
Bruce Wells
a944fe4e56
Bcmath (#115)
* Add useBCMath

* Support for % operator (mod)
2022-06-01 18:11:51 -04:00
Bruce Wells
cbada2b920
Space should end open numbers (#113) 2022-05-28 16:02:04 -04:00
Fatih Kızmaz
3e6700d157
Added ability to escape quotes in strings. (#110)
* Added ability to escape quotes in strings.

* Removed type checking for customfunc arguments. It was a bad idea to check types, because php automatically tries to convert a parameter to required type and throws if it failures. On the other hand, we can check types also in callables if required.

* Update phpdoc

* Fix some typos + improve min, max, avg funcs.

* Update readme + improvements.

* Fix a typo in sample.

* Fix unshown backslash in readme.
2022-05-18 22:03:44 -04:00
Fatih Kızmaz
5d6b4a5dfd
Full support for arrays => min, max and avg funcs accept array argument. Also array function is defined which return arguments as array. Square bracket arrays are also supported. (#108)
valid expression -> "max([1,2,3])"
valid expression -> "max(array(1,2,3))"
valid expression -> "max($ages_arr)"
valid expression -> "max(ages_arr())"
2022-05-16 17:57:37 -04:00
Fatih Kızmaz
2874b11341
Small support for arrays => min, max and avg funcs accept array argument. (handwritten arrays not supported yet, can be used for array variables or functions returning an array) (#107)
invalid expression -> "max([1,2,3])"
valid expression -> "max($ages_arr)"
valid expression -> "max(ages_arr())"
2022-05-16 11:12:36 -04:00
Fatih Kızmaz
e21d59c9de
Support unlimited args for min, max default funcs. (#106)
* Support unlimited args for min, max default funcs.

Default functions max and min were requiring 2 arguments strictly. Now they supoort unlimited args, same as php's min, max funcs.

* Improved functions: support unlimited parameters (see min, max funcs), optional parameters (see round func), parameters with types (see round func, throws IncorrectFunctionParameterException on unmatched type, union types and intersection types not supported because of min php level! there is a todo for this, to support them later @see CustomFunction@execute) Also added unittests for improvements.

* Run php-cs-fixer fix
2022-05-13 08:55:52 -04:00
Javier Marín
645f1dfbc6
Two more tests + some code refactoring (#104)
* test: add testNullReturnType and testUnsupportedOperands

* refactor: fix PhpDoc comments and use PHP 7.4 arrow functions

* refactor: fix PHP-CS-Fixer issues

* test: run testUnsupportedOperands() only on PHP8+

Co-authored-by: Javier Marín <contacto@ideatic.net>
2022-05-09 14:13:30 -04:00
Bruce Wells
b7b46bfc47
Phpcs fixer (#103)
* Configuring PHP CS Fixer

Dropping PHP 7,3 support

* Fixing merge issue
2022-04-26 17:31:50 -04:00
Bruce Wells
c396a882ff
Prep for V2.2.0 release (#99) 2022-04-26 16:14:59 -04:00
Matthijs Meulenbrug
ef82911187
Add a custom variable validator + protected props (#98) 2022-04-25 10:50:51 -04:00
Bruce Wells
a0ff7a79af
Adding varExists method and support for undefined var handler in getVar (#96)
* Added varExists method

* getVar now respects VarNotFoundHandler setting

* Use local version of PHP-CS-Fixer

Instead of hard coded version from github actions

* Fixing actions

* Fixing actions

* Dropping testing for 7.3, as it is no longer supported
2022-03-21 12:52:25 -04:00
Javier Marín
20f8cabf10 fix: broken support for positive exponent numbers 2022-01-05 09:53:06 +01:00
Javier Marín
d1d27b494d
PhpStan support, consts visibilty and name for tokens (#89)
* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic

* Better support for null variables

* Better support for null variables

* Better support for null variables

* Allow null values in `setVar` method

* Support for unary positive operator

* Add PhpStan config file
Fix PhpStan warnings
Set consts visibility
Add name info to variable tokens for easier debugging

Co-authored-by: Javier Marín <contacto@ideatic.net>
2021-07-13 22:12:41 -04:00
Bruce Wells
aa37abbaeb
Release prep (#86) 2021-03-04 20:08:57 -05:00
Bruce Wells
16dde01158
Merge branch 'master' into master 2021-03-04 19:47:04 -05:00
Javier Marín
d99491c1f4
Support for unary positive expressions (#85)
* Support for unary positive operator
2021-03-04 19:42:01 -05:00
Bruce Wells
17cc5b9dc4
Unary Minus (#84)
Fixed unary minus to allow a minus sign in front of functions and parentheses.
2021-02-16 22:13:44 -05:00
Chun-Sheng, Li
936ee5caca
Improve autoloading, asssertions and CI trigger (#79) 2021-01-05 19:07:33 -05:00
Mirosław Sztorc
a4b0fac121
Cache-control improvements (#81)
* cache-control improvements

* Update src/NXP/MathExecutor.php

yeah, you're right.

Co-authored-by: Alexander Kiryukhin <a.kiryukhin@mail.ru>

* Update MathExecutor.php

braces qfix

* Update MathExecutor.php

Co-authored-by: Alexander Kiryukhin <a.kiryukhin@mail.ru>
2021-01-05 19:06:04 -05:00
Bruce Wells
761ac50344
Additional tests Hacktoberfest (#77)
* Additional tests

Co-authored-by: diman3210 <diman-3210@mail.ru>
2020-10-19 19:25:48 -04:00
diman3210
e28c1bf9e7
add new functions and aliases to the old functions (#76)
* add new functions and aliases to the old functions

* add tests for new functions
2020-10-19 18:48:30 -04:00
Bruce Wells
d9eb39e38d
Improved unit tests (#74)
* Variable fixes (#67)

* Reproduce if throws UnknownOperatorException

* Fix variable detection

* Adding IncorrectNumberOfFunctionParametersException

* Removing tabs

* Better exception message text

* Handler for not found variables (#68)

* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic

* Release prep (#69)

* String comparison unit tests

* getVars and getFunctions sanity checks

* Add dynamic variable documentation

* Better setVar error message (#70)

Additional unit tests
Readme update

* Improved support for null variables (#72)

* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic

* Better support for null variables

* Better support for null variables

* Better support for null variables

* Allow null values in `setVar` method (#73)

* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic

* Better support for null variables

* Better support for null variables

* Better support for null variables

* Allow null values in `setVar` method

* Better unit testing

Co-authored-by: Javier Marín <javier@marinros.com>
2020-09-15 21:27:43 -04:00
Bruce Wells
71eda0b535 Better unit testing 2020-09-15 21:24:02 -04:00
Javier Marín
8fc77e54e0 Improved support for null variables (#72)
* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic

* Better support for null variables

* Better support for null variables

* Better support for null variables
2020-09-15 21:14:44 -04:00
Bruce Wells
8a2cae984f Better setVar error message (#70)
Additional unit tests
Readme update
2020-09-15 21:14:44 -04:00
Bruce Wells
92d1a4524b Release prep (#69)
* String comparison unit tests

* getVars and getFunctions sanity checks

* Add dynamic variable documentation
2020-09-15 21:14:44 -04:00
Javier Marín
462d6e4ddc Handler for not found variables (#68)
* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic
2020-09-15 21:14:44 -04:00
Bruce Wells
a0e0f405a9 Variable fixes (#67)
* Reproduce if throws UnknownOperatorException

* Fix variable detection

* Adding IncorrectNumberOfFunctionParametersException

* Removing tabs

* Better exception message text
2020-09-15 21:14:44 -04:00
Javier Marín
f8faf3fa8d
Improved support for null variables (#72)
* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic

* Better support for null variables

* Better support for null variables

* Better support for null variables
2020-09-14 20:47:26 -04:00
Bruce Wells
44d72cc252
Better setVar error message (#70)
Additional unit tests
Readme update
2020-07-27 12:25:59 -04:00
Bruce Wells
b38893d672
Release prep (#69)
* String comparison unit tests

* getVars and getFunctions sanity checks

* Add dynamic variable documentation
2020-07-26 22:14:51 -04:00
Javier Marín
c1e07f254a
Handler for not found variables (#68)
* Added handler to define not found variables
Added support for string variables
Fixed strings and ints comparison error

* Check if variables have scalar types (int, float, string and bool)
Better $onVarNotFound logic
2020-07-25 22:27:26 -04:00
Bruce Wells
aa8ffe19f2
Variable fixes (#67)
* Reproduce if throws UnknownOperatorException

* Fix variable detection

* Adding IncorrectNumberOfFunctionParametersException

* Removing tabs

* Better exception message text
2020-06-04 11:43:16 -04:00
Alexander Kiryukhin
ea898d7a7b
Code style fixes & Github Actions (#65)
* Code style fixes

Up phpunit to v8
New CI

* Remove travis

* Fix CI badge

* Added php-cs-fixer action
2020-05-31 20:50:39 -04:00
Bruce Wells
b95ab24f36 setDivisionByZeroIsZero 2020-05-19 22:36:55 -04:00
Alexander Kiryukhin
cab8e2d38a Massive refactoring
More clean structure
Parsing without regular expressions
2020-05-15 21:51:23 +03:00
Bruce Wells
4d50343330
Negative expression start (#60)
* Update documentation for PHPFUI/InstaDoc

* Support for negative numbers starting paren enclosed expressions
2020-04-21 11:12:55 -04:00
Bruce Wells
4955c639e1
PHP 7.4 support (#57)
* Merge in neonxp master (#9)

* Version 1.1 (#51)

* Update README.md and more function support

* Removing phpunit symbolic link (#53)

* Left bracket and minus fix (#55)

* Left bracket and minus fix (#54)

* Add test for left bracket and minus fix #55

* Fix substraction by zero bug (#56)

Co-authored-by: franksl <info@streamlake.com>
Co-authored-by: Clément Lafont <johnrazeur@gmail.com>

* Docs and test updates

* Update composer

Co-authored-by: franksl <info@streamlake.com>
Co-authored-by: Clément Lafont <johnrazeur@gmail.com>
2020-02-07 17:45:33 -05:00
Bruce Wells
0eeed45566
Merge branch 'master' into master 2020-02-07 12:27:48 -05:00
Clément Lafont
43790a456e
Fix substraction by zero bug (#56) 2020-02-07 11:05:26 -05:00
Clément Lafont
707e22029d Left bracket and minus fix (#55)
* Left bracket and minus fix (#54)

* Add test for left bracket and minus fix #55
2020-01-13 12:09:18 -05:00
Bruce Wells
2db48eff95 PHP 7.4 support 2019-11-30 18:47:04 -05:00
Bruce Wells
f240380438
Version 1.1 (#51)
* Update README.md and more function support
2019-11-27 12:39:25 -05:00
Bruce Wells
84f3f967b7 Update README.md and more function support 2019-11-27 12:33:50 -05:00
franksl
29c5b5006c Logicandcompare (#50)
* TokenFactory: allowing multicharacter tokens

* Added logical and compare operators: <, <=, >, >=, ==, !=, ||, &&

* Fixed operator priorities

* Error messages fixes

* Fixed operators priority

The priorities are assigned by following the php language standard
(https://www.php.net/manual/en/language.operators.precedence.php)
I've assigned precedence in steps of 10 units by following the linked page:
230 clone new
220 **
210 ++ -- ~ (int) (float) (string) (array) (object) (bool) @
200 instanceof
190 !
180 * / %
170 + - .
160 << >>
150 < <= > >=
140 == != === !== <> <=>
130 &
120 ^
110 |
100 &&
 90 ||
 80 ??
 70 ? :
 60 = += -= *= **= /= .= %= &= |= ^= <<= >>=
 50 yield from
 40 yield
 30 and
 20 xor
 10 or

* Added if() function

* Cache key fix

There are cases where the cache key creation raised an error, for example
while evaluating the expression "if(cos(2), cos(2), 0)", because the
if() function was passing a float to the MathExecutor:execute() method.
2019-11-26 09:00:24 -05:00