-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeclaredHandler.php
More file actions
42 lines (33 loc) · 958 Bytes
/
DeclaredHandler.php
File metadata and controls
42 lines (33 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/*
* This file is part of Respect/Stringifier.
* Copyright (c) Henrique Moody <henriquemoody@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Stringifier\Handlers;
use Respect\Stringifier\Handler;
use Respect\Stringifier\Quoter;
use function class_exists;
use function enum_exists;
use function interface_exists;
use function is_string;
use function trait_exists;
final class DeclaredHandler implements Handler
{
public function __construct(
private readonly Quoter $quoter,
) {
}
public function handle(mixed $raw, int $depth): string|null
{
if (!is_string($raw) || $this->isNotDeclared($raw)) {
return null;
}
return $this->quoter->quote($raw, $depth);
}
public function isNotDeclared(string $raw): bool
{
return !class_exists($raw) && !interface_exists($raw) && !trait_exists($raw) && !enum_exists($raw);
}
}