Skip to content

Commit

Permalink
Update to php 8 code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Matys333 committed Oct 12, 2023
1 parent 63cd7ba commit c3b37cf
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 57 deletions.
20 changes: 10 additions & 10 deletions src/Type/CursorResultType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

namespace Youshido\GraphQLExtension\Type;


use Youshido\GraphQL\Config\Object\ObjectTypeConfig;
use Youshido\GraphQL\Exception\ConfigurationException;
use Youshido\GraphQL\Relay\Connection\Connection;
use Youshido\GraphQL\Relay\Type\PageInfoType;
use Youshido\GraphQL\Type\AbstractType;
Expand All @@ -19,30 +18,31 @@

class CursorResultType extends AbstractObjectType
{

private $edgeType;
private AbstractType $edgeType;

public function __construct(AbstractType $edgeType)
{
parent::__construct([
'name' => sprintf('Cursor%sResult', $edgeType->getName()),
'name' => sprintf('Cursor%sResult', $edgeType->getName()),
'description' => sprintf('Returns list of type %s in batches', $edgeType->getName())
]);
$this->edgeType = $edgeType;
}

public function build($config)
/**
* @throws ConfigurationException
*/
public function build($config): void
{
$config->addFields([
'pageInfo' => [
'type' => new NonNullType(new PageInfoType()),
'type' => new NonNullType(new PageInfoType()),
'description' => 'Information to aid in pagination.',
],
'edges' => [
'type' => new ListType(Connection::edgeDefinition($this->edgeType)),
'edges' => [
'type' => new ListType(Connection::edgeDefinition($this->edgeType)),
'description' => 'A list of edges.',
]
]);
}

}
18 changes: 7 additions & 11 deletions src/Type/FileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace Youshido\GraphQLExtension\Type;


use Youshido\GraphQL\Config\Object\ObjectTypeConfig;
use Youshido\GraphQL\Type\Object\AbstractObjectType;
use Youshido\GraphQL\Type\Scalar\DateTimeType;
use Youshido\GraphQL\Type\Scalar\IdType;
Expand All @@ -18,22 +16,20 @@

class FileType extends AbstractObjectType
{
public function build($config)
public function build($config): void
{
$config->addFields([
'id' => new IdType(),
'title' => [
'type' => new StringType(),
'id' => new IdType(),
'title' => [
'type' => new StringType(),
'description' => 'Can be used to store a more descriptive title',
],
'createdAt' => new DateTimeType('c'),
'updatedAt' => new DateTimeType('c'),
'url' => new StringType(),
'size' => new IntType(),
'name' => new StringType(),
'url' => new StringType(),
'size' => new IntType(),
'name' => new StringType(),
'extension' => new StringType(),
]);
}


}
13 changes: 4 additions & 9 deletions src/Type/PaginatedResultType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,28 @@

namespace Youshido\GraphQLExtension\Type;


use Youshido\GraphQL\Config\Object\ObjectTypeConfig;
use Youshido\GraphQL\Type\AbstractType;
use Youshido\GraphQL\Type\ListType\ListType;
use Youshido\GraphQL\Type\Object\AbstractObjectType;
use Youshido\GraphQL\Type\Object\ObjectType;
use Youshido\GraphQL\Type\Scalar\IntType;

class PaginatedResultType extends AbstractObjectType
{
private $listItemType;
private AbstractType $listItemType;

public function __construct(AbstractType $type)
{
parent::__construct([
'name' => sprintf('Batch%sResult', $type->getName()),
'name' => sprintf('Batch%sResult', $type->getName()),
'description' => sprintf('Returns list of type %s in batches', $type->getName())
]);
$this->listItemType = $type;
}

public function build($config)
public function build($config): void
{
$config->addFields([
'pagingInfo' => new PagingInfoType(),
'items' => new ListType($this->listItemType),
'items' => new ListType($this->listItemType),
]);
}

}
8 changes: 3 additions & 5 deletions src/Type/PagingInfoType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@

namespace Youshido\GraphQLExtension\Type;


use Youshido\GraphQL\Config\Object\ObjectTypeConfig;
use Youshido\GraphQL\Type\Object\AbstractObjectType;
use Youshido\GraphQL\Type\Scalar\IntType;

class PagingInfoType extends AbstractObjectType
{
public function build($config)
public function build($config): void
{
$config->addFields([
'offset' => new IntType(),
'limit' => new IntType(),
'offset' => new IntType(),
'limit' => new IntType(),
'totalCount' => new IntType(),
]);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Type/PagingParamsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@

namespace Youshido\GraphQLExtension\Type;

use Youshido\GraphQL\Config\Object\InputObjectTypeConfig;
use Youshido\GraphQL\Type\InputObject\AbstractInputObjectType;
use Youshido\GraphQL\Type\Scalar\IntType;

class PagingParamsType extends AbstractInputObjectType
{
public function build($config)
public function build($config): void
{
$this->addFields([
'offset' => new IntType(),
'limit' => new IntType(),
'limit' => new IntType(),
]);
}

}
9 changes: 4 additions & 5 deletions src/Type/Sorting/SortingOrderType.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<?php
namespace Youshido\GraphQLExtension\Type\Sorting;

namespace Youshido\GraphQLExtension\Type\Sorting;

use Youshido\GraphQL\Type\Enum\AbstractEnumType;

class SortingOrderType extends AbstractEnumType
{
public function getValues()
public function getValues(): array
{
return [
[
'name' => 'ASC',
'name' => 'ASC',
'value' => 1,
],
[
'name' => 'DESC',
'name' => 'DESC',
'value' => -1,
],
];
}

}
23 changes: 10 additions & 13 deletions src/Type/Sorting/SortingParamsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,43 @@

class SortingParamsType extends AbstractInputObjectType
{

/** @var AbstractType */
private $type;
private AbstractType $type;

/** @var array */
private $fields;
private array $fields;

/** @var string */
private $prefix;
private string $prefix;

public function __construct(AbstractType $type, array $fields)
{
$this->type = $type;
$this->type = $type;
$this->fields = $fields;
$this->prefix = sprintf("%sSorting", $type->getName());
$this->prefix = sprintf("%sSorting", $this->type->getName());

parent::__construct([
'name' => $this->prefix . 'Params'
]);
}

public function build($config)
public function build($config): void
{
$config->addFields([
'field' => [
'type' => new EnumType([
'name' => $this->prefix . 'Fields',
'type' => new EnumType([
'name' => $this->prefix . 'Fields',
'values' => array_map(function ($field) {
return [
'name' => $field,
'name' => $field,
'value' => $field,
];
}, $this->fields)
]),
'description' => 'Field to sort by: ' . implode(', ', $this->fields),
'description' => 'Field to sort by: ' . implode(', ', $this->fields),
'defaultValue' => 'id',
],
'order' => new SortingOrderType()
]);
}


}

0 comments on commit c3b37cf

Please sign in to comment.