<commit_before># PHP Condition library

This library allows to build complex conditions connected with AND/OR statements with subconditions support and then check them in some context.

## Usage

### Getting objects

#### Building conditions
Let's say we want to match books that are hard to read or those ones with titles longer than 50 characters:
```php
$wiseBookCondition = (new ConditionComposite())
    ->addOR(new Difficulty(Difficulty::HARD))
    ->addOR(new TitleOfMoreCharsThan(50));
```
Or easy books with short titles for children:
```php
$booksForChildrenCondition = (new ConditionComposite())
    ->addAND(new Difficulty(Difficulty::EASY))
    ->addAND((new TitleOfMoreCharsThan(15))->negate());
```
Or those with really long titles:
```php
$titleLogerThan99Condition = new TitleOfMoreCharsThan(99);
```

#### Building context
An easy to read book with a long title:
```php
$easyBookWithLongTitle = (new Book())
    ->setTitle("A really long title of some book that must be wise.")
    ->markAsEasy();
```
A hard to read book with short title:
```php
$hardBookWithShortTitle = (new Book())
    ->markAsHard()
    ->setTitle("How?");
```
An easy to read book with a short title:
```php
$easyBookWithShortTitle = (new Book())
    ->markAsEasy()
    ->setTitle("Cats");
```
### Checking
#### Is a condition true?
Is this book wise?
```php
$wiseBookCondition->isTrueIn($easyBookWithLongTitle), //true
$wiseBookCondition->isTrueIn($hardBookWithShortTitle), //true
$wiseBookCondition->isTrueIn($easyBookWithShortTitle), //false
```
Is it for children?
```php
$booksForChildrenCondition->isTrueIn($easyBookWithLongTitle), //false
$booksForChildrenCondition->isTrueIn($hardBookWithShortTitle), //false
$booksForChildrenCondition->isTrueIn($easyBookWithShortTitle), //true
```
Is the title longer than 99 characters?
```php
$titleLogerThan99Condition->isTrueIn($easyBookWithLongTitle), //false
$titleLogerThan99Condition->isTrueIn($hardBookWithShortTitle), //false
$titleLogerThan99Condition->isTrueIn($easyBookWithShortTitle) //false
```

#### Does intersection exist between two conditions?
A title of a wise book may be longer than 99 characters.
```php
/* @var $intersectDetector IntersectDetector */
$intersectDetector->intersectExists(
    $wiseBookCondition,
    $titleLogerThan99Condition
), //true
```
But books for children have no titles that long.
```php
/* @var $intersectDetector IntersectDetector */
$intersectDetector->intersectExists(
    $booksForChildrenCondition,
    $titleLogerThan99Condition
) //false
```

#### Are two conditions equal?
Two condition objects may be equal.
```php
/* @var $comparator EqualityComparator */
$comparator->equal(
    $titleLogerThan99Condition,
    new TitleOfMoreCharsThan(99)
) //true
```
## Installation
Use [composer](https://getcomposer.org) to get the latest version:
```
$ composer require lukaszmakuch/lmcondition<commit_msg>fixing readme<commit_after># PHP Condition library

This library allows to build complex conditions connected with AND/OR statements with subconditions support and then check them in some context.

## Usage

### Getting objects

#### Building conditions
Let's say we want to match books that are hard to read or those ones with titles longer than 50 characters:
```php
$wiseBookCondition = (new ConditionComposite())
    ->addOR(new Difficulty(Difficulty::HARD))
    ->addOR(new TitleOfMoreCharsThan(50));
```
Or easy books with short titles for children:
```php
$booksForChildrenCondition = (new ConditionComposite())
    ->addAND(new Difficulty(Difficulty::EASY))
    ->addAND((new TitleOfMoreCharsThan(15))->negate());
```
Or those with really long titles:
```php
$titleLogerThan99Condition = new TitleOfMoreCharsThan(99);
```

#### Building context
An easy to read book with a long title:
```php
$easyBookWithLongTitle = (new Book())
    ->setTitle("A really long title of some book that must be wise.")
    ->markAsEasy();
```
A hard to read book with short title:
```php
$hardBookWithShortTitle = (new Book())
    ->markAsHard()
    ->setTitle("How?");
```
An easy to read book with a short title:
```php
$easyBookWithShortTitle = (new Book())
    ->markAsEasy()
    ->setTitle("Cats");
```
### Checking
#### Is a condition true?
Is this book wise?
```php
$wiseBookCondition->isTrueIn($easyBookWithLongTitle); //true
$wiseBookCondition->isTrueIn($hardBookWithShortTitle); //true
$wiseBookCondition->isTrueIn($easyBookWithShortTitle); //false
```
Is it for children?
```php
$booksForChildrenCondition->isTrueIn($easyBookWithLongTitle); //false
$booksForChildrenCondition->isTrueIn($hardBookWithShortTitle); //false
$booksForChildrenCondition->isTrueIn($easyBookWithShortTitle); //true
```
Is the title longer than 99 characters?
```php
$titleLogerThan99Condition->isTrueIn($easyBookWithLongTitle); //false
$titleLogerThan99Condition->isTrueIn($hardBookWithShortTitle); //false
$titleLogerThan99Condition->isTrueIn($easyBookWithShortTitle);//false
```

#### Does intersection exist between two conditions?
A title of a wise book may be longer than 99 characters.
```php
/* @var $intersectDetector IntersectDetector */
$intersectDetector->intersectExists(
    $wiseBookCondition,
    $titleLogerThan99Condition
); //true
```
But books for children have no titles that long.
```php
/* @var $intersectDetector IntersectDetector */
$intersectDetector->intersectExists(
    $booksForChildrenCondition,
    $titleLogerThan99Condition
); //false
```

#### Are two conditions equal?
Two condition objects may be equal.
```php
/* @var $comparator EqualityComparator */
$comparator->equal(
    $titleLogerThan99Condition,
    new TitleOfMoreCharsThan(99)
); //true
```
## Installation
Use [composer](https://getcomposer.org) to get the latest version:
```
$ composer require lukaszmakuch/lmcondition
{'fraction_non_alphanumeric': 0.12984094052558784, 'fraction_numerical': 0.009681881051175657, 'mean_word_length': 5.781946072684643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5744000', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1667, 'n_words': 509}