1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* It's free open-source software released under the MIT License. |
5
|
|
|
* |
6
|
|
|
* @author Anatoly Nekhay <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2018, Anatoly Nekhay |
8
|
|
|
* @license https://github.com/sunrise-php/http-router/blob/master/LICENSE |
9
|
|
|
* @link https://github.com/sunrise-php/http-router |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sunrise\Http\Router\OpenApi\PhpTypeSchemaResolver; |
15
|
|
|
|
16
|
|
|
use ReflectionParameter; |
17
|
|
|
use ReflectionProperty; |
18
|
|
|
use Reflector; |
19
|
|
|
use SensitiveParameter; |
|
|
|
|
20
|
|
|
use Sunrise\Http\Router\OpenApi\Exception\UnsupportedPhpTypeException; |
21
|
|
|
use Sunrise\Http\Router\OpenApi\OpenApiPhpTypeSchemaResolverInterface; |
22
|
|
|
use Sunrise\Http\Router\OpenApi\Type; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @since 3.0.0 |
26
|
|
|
*/ |
27
|
|
|
final class StringPhpTypeSchemaResolver implements OpenApiPhpTypeSchemaResolverInterface |
28
|
|
|
{ |
29
|
3 |
|
public function supportsPhpType(Type $phpType, Reflector $phpTypeHolder): bool |
30
|
|
|
{ |
31
|
3 |
|
return $phpType->name === Type::PHP_TYPE_NAME_STRING; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritDoc |
36
|
|
|
*/ |
37
|
3 |
|
public function resolvePhpTypeSchema(Type $phpType, Reflector $phpTypeHolder): array |
38
|
|
|
{ |
39
|
3 |
|
$this->supportsPhpType($phpType, $phpTypeHolder) or throw new UnsupportedPhpTypeException(); |
40
|
|
|
|
41
|
3 |
|
$phpTypeSchema = [ |
42
|
3 |
|
'type' => Type::OAS_TYPE_NAME_STRING, |
43
|
3 |
|
]; |
44
|
|
|
|
45
|
3 |
|
if ($phpTypeHolder instanceof ReflectionParameter) { |
46
|
3 |
|
if ($phpTypeHolder->getAttributes(SensitiveParameter::class) !== []) { |
47
|
3 |
|
$phpTypeSchema['format'] = 'password'; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
3 |
|
if ($phpTypeHolder instanceof ReflectionProperty) { |
52
|
3 |
|
foreach ($phpTypeHolder->getDeclaringClass()->getConstructor()?->getParameters() ?? [] as $parameter) { |
53
|
3 |
|
if ($parameter->name === $phpTypeHolder->name) { |
54
|
3 |
|
if ($parameter->isPromoted() && $parameter->getAttributes(SensitiveParameter::class) !== []) { |
55
|
3 |
|
$phpTypeSchema['format'] = 'password'; |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
break; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
3 |
|
return $phpTypeSchema; |
64
|
|
|
} |
65
|
|
|
|
66
|
3 |
|
public function getWeight(): int |
67
|
|
|
{ |
68
|
3 |
|
return 0; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths