Skip to content

Commit 36a81fa

Browse files
committed
Added PHPDoc for generic functions
1 parent 5077a49 commit 36a81fa

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/main/de/interaapps/jsonplus/parser/JSONDecoder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ public function readString() : string {
112112
}
113113

114114
private function primitiveStringToPHP($p){
115+
$p = trim($p);
115116
if ($p == "false")
116117
return false;
117-
if ($p == "true")
118+
else if ($p == "true")
118119
return true;
120+
else if ($p == "null")
121+
return null;
119122
return (double) $p;
120123
}
121124

src/main/de/interaapps/jsonplus/parser/JSONEncoder.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public function encode($v, $tabs="") : string {
1010
$this->prettyPrintNewLine = $this->prettyPrint ? "\n": '';
1111
$identedTabs = $this->prettyPrint ? $tabs." " : '';
1212

13-
if (is_bool($v)) {
13+
if (!isset($v)) {
14+
return "null";
15+
} if (is_bool($v)) {
1416
return $v ? "true" : "false";
1517
} else if (is_int($v) || is_bool($v) || is_double($v)) {
1618
return strval($v);
@@ -22,10 +24,6 @@ public function encode($v, $tabs="") : string {
2224
return '"'.$this->escapeString($v).'"';
2325
} else if (is_object($v)) {
2426
$v = (array) $v;
25-
foreach ($v as $key=>$value) {
26-
if (!isset($value))
27-
unset($v[$key]);
28-
}
2927
if (count($v) == 0)
3028
return "{}";
3129
return '{'.$this->prettyPrintNewLine.implode(", ".$this->prettyPrintNewLine, array_map(fn($k, $val)=>$identedTabs.$this->encode($k, $identedTabs).': '.$this->encode($val, $identedTabs), array_keys($v), array_values($v))).$this->prettyPrintNewLine.$tabs.'}';

src/test/testbootstrap.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class Test {
2929
public array $aeef;
3030
public object $aeef2;
3131
public Test2 $test2;
32+
public $aaaa;
33+
public $aa;
3234
public function __construct(){
3335
}
3436

@@ -45,11 +47,14 @@ public function setName(string $name): Test {
4547
"test": false,
4648
"feef": 21,
4749
"aeef": ["1","2","3"],
48-
"test2": "a"
50+
"test2": "a",
51+
"aaaa": null,
52+
"aa": false
4953
}';
5054

5155
//echo Test::fromJson(JSON)->toJson();
52-
$json = new JSONPlus(new PHPJsonSerializationAdapter());
56+
$json = new JSONPlus(new JsonSerializationAdapter());
5357
$var = $json->fromJson(JSON, Test::class);
58+
5459
echo $var->name."\n";
55-
echo $json->toJson($var);
60+
echo $json->toJson($var);

0 commit comments

Comments
 (0)