An open API service indexing awesome lists of open source software.

https://github.com/voku/value_objects


https://github.com/voku/value_objects

Last synced: 5 months ago
JSON representation

Awesome Lists containing this project

README

          

[//]: # (AUTO-GENERATED BY "PHP README Helper": base file -> docs/base.md)
[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)

[![Build Status](https://github.com/voku/value_objects/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/voku/value_objects/actions)
[![codecov.io](http://codecov.io/github/voku/value_objects/coverage.svg?branch=main)](http://codecov.io/github/voku/value_objects?branch=main)

# Value Objects

A collection of value objects that can help you to write more readable,
self-validated and immutable code.

### Install with Composer

```shell
composer require voku/value_objects
```

### Usage

```php
use voku\ValueObjects\ValueObjectVatPercentage;

require_once __DIR__ . '/vendor/autoload.php'; // example path

$vat = ValueObjectVatPercentage::create('16.0');

$vat->getGross(10.0)); // '11.6'
```

### Unit Tests

1) [Composer](https://getcomposer.org) is a prerequisite for running the tests.

```shell
composer install
```

2) The tests can be executed by running this command from the root directory.

```shell
./vendor/bin/phpunit
```

## AbstractHttpProvider methods

create
createEmpty
decryptFromString
encrypt
jsonSerialize
value
valueOrFallback
valueOrThrowException

## create(\TCreateValue|null $value): static

**Parameters:**
- `\TCreateValue|null $value`

**Return:**
- `static`

--------

## createEmpty(): static

**Parameters:**
__nothing__

**Return:**
- `static`

--------

## decryptFromString(string $password, string $data): static

**Parameters:**
- `string $password`
- `string $data`

**Return:**
- `static`

--------

## encrypt(string $password):

**Parameters:**
- `string $password`

**Return:**
- `string`

--------

## jsonSerialize(): string

**Parameters:**
__nothing__

**Return:**
- `string`

--------

## value(): TValue|null

Get the value that are used for the database.

**Parameters:**
__nothing__

**Return:**
- `\TValue|null`

--------

## valueOrFallback(\TValueFallback $fallback): TValue|\TValueFallback

**Parameters:**
- `\TValueFallback $fallback`

**Return:**
- `\TValue|\TValueFallback`

--------

## valueOrThrowException(): TValue

**Parameters:**
__nothing__

**Return:**
- `\TValue`

--------

### Thanks

- Thanks to [GitHub](https://github.com) (Microsoft) for hosting the code and a good infrastructure including Issues-Management, etc.
- Thanks to [IntelliJ](https://www.jetbrains.com) as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to [StyleCI](https://styleci.io/) for the simple but powerful code style check.
- Thanks to [PHPStan](https://github.com/phpstan/phpstan) && [Psalm](https://github.com/vimeo/psalm) for really great Static analysis tools and for discover bugs in the code!