Skip to content

Commit

Permalink
Pint
Browse files Browse the repository at this point in the history
  • Loading branch information
antoninmasek committed Sep 4, 2024
1 parent ef8eb8a commit cc6ec24
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 38 deletions.
22 changes: 11 additions & 11 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@

$finder = Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__.'/src',
__DIR__.'/tests',
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new Config())
return (new Config)
->setRules([
'@Symfony' => true,
'phpdoc_no_empty_return' => false,
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => false,
'binary_operator_spaces' => [
'@Symfony' => true,
'phpdoc_no_empty_return' => false,
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => false,
'binary_operator_spaces' => [
'operators' => [
'=>' => 'align',
'=' => 'align',
'=' => 'align',
],
],
'concat_space' => ['spacing' => 'one'],
'increment_style' => ['style' => 'post'],
'concat_space' => ['spacing' => 'one'],
'increment_style' => ['style' => 'post'],
'not_operator_with_successor_space' => true,
])
->setFinder($finder);
4 changes: 1 addition & 3 deletions src/Attributes/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
#[Attribute]
class Collection
{
public function __construct(public string $class_name)
{
}
public function __construct(public string $class_name) {}
}
4 changes: 1 addition & 3 deletions src/Attributes/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
#[Attribute]
class Key
{
public function __construct(public string $key)
{
}
public function __construct(public string $key) {}
}
10 changes: 3 additions & 7 deletions src/Casters/Caster.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ abstract class Caster

private static array $casters = [];

public function __construct(protected string $class_name, protected bool $allows_null = false)
{
}
public function __construct(protected string $class_name, protected bool $allows_null = false) {}

public static function setCasters(array $map): array
{
Expand Down Expand Up @@ -66,7 +64,7 @@ public static function make(string $className, bool $allowsNull): Caster
$caster = new $casterClassNameOrCallable($className, $allowsNull);

if (! ($caster instanceof Caster)) {
throw new InvalidCasterException();
throw new InvalidCasterException;
}

return $caster;
Expand All @@ -76,9 +74,7 @@ private static function handleCallableCaster($callable): Caster
{
return new class($callable) extends Caster
{
public function __construct(private mixed $callable)
{
}
public function __construct(private mixed $callable) {}

public function cast(mixed $value): mixed
{
Expand Down
2 changes: 1 addition & 1 deletion src/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function make(...$arguments): self
* @throws Exceptions\CasterException
* @throws Exceptions\InvalidCasterException
*/
public static function fromArray(array $data = null): ?static
public static function fromArray(?array $data = null): ?static
{
if (Arr::isList($data)) {
throw InvalidInputDataException::unexpectedArrayList();
Expand Down
4 changes: 2 additions & 2 deletions src/Hydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ abstract class Hydrator
* @throws CasterException
* @throws Exceptions\InvalidCasterException
*/
public static function hydrate(string $className, array $data = null): ?object
public static function hydrate(string $className, ?array $data = null): ?object
{
if (empty($data)) {
return null;
}

$reflectionClass = new \ReflectionObject($dto = new $className());
$reflectionClass = new \ReflectionObject($dto = new $className);
$publicProperties = $reflectionClass->getProperties(ReflectionProperty::IS_PUBLIC);

foreach ($publicProperties as $property) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Casters/TestingCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class TestingCaster extends Caster
{
public function cast(mixed $value): ClassThatNeedsCustomCaster
{
$class = new ClassThatNeedsCustomCaster();
$class = new ClassThatNeedsCustomCaster;

$class->value = floatval((new \DateTime())->format('n')) + $value;
$class->value = floatval((new \DateTime)->format('n')) + $value;

return $class;
}
Expand Down
4 changes: 1 addition & 3 deletions tests/Models/ClassThatNeedsCustomCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ class ClassThatNeedsCustomCaster
{
public float $value;

public function __construct()
{
}
public function __construct() {}
}
12 changes: 6 additions & 6 deletions tests/SimpleHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function testItIsPossibleToWriteCaster()

$class = Hydrator::hydrate(Car::class, $data);

$expectedValue = floatval((new \DateTime())->format('n')) + 36;
$expectedValue = floatval((new \DateTime)->format('n')) + 36;
$this->assertSame($expectedValue, $class->customCaster->value);
}

Expand All @@ -227,16 +227,16 @@ public function testItIsPossibleToWriteAnonymousCaster()
$data = ['brand' => 'Ford', 'type' => 'Mustang', 'customCaster' => 36.0];

Caster::registerCaster(ClassThatNeedsCustomCaster::class, function ($value) {
$class = new ClassThatNeedsCustomCaster();
$class = new ClassThatNeedsCustomCaster;

$class->value = floatval((new \DateTime())->format('n')) + $value;
$class->value = floatval((new \DateTime)->format('n')) + $value;

return $class;
});

$class = Hydrator::hydrate(Car::class, $data);

$expectedValue = floatval((new \DateTime())->format('n')) + 36;
$expectedValue = floatval((new \DateTime)->format('n')) + 36;
$this->assertSame($expectedValue, $class->customCaster->value);
}

Expand All @@ -250,7 +250,7 @@ public function testItIsPossibleToOverwriteDefaultCaster()
return null;
}

return (new \DateTime())->setTimestamp($value);
return (new \DateTime)->setTimestamp($value);
});

$person = Human::fromArray($data);
Expand Down Expand Up @@ -328,7 +328,7 @@ public function testRegisteredCastersAreUsedForCollections()
];

Caster::registerCaster(Key::class, function ($value) {
$key = new Key();
$key = new Key;

$key->name = 'overwritten';

Expand Down

0 comments on commit cc6ec24

Please sign in to comment.