Skip to content

Simple checker for check expression on correct brackets

License

Notifications You must be signed in to change notification settings

pusachev/brackets-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MageKeeper BracketsChecker

Simple checker for check expression on correct brackets

Requirements

  • PHP 7.0 or above
  • Command line interface

Installation Instructions

  • If you do not have Composer yet, download it and follow the instructions on http://getcomposer.org/ website or simply run the following command:
curl -s https://getcomposer.org/installer | php
git clone https://github.com/pusachev/brackets-checker.git
  • Install project dependencies with Composer. If the installation process is too slow, you can use the "--prefer-dist" option. Run composer installation:
php composer.phar install --prefer-dist

Usage

For use console command and check expression like "(12 + 5) * 2" please run

php bin/console magekeeper:brackects-checker:check "(12 + 5) * 2"

Usage in code

If by any chance you are not already including the autoload generated by composer, do not forget to add:

require __DIR__ . '/vendor/autoload.php';

Validator example

use MageKeeper\BracketsChecker\Validator\BracketsValidator;

$expression = '(100 - 20) / 2';

/** @var MageKeeper\BracketsChecker\Validator\BracketsValidatorInterface $validator */
$validator = new BracketsValidator();

if($validator->validate($expression)) {
    //do something if valid
} else {
    //do something if invalid
}

If you need added custom brackets like "#", please usage next method:

/** @var MageKeeper\BracketsChecker\Validator\CustomBracketsInterface $validator */
$validator->addBrackets('#', '#')

Unit Tests

For run unit tests please run this command:

php bin/phpunit

About

Simple checker for check expression on correct brackets

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages