Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP - uint8, int8 serialization support #1473

Merged
merged 10 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Added missing mappings in PHP for uint8 and int8. [#1473](https://github.com/microsoft/kiota/pull/1473)

### Changed

Expand Down
13 changes: 0 additions & 13 deletions abstractions/php/src/Serialization/ParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use DateInterval;
use DateTime;
use Microsoft\Kiota\Abstractions\Enum;
use Microsoft\Kiota\Abstractions\Types\Byte;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -93,18 +92,6 @@ public function getTimeValue(): ?Time;
*/
public function getEnumValue(string $targetEnum): ?Enum;

/**
* @param string $targetClass
* @return Enum[]|null
*/
public function getCollectionOfEnumValues(string $targetClass): ?array;

/**
* Return a byte value.
* @return Byte|null
*/
public function getByteValue(): ?Byte;

/**
* Get a Stream from node.
* @return StreamInterface|null
Expand Down
8 changes: 0 additions & 8 deletions abstractions/php/src/Serialization/SerializationWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use DateInterval;
use DateTime;
use Microsoft\Kiota\Abstractions\Enum;
use Microsoft\Kiota\Abstractions\Types\Byte;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -122,13 +121,6 @@ public function writeTimeValue(?string $key, ?Time $value): void;
* @return void
*/
public function writeDateIntervalValue(?string $key, ?DateInterval $value): void;
/**
* Write a byte value.
* @param string|null $key
* @param Byte|null $value
* @return void
*/
public function writeByteValue(?string $key, ?Byte $value): void;

/**
* @param string|null $key
Expand Down
32 changes: 0 additions & 32 deletions abstractions/php/src/Types/Byte.php

This file was deleted.

5 changes: 4 additions & 1 deletion serialization/php/json/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"repositories": [
{
"type": "path",
"url": "../../../abstractions/php"
"url": "../../../abstractions/php",
"options": {
"symlink": false
}
}
],
"autoload": {
Expand Down
10 changes: 0 additions & 10 deletions serialization/php/json/src/JsonParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Microsoft\Kiota\Abstractions\Serialization\AdditionalDataHolder;
use Microsoft\Kiota\Abstractions\Serialization\Parsable;
use Microsoft\Kiota\Abstractions\Serialization\ParseNode;
use Microsoft\Kiota\Abstractions\Types\Byte;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -238,8 +237,6 @@ public function getAnyValue(string $type) {
return $this->getDateValue();
case Time::class:
return $this->getTimeValue();
case Byte::class:
return $this->getByteValue();
default:
if (is_subclass_of($type, Enum::class)){
return $this->getEnumValue($type);
Expand Down Expand Up @@ -268,13 +265,6 @@ public function getTimeValue(): ?Time {
return ($this->jsonNode !== null) ? new Time($this->jsonNode) : null;
}

/**
* @inheritDoc
*/
public function getByteValue(): ?Byte {
return ($this->jsonNode !== null) ? new Byte($this->jsonNode) : null;
}

/**
* @inheritDoc
* @throws Exception
Expand Down
18 changes: 0 additions & 18 deletions serialization/php/json/src/JsonSerializationWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ public function writeAnyValue(?string $key, $value): void{
case Time::class:
$this->writeTimeValue($key, $value);
break;
case Byte::class:
$this->writeByteValue($key, $value);
break;
case DateTime::class:
$this->writeDateTimeValue($key, $value);
break;
Expand Down Expand Up @@ -464,19 +461,4 @@ public function writeDateIntervalValue(?string $key, ?DateInterval $value): void
$this->writePropertyValue($key, $val);
}
}

/**
* @inheritDoc
*/
public function writeByteValue(?string $key, ?Byte $value): void {


if ($value !== null) {
if (!empty($key)) {
$this->writePropertyName($key);
}
$val = (int)(string)($value);
$this->writePropertyValue($key, $val);
}
}
}
11 changes: 0 additions & 11 deletions serialization/php/json/tests/JsonParseNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use GuzzleHttp\Psr7\Utils;
use Microsoft\Kiota\Abstractions\Enum;
use Microsoft\Kiota\Abstractions\Serialization\ParseNode;
use Microsoft\Kiota\Abstractions\Types\Byte;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use Microsoft\Kiota\Serialization\Json\JsonParseNode;
Expand Down Expand Up @@ -95,16 +94,6 @@ public function testGetAnyValue(): void {
$this->assertEquals('Silas Kenneth', $expectedString);
}

public function testGetByteValue(): void {
$this->parseNode = new JsonParseNode('23');
$expected = $this->parseNode->getByteValue();
$this->assertInstanceOf(Byte::class, $expected);
$this->assertEquals(23, (string)$expected);
$this->expectException(Exception::class);
$this->parseNode = new JsonParseNode('-192');
$this->parseNode->getByteValue();
}

public function testGetEnumValue(): void {
$this->parseNode = new JsonParseNode('married');
/** @var Enum $expected */
Expand Down
18 changes: 3 additions & 15 deletions serialization/php/json/tests/JsonSerializationWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Microsoft\Kiota\Serialization\Tests;

use Microsoft\Kiota\Abstractions\Serialization\SerializationWriter;
use Microsoft\Kiota\Abstractions\Types\Byte;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use Microsoft\Kiota\Serialization\Json\JsonSerializationWriter;
Expand Down Expand Up @@ -135,9 +134,9 @@ public function testWriteEnumValue(): void{

public function testWriteAnyValue(): void {
$this->jsonSerializationWriter = new JsonSerializationWriter();
$byte = new Byte(23);
$this->jsonSerializationWriter->writeAnyValue("to", $byte);
$expected = '"to":23';
$time = new Time('11:00:00');
$this->jsonSerializationWriter->writeAnyValue("created", $time);
$expected = '"created":"11:00:00"';
$actual = $this->jsonSerializationWriter->getSerializedContent()->getContents();
$this->assertEquals($expected, $actual);
}
Expand Down Expand Up @@ -198,17 +197,6 @@ public function testGetSerializedContent(): void{
$this->assertEquals($expected, $actual);
}

/**
*/
public function testWriteByteValue(): void{
$this->jsonSerializationWriter = new JsonSerializationWriter();
$byte = new Byte(23);
$this->jsonSerializationWriter->writeAnyValue("to", $byte);
$expected = '"to":23';
$actual = $this->jsonSerializationWriter->getSerializedContent()->getContents();
$this->assertEquals($expected, $actual);
}

/**
*/
public function testWriteStringValue(): void {
Expand Down
5 changes: 3 additions & 2 deletions src/Kiota.Builder/Writers/Php/PhpConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public override string TranslateType(CodeType type)
return typeName?.ToLowerInvariant() switch
{
"boolean" => "bool",
"double" or "decimal" => "float",
"integer" or "int32" or "int64" => "int",
"double" => "float",
"decimal" or "byte" => "string",
"integer" or "int32" or "int64" or "sbyte" => "int",
"object" or "string" or "array" or "float" or "void" => typeName.ToLowerInvariant(),
"binary" => "StreamInterface",
_ => typeName.ToFirstCharacterUpperCase()
Expand Down
Loading