Skip to content

Commit fbeaab3

Browse files
Built Inspector structure
Signed-off-by: Tom Wright <[email protected]>
1 parent e243d4a commit fbeaab3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3470
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## Unreleased
8+
- Built Inspector structure
9+
- Implemented Dumpable interface
10+
- Ported SensitiveProperty and LazyType

composer.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
"name": "decodelabs/nuance",
33
"description": "Type inspection tools",
44
"type": "library",
5-
"keywords": [],
5+
"keywords": [ ],
66
"license": "MIT",
7-
"authors": [{
8-
"name": "Tom Wright",
9-
"email": "[email protected]"
10-
}],
7+
"authors": [ {
8+
"name": "Tom Wright",
9+
"email": "[email protected]"
10+
} ],
1111
"require": {
1212
"php": "^8.4",
13-
"decodelabs/exceptional": "^0.5.3"
13+
"decodelabs/coercion": "^0.3.2",
14+
"decodelabs/exceptional": "^0.5.3",
15+
"decodelabs/glitch-support": "^0.5.1"
1416
},
1517
"require-dev": {
16-
"decodelabs/phpstan-decodelabs": "^0.7.0"
18+
"decodelabs/phpstan-decodelabs": "^0.7.0",
19+
"php-ds/php-ds": "^1.5"
1720
},
1821
"autoload": {
1922
"psr-4": {

src/Dumpable.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/**
4+
* @package Nuance
5+
* @license http://opensource.org/licenses/MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace DecodeLabs\Nuance;
11+
12+
use DecodeLabs\Nuance\Entity\NativeObject;
13+
14+
interface Dumpable
15+
{
16+
public function nuanceDump(): NativeObject;
17+
}

src/Entity.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* @package Nuance
5+
* @license http://opensource.org/licenses/MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace DecodeLabs\Nuance;
11+
12+
interface Entity
13+
{
14+
}

src/Entity/Binary.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* @package Nuance
5+
* @license http://opensource.org/licenses/MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace DecodeLabs\Nuance\Entity;
11+
12+
class Binary extends NativeString implements Structured
13+
{
14+
use StructuredTrait;
15+
16+
public function getHex(): string
17+
{
18+
return bin2hex($this->value);
19+
}
20+
}

src/Entity/ClassString.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* @package Nuance
5+
* @license http://opensource.org/licenses/MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace DecodeLabs\Nuance\Entity;
11+
12+
class ClassString implements Value
13+
{
14+
public string $value;
15+
16+
public string $type {
17+
get {
18+
if(trait_exists($this->value)) {
19+
return 'trait';
20+
}
21+
22+
if(interface_exists($this->value)) {
23+
return 'interface';
24+
}
25+
26+
return 'class';
27+
}
28+
}
29+
30+
public function __construct(
31+
string $value
32+
) {
33+
$this->value = $value;
34+
}
35+
}

src/Entity/ConstOption.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* @package Nuance
5+
* @license http://opensource.org/licenses/MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace DecodeLabs\Nuance\Entity;
11+
12+
class ConstOption implements Value, Structured
13+
{
14+
use StructuredTrait;
15+
16+
public string|bool|int|float|null $value;
17+
18+
/**
19+
* @var array<string,string|bool|int|float|null>
20+
*/
21+
protected(set) array $options = [];
22+
23+
/**
24+
* @param list<string> $constNames
25+
*/
26+
public function __construct(
27+
string|bool|int|float|null $value,
28+
array $constNames = []
29+
) {
30+
$this->value = $value;
31+
$this->options = [];
32+
33+
foreach($constNames as $name) {
34+
$name = ltrim($name, '\\');
35+
36+
// @phpstan-ignore-next-line
37+
$this->options[$name] = constant($name);
38+
}
39+
}
40+
41+
public function getSelectedConstName(): ?string
42+
{
43+
if ($this->value === null) {
44+
return null;
45+
}
46+
47+
foreach ($this->options as $name => $constValue) {
48+
if ($constValue === $this->value) {
49+
return $name;
50+
}
51+
}
52+
53+
return null;
54+
}
55+
}

src/Entity/FlagSet.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/**
4+
* @package Nuance
5+
* @license http://opensource.org/licenses/MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace DecodeLabs\Nuance\Entity;
11+
12+
use DecodeLabs\Coercion;
13+
14+
class FlagSet implements Value
15+
{
16+
public int $value;
17+
18+
/**
19+
* @var array<string,int>
20+
*/
21+
protected(set) array $options = [];
22+
23+
/**
24+
* @param list<string> $constNames
25+
*/
26+
public function __construct(
27+
int $value,
28+
array $constNames = []
29+
) {
30+
$this->value = $value;
31+
$this->options = [];
32+
33+
foreach($constNames as $name) {
34+
$name = ltrim($name, '\\');
35+
$option = Coercion::tryInt(constant($name));
36+
37+
if($option === null) {
38+
continue;
39+
}
40+
41+
$this->options[$name] = $option;
42+
}
43+
}
44+
45+
/**
46+
* @return array<string,int>
47+
*/
48+
public function getSelectedConstValues(): array
49+
{
50+
$output = [];
51+
52+
foreach ($this->options as $name => $constValue) {
53+
if (
54+
(
55+
$constValue !== 0 &&
56+
($this->value & $constValue) === $constValue
57+
) ||
58+
(
59+
$this->value === 0 &&
60+
$constValue === 0
61+
)
62+
) {
63+
$output[$name] = $constValue;
64+
}
65+
}
66+
67+
return $output;
68+
}
69+
}

src/Entity/NativeArray.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
/**
4+
* @package Nuance
5+
* @license http://opensource.org/licenses/MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace DecodeLabs\Nuance\Entity;
11+
12+
class NativeArray implements Value, Structured
13+
{
14+
use StructuredTrait;
15+
16+
private static ?string $cookieKey = null;
17+
18+
/**
19+
* @var array<mixed>
20+
*/
21+
public array $value;
22+
23+
public int $length {
24+
get => count($this->value) - 1;
25+
}
26+
27+
public ?string $hash {
28+
get {
29+
if (isset($this->hash)) {
30+
return $this->hash;
31+
}
32+
33+
if(!$this->length) {
34+
return null;
35+
}
36+
37+
$cookieKey = self::getCookieKey();
38+
$value = $this->value;
39+
unset($value[$cookieKey]);
40+
41+
return md5(print_r($value, true));
42+
}
43+
}
44+
45+
protected(set) bool $referenced = false;
46+
47+
/**
48+
* @param array<mixed> $value
49+
*/
50+
public function __construct(
51+
array &$value
52+
) {
53+
$this->value = &$value;
54+
$cookieKey = self::getCookieKey();
55+
56+
$this->referenced = array_key_exists($cookieKey, $this->value);
57+
58+
if (!$this->referenced) {
59+
$this->value[$cookieKey] = $this->hash;
60+
}
61+
}
62+
63+
public static function getCookieKey(): string
64+
{
65+
if(self::$cookieKey === null) {
66+
self::$cookieKey = uniqid('__nuance_array_');
67+
}
68+
69+
return self::$cookieKey;
70+
}
71+
}

src/Entity/NativeBoolean.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* @package Nuance
5+
* @license http://opensource.org/licenses/MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace DecodeLabs\Nuance\Entity;
11+
12+
class NativeBoolean implements Value
13+
{
14+
public bool $value;
15+
16+
public function __construct(
17+
bool $value
18+
) {
19+
$this->value = $value;
20+
}
21+
}

0 commit comments

Comments
 (0)