Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
danolshev committed Aug 1, 2020
2 parents 37fea00 + 6347eea commit 5157706
Show file tree
Hide file tree
Showing 29 changed files with 874 additions and 844 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.5.0] - 2020-08-01
### Added
- It is Mess now 🍺

## [0.4.0] - 2020-08-01
### Removed
- `TypedAccessor` (deprecated, use `Mess` instead)

## [0.3.1] - 2020-08-01
### Added
- `Mess` alias (can be used instead long and boring `TypedAccessor`)
- more tests

## [0.3.0] - 2020-08-01
### Added
- `getObject()`
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- Illogical type casting (`PHP`'s native implementation is way too "smart")
- Pointless casts like `array => float` are **allowed**
- Arrays & boilerplate code to work with them (check if `isset()`, throw an exception, cast the type, etc.)
- Boilerplate code to work with arrays (check if `isset()`, throw an exception, cast the type, etc.)

Consider an example:
```php
Expand All @@ -16,28 +16,32 @@ $userId = (int)$userId;
## Way too verbose. Any ideas?

```php
$userId = (new TypedAccessor($queryParams))['userId']->getAsInt();
$userId = (new Mess($queryParams))['userId']->getAsInt();
```

```bash
$ composer require zakirullin/mess
```

## A few real-world examples

```php
$queryParams = new TypedAccessor(['isDeleted' => 'true']);
$queryParams = new Mess(['isDeleted' => 'true']);
$queryParams['isDeleted']->getBool(); // UnexpectedTypeException
$queryParams['isDeleted']->getAsBool(); // true

$value = new TypedAccessor('25');
$value = new Mess('25');
$value->getInt(); // UnexpectedTypeException
$value->getAsInt(); // 25
$value->getString(); // '25'

$value = new TypedAccessor('abc');
$value = new Mess('abc');
$value->getInt(); // UnexpectedTypeException
$value->getAsInt(); // UncastableValueException
$value->findInt(); // null
$value->findInt() ?? 1; // 1

$config = new TypedAccessor(['param' => '1']);
$config = new Mess(['param' => '1']);
$config['a']['b']->getInt(); // MissingKeyException: "MissingKeyException: a.b"
$config['a']->findInt(); // null
$config['param']->getInt(); // UnexpectedTypeException
Expand Down Expand Up @@ -95,11 +99,9 @@ And that's the worst thing about it. It will continue to work, though, not in a

## The library comes in handy in a variety of scenarios 🚀

Where does mess come from?

- Deserialized data
- Request `body`/`query`
- `API` responses
- etc.

```bash
$ composer require zakirullin/typed-accessor
```
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "zakirullin/typed-accessor",
"name": "zakirullin/mess",
"type": "library",
"description": "Convenient array-related routine & better type casting",
"keywords": [
Expand All @@ -10,7 +10,7 @@
"php",
"json"
],
"homepage": "https://github.com/zakirullin/typed-accessor",
"homepage": "https://github.com/zakirullin/mess",
"license": "MIT",
"authors": [
{
Expand All @@ -31,12 +31,13 @@
},
"autoload": {
"psr-4": {
"Zakirullin\\Mess\\": "src/",
"Zakirullin\\TypedAccessor\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Zakirullin\\TypedAccessor\\Tests\\": "tests/unit"
"Zakirullin\\Mess\\Tests\\": "tests/unit"
}
}
}
4 changes: 2 additions & 2 deletions src/Caster/ArrayOfStringToTypeCaster.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Caster;
namespace Zakirullin\Mess\Caster;

use Zakirullin\TypedAccessor\Finder\ArrayOfStringToMixedFinder;
use Zakirullin\Mess\Finder\ArrayOfStringToMixedFinder;

final class ArrayOfStringToTypeCaster
{
Expand Down
2 changes: 1 addition & 1 deletion src/Caster/BoolCaster.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Caster;
namespace Zakirullin\Mess\Caster;

use function is_bool;

Expand Down
2 changes: 1 addition & 1 deletion src/Caster/IntCaster.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Caster;
namespace Zakirullin\Mess\Caster;

use function filter_var;
use function is_bool;
Expand Down
4 changes: 2 additions & 2 deletions src/Caster/ListOfTypeCaster.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Caster;
namespace Zakirullin\Mess\Caster;

use Zakirullin\TypedAccessor\Finder\ListOfMixedFinder;
use Zakirullin\Mess\Finder\ListOfMixedFinder;

final class ListOfTypeCaster
{
Expand Down
2 changes: 1 addition & 1 deletion src/Caster/StringCaster.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Caster;
namespace Zakirullin\Mess\Caster;

use function is_int;
use function is_string;
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/TypeEnum.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Enum;
namespace Zakirullin\Mess\Enum;

final class TypeEnum
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Exception;
namespace Zakirullin\Mess\Exception;

use RuntimeException;
use Throwable;

final class CannotModifyAccessorException extends RuntimeException implements TypedAccessorExceptionInterface
final class CannotModifyMessException extends RuntimeException implements MessExceptionInterface
{
/**
* @psalm-var list<string|int>
Expand All @@ -25,7 +25,7 @@ public function __construct(array $keySequence, Throwable $previous = null)
{
$this->keySequence = $keySequence;

$message = "TypedAccessor cannot modify it's value";
$message = "Mess cannot modify it's value";

parent::__construct($message, 0, $previous);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Exception;
namespace Zakirullin\Mess\Exception;

interface TypedAccessorExceptionInterface
interface MessExceptionInterface
{
/**
* @psalm-return list<string|int>
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/MissingKeyException.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Exception;
namespace Zakirullin\Mess\Exception;

use RuntimeException;
use Throwable;
use function implode;

final class MissingKeyException extends RuntimeException implements TypedAccessorExceptionInterface
final class MissingKeyException extends RuntimeException implements MessExceptionInterface
{
/**
* @psalm-var list<string|int>
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/UncastableValueException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Exception;
namespace Zakirullin\Mess\Exception;

use RuntimeException;
use Throwable;

final class UncastableValueException extends RuntimeException implements TypedAccessorExceptionInterface
final class UncastableValueException extends RuntimeException implements MessExceptionInterface
{
/**
* @var string
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/UnexpectedKeyTypeException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Exception;
namespace Zakirullin\Mess\Exception;

use RuntimeException;
use Throwable;

final class UnexpectedKeyTypeException extends RuntimeException implements TypedAccessorExceptionInterface
final class UnexpectedKeyTypeException extends RuntimeException implements MessExceptionInterface
{
/**
* @var mixed
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/UnexpectedTypeException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Exception;
namespace Zakirullin\Mess\Exception;

use RuntimeException;
use Throwable;

final class UnexpectedTypeException extends RuntimeException implements TypedAccessorExceptionInterface
final class UnexpectedTypeException extends RuntimeException implements MessExceptionInterface
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Finder/ArrayOfStringToMixedFinder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Finder;
namespace Zakirullin\Mess\Finder;

use function is_array;
use function is_string;
Expand Down
2 changes: 1 addition & 1 deletion src/Finder/ArrayOfStringToTypeFinder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Finder;
namespace Zakirullin\Mess\Finder;

final class ArrayOfStringToTypeFinder
{
Expand Down
2 changes: 1 addition & 1 deletion src/Finder/ListOfMixedFinder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Finder;
namespace Zakirullin\Mess\Finder;

use function array_keys;
use function count;
Expand Down
2 changes: 1 addition & 1 deletion src/Finder/ListOfTypeFinder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Zakirullin\TypedAccessor\Finder;
namespace Zakirullin\Mess\Finder;

final class ListOfTypeFinder
{
Expand Down
Loading

0 comments on commit 5157706

Please sign in to comment.