Skip to content

Commit

Permalink
Update code from Temporal PHP SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Jul 16, 2023
1 parent 1838425 commit 8ee5eb0
Show file tree
Hide file tree
Showing 40 changed files with 1,027 additions and 245 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.php_cs
.php_cs.cache
.phpunit.result.cache
.phpunit.cache
build
composer.lock
coverage
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"license": "MIT",
"require": {
"php": ">=8.1",
"nesbot/carbon": "^2.67.0",
"nesbot/carbon": "^2.68.0",
"google/protobuf": "^3.23",
"spiral/attributes": "^2.7 || ^3.0"
},
"require-dev": {
"ramsey/uuid": "^4.7",
"roave/security-advisories": "dev-latest",
"jetbrains/phpstorm-attributes": "dev-master@dev",
"phpunit/phpunit": "^10.2",
Expand All @@ -27,7 +28,7 @@
},
"autoload-dev": {
"psr-4": {
"Spiral\\Marshaller\\Tests\\": "tests/src"
"Spiral\\Marshaller\\Tests\\": "tests"
}
},
"scripts": {
Expand Down
42 changes: 29 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
stopOnError="false"
stderr="true">
executionOrder="random"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true">
<testsuites>
<testsuite name="Marshaller Test Suite">
<directory>./tests/</directory>
<testsuite name="Marshaller">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
9 changes: 9 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Spiral\Marshaller\Exception;

final class InvalidArgumentException extends \InvalidArgumentException
{
}
14 changes: 12 additions & 2 deletions src/Marshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Spiral\Marshaller;

use Spiral\Marshaller\Exception\InvalidArgumentException;
use Spiral\Marshaller\Mapper\MapperFactoryInterface;
use Spiral\Marshaller\Mapper\MapperInterface;

Expand Down Expand Up @@ -51,8 +52,17 @@ public function marshal(object $from): array
*/
public function unmarshal(array $from, object $to): object
{
$mapper = $this->getMapper(\get_class($to));
$class = $to::class;

if ($class === \stdClass::class) {
foreach ($from as $key => $value) {
$to->{$key} = $value;
}

return $to;
}

$mapper = $this->getMapper($class);
$result = $mapper->isCopyOnWrite() ? clone $to : $to;

foreach ($mapper->getSetters() as $field => $setter) {
Expand All @@ -63,7 +73,7 @@ public function unmarshal(array $from, object $to): object
try {
$setter->call($result, $from[$field] ?? null);
} catch (\Throwable $e) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
\sprintf('Unable to unmarshal field `%s` of class %s', $field, $to::class),
previous: $e
);
Expand Down
1 change: 0 additions & 1 deletion src/Meta/Marshal.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Marshal extends MarshallingRule
{
/**
* @param class-string|null $type
* @param null|Marshal|string $of
*/
public function __construct(
?string $name = null,
Expand Down
6 changes: 6 additions & 0 deletions src/Meta/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ class Scope
| self::VISIBILITY_PROTECTED
| self::VISIBILITY_PUBLIC;

/**
* @var ExportScope
*/
#[ExpectedValues(valuesFromClass: Scope::class)]
public int $properties;

public bool $copyOnWrite;

/**
* @param ExportScope $properties
*/
public function __construct(
int $properties = self::VISIBILITY_PUBLIC,
bool $copyOnWrite = false
Expand Down
2 changes: 1 addition & 1 deletion src/RuleFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Defines ability for {@see TypeFactoryInterface} to produce {@see MarshallingRule}
* using {@see \Spiral\Marshaller\Type\RuleFactoryInterface}.
* using {@see Type\RuleFactoryInterface}.
*/
interface RuleFactoryInterface extends TypeFactoryInterface
{
Expand Down
152 changes: 0 additions & 152 deletions src/Support/DateInterval.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Support/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;

final class DateTime
{
Expand Down
63 changes: 0 additions & 63 deletions src/Type/DateIntervalType.php

This file was deleted.

0 comments on commit 8ee5eb0

Please sign in to comment.