https://github.com/imponeer/object-errors
  
  
    Library that adds a possibility to collect errors for objects 
    https://github.com/imponeer/object-errors
  
errors hacktoberfest object php-library
        Last synced: 18 days ago 
        JSON representation
    
Library that adds a possibility to collect errors for objects
- Host: GitHub
- URL: https://github.com/imponeer/object-errors
- Owner: imponeer
- License: mit
- Created: 2018-03-11T22:46:38.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2025-10-01T00:02:45.000Z (about 1 month ago)
- Last Synced: 2025-10-01T02:29:18.539Z (about 1 month ago)
- Topics: errors, hacktoberfest, object, php-library
- Language: PHP
- Homepage:
- Size: 146 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
- License: LICENSE
 
Awesome Lists containing this project
README
          [](LICENSE)
[](https://packagist.org/packages/imponeer/object-errors) [](http://php.net)
[](https://packagist.org/packages/imponeer/object-errors)
# Object Errors
A PHP library for collecting and managing errors associated with objects. Useful for tracking validation or processing errors in a structured way.
## Installation
Install via [Composer](https://getcomposer.org):
```bash
composer require imponeer/object-errors
```
Alternatively, you can manually include the files from the `src/` directory.
## Usage
This library allows you to attach an error collection to your objects and manage errors easily.
### Using as a property
Below is a simple usage example by directly creating an `ErrorsCollection` instance:
```php
use Imponeer\ObjectErrors\ErrorsCollection;
class MyObject {
    /**
     * @var ErrorsCollection|null
     */
    public $errors = null;
    public function __construct() {
        $this->errors = new ErrorsCollection();
    }
    public function doSomething() {
        // Example logic
        if ($failed) {
            $this->errors->add("Some error");
        }
    }
    public function render() {
        if ($this->errors->isEmpty()) {
            return 'Everything fine';
        } else {
            return $this->errors->getHtml();
        }
    }
}
```
### Using as a trait
You can also use the provided `ErrorsTrait` to quickly add error handling to your classes:
```php
use Imponeer\ObjectErrors\ErrorsTrait;
class MyObject {
    use ErrorsTrait;
    public function doSomething() {
        if ($failed) {
            $this->setErrors("Some error");
        }
    }
    public function render() {
        if ($this->hasError()) {
            return $this->getHtmlErrors();
        }
        return 'Everything fine';
    }
}
```
## Development
Below are useful commands for development. Each command should be run from the project root directory.
Run tests using PHPUnit:
```bash
composer test
```
Check code style using PHP_CodeSniffer:
```bash
composer phpcs
```
Automatically fix code style issues:
```bash
composer phpcbf
```
Run static analysis using PHPStan:
```bash
composer phpstan
```
## API Documentation
For detailed API documentation, please visit the [Object Errors Wiki](https://github.com/imponeer/object-errors/wiki).
## How to contribute?
Contributions are welcome! If you want to add new features or fix bugs, please fork the repository, make your changes, and submit a pull request.
If you find any bugs or have questions, please use the [issues tab](https://github.com/imponeer/object-errors/issues) to report them or ask questions.