Skip to content

Commit

Permalink
Merge pull request #1 from KnpLabs/fix/typehint-errors
Browse files Browse the repository at this point in the history
fix: typehint errors
  • Loading branch information
Antoine Lelaisant authored Oct 26, 2022
2 parents 9c32434 + f78f98e commit e62f880
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "A Symfony bundle for knplabs/php-json-schema",
"type": "library",
"license": "MIT",
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"Knp\\JsonSchemaBundle\\": "src/"
Expand All @@ -16,10 +17,13 @@
],
"require": {
"php": ">=8.0",
"knplabs/php-json-schema": ">=0.0.3",
"knplabs/php-json-schema": ">=0.0.4",
"zircote/swagger-php": ">=4.4",
"symfony/http-kernel": ">=6.0",
"symfony/dependency-injection": ">=6.0",
"symfony/config": ">=6.0"
},
"require-dev": {
"vimeo/psalm": "5.x-dev"
}
}
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
2 changes: 1 addition & 1 deletion src/DependencyInjection/JsonSchemaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class JsonSchemaExtension extends Extension
{
public function load(array $config, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader(
$container,
Expand Down
6 changes: 3 additions & 3 deletions src/OpenApi/Annotation/JsonSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class JsonSchema extends Schema
{
/**
* @var array<string>
* @var array<mixed>
*/
public static $_required = ['schema'];

Expand All @@ -34,10 +34,10 @@ public function __construct(array $properties)
$this->required = $jsonSchema['required'] ?? false;
$this->additionalProperties = $jsonSchema['additionalProperties'] ?? true;

$this->properties = array_map(function ($name, $property) {
$this->properties = array_map(function ($name, array $property) {
if (\array_key_exists('oneOf', $property)) {
$property['oneOf'] = array_map(
fn ($schema) => new Schema($schema),
fn (array $schema) => new Schema($schema),
$property['oneOf']
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/OpenApi/Attributes/JsonSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function __construct(array $properties)
$this->required = $jsonSchema['required'] ?? false;
$this->additionalProperties = $jsonSchema['additionalProperties'] ?? true;

$this->properties = array_map(function ($name, $property) {
$this->properties = array_map(function ($name, array $property) {
if (\array_key_exists('oneOf', $property)) {
$property['oneOf'] = array_map(
fn ($schema) => new Schema($schema),
fn (object $schema) => new Schema($schema),
$property['oneOf']
);
}
Expand Down
12 changes: 9 additions & 3 deletions src/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Knp\JsonSchemaBundle;

use Knp\JsonSchema\Collection;
use Knp\JsonSchema\JsonSchemaInterface;
use Knp\JsonSchema\Validator;
use Knp\JsonSchemaBundle\Exception\JsonSchemaException;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -20,16 +21,21 @@ class RequestHandler
'application/json;charset=utf-8',
];

private Collection $schemas;
private Validator $validator;

public function __construct(
private readonly Collection $schemas,
private readonly Validator $validator
Collection $schemas,
Validator $validator
) {
$this->schemas = $schemas;
$this->validator = $validator;
}

/**
* @template T
*
* @param class-string<JsonSchema<T>> $schemaClass
* @param class-string<JsonSchemaInterface<T>> $schemaClass
*
* @return T
*/
Expand Down

0 comments on commit e62f880

Please sign in to comment.