<commit_before># Traitor

A PHP package for automatically adding a `trait use statement` to a given class.

## Installation
Via composer:
```
composer require kkszymanowski/traitor
```

## Usage
- Basic usage:
```
(new TraitUseAdder)->add(FooTrait::class)->to(BarClass:class);
```
- Only generate output without changing files:
```
$handler = new AbstractTreeHandler(file($originalFilePath), FooTrait::class, BarClass::class);

$newContent = $handler->handle()->toString();
```
Note, that `AbstractTreeHandler` accepts input file as an array of lines, such as one produced from `file()` call.

## Behavior
Adding a new trait use statement does not change in any way formatting of your file(or at least it shouldn't).

If the trait is not present in the `use` section below the namespace declaration, it will be also added there, below any existing imports.

If it's not present in the `use` section in the class body, it will be added there below any existing use statements, on it's own line:<commit_msg>Update readme to reflect syntax changes<commit_after># Traitor

A PHP package for automatically adding a `trait use statement` to a given class.

## Installation
Via composer:
```
composer require kkszymanowski/traitor
```

## Usage
- Basic usage:
```
use Traitor\Traitor;

Traitor::addTrait(FooTrait::class)->toClass(FooClass:class);
```
- Add multiple traits:
```
use Traitor\Traitor;

Traitor::addTraits([
    FooTrait::class,
    BarTrait::class,
    BazTrait::class
])->toClass(FooClass:class);
```
- Only generate output without changing files:
```
$handler = new AbstractTreeHandler(file($originalFilePath), FooTrait::class, BarClass::class);

$newContent = $handler->handle()->toString();
```
Note, that `AbstractTreeHandler` accepts input file as an array of lines, such as one produced from `file()` call.

## Behavior
Adding a new trait use statement does not change in any way formatting of your file(or at least it shouldn't).

If the trait is not present in the `use` section below the namespace declaration, it will be also added there, below any existing imports.

If it's not present in the `use` section in the class body, it will be added there below any existing use statements, on it's own line:
{'fraction_non_alphanumeric': 0.10535794687077893, 'fraction_numerical': 0.0, 'mean_word_length': 5.259154929577464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '7070096', 'n_tokens_mistral': 647, 'n_tokens_neox': 611, 'n_words': 273}