Skip to content

Commit

Permalink
Fixed CS
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Dunogier authored and bdunogier committed Dec 6, 2019
1 parent 606f187 commit e97d89d
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
composer.lock
.php_cs.cache
7 changes: 7 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return EzSystems\EzPlatformCodeStyle\PhpCsFixer\EzPlatformInternalConfigFactory::build()->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->files()->name('*.php')
);
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
}
},
"require-dev": {
"phpspec/phpspec": "^5.1"
"phpspec/phpspec": "^5.1",
"ezsystems/ezplatform-code-style": "^0.1.0",
"friendsofphp/php-cs-fixer": "^2.16.0"
},
"extra": {
"branch-alias": {
Expand Down
10 changes: 4 additions & 6 deletions doc/examples/nearby_places/NearbyPlacesQueryType.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

/**
* Created by PhpStorm.
* User: bdunogier
* Date: 29/09/2018
* Time: 16:46
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/

namespace AppBundle\QueryType;

use eZ\Publish\API\Repository\Values\Content\Query;
Expand Down Expand Up @@ -39,4 +37,4 @@ public static function getName()
{
return 'NearbyPlaces';
}
}
}
8 changes: 4 additions & 4 deletions src/API/QueryFieldService.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/

namespace EzSystems\EzPlatformQueryFieldType\API;

use eZ\Publish\API\Repository\ContentTypeService;
Expand Down Expand Up @@ -50,6 +50,7 @@ public function __construct(
* @param string $fieldDefinitionIdentifier
*
* @return \eZ\Publish\API\Repository\Values\Content\Content[]
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function loadFieldData(Content $content, string $fieldDefinitionIdentifier): array
Expand All @@ -59,7 +60,7 @@ public function loadFieldData(Content $content, string $fieldDefinitionIdentifie
$parameters = $this->resolveParameters($fieldDefinition->fieldSettings['Parameters'], $content);

return array_map(
function(SearchHit $searchHit) {
function (SearchHit $searchHit) {
return $searchHit->valueObject;
},
$this->searchService->findContent($queryType->getQuery($parameters))->searchHits
Expand All @@ -72,7 +73,6 @@ public function getFieldDefinition(ContentInfo $contentInfo, string $fieldDefini
$this
->contentTypeService->loadContentType($contentInfo->contentTypeId)
->getFieldDefinition($fieldDefinitionIdentifier);

}

/**
Expand Down Expand Up @@ -105,4 +105,4 @@ private function applyContentToParameter(Content $content, string $parameter)
]
);
}
}
}
11 changes: 7 additions & 4 deletions src/Controller/QueryFieldController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\Controller;

use EzSystems\EzPlatformQueryFieldType\API\QueryFieldService;
use EzSystems\EzPlatformQueryFieldType\GraphQL\QueryFieldResolver;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use EzSystems\EzPlatformGraphQL\GraphQL\Value\Field as GraphQLField;

final class QueryFieldController
{
Expand All @@ -25,9 +28,9 @@ public function renderQueryFieldAction(ContentView $view, $queryFieldDefinitionI
'query_results' => $this->queryFieldService->loadFieldData(
$view->getContent(),
$queryFieldDefinitionIdentifier
)
),
]);

return $view;
}
}
}
12 changes: 8 additions & 4 deletions src/Controller/QueryFieldRestController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\Controller;

use EzSystems\EzPlatformQueryFieldType\API\QueryFieldService;
Expand Down Expand Up @@ -38,8 +43,7 @@ public function __construct(
ContentService $contentService,
ContentTypeService $contentTypeService,
LocationService $locationService
)
{
) {
$this->queryFieldService = $queryFieldService;
$this->contentService = $contentService;
$this->contentTypeService = $contentTypeService;
Expand All @@ -52,7 +56,7 @@ public function getResults($contentId, $versionNumber, $fieldDefinitionIdentifie

return new ContentList(
array_map(
function(Content $content) {
function (Content $content) {
return new RestContent(
$content->contentInfo,
$this->locationService->loadLocation($content->contentInfo->mainLocationId),
Expand All @@ -76,4 +80,4 @@ private function getContentType(ContentInfo $contentInfo): ContentType

return $contentTypes[$contentInfo->contentTypeId];
}
}
}
11 changes: 8 additions & 3 deletions src/FieldType/Mapper/QueryFormMapper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\FieldType\Mapper;

use EzSystems\EzPlatformQueryFieldType\Form\Type\FieldType\QueryFieldType;
Expand All @@ -20,7 +24,8 @@ class QueryFormMapper implements FieldDefinitionFormMapperInterface, FieldValueF
private $contentTypeService;

/**
* List of query types
* List of query types.
*
* @var array
*/
private $queryTypes;
Expand All @@ -34,7 +39,7 @@ public function __construct(ContentTypeService $contentTypeService, array $query
public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data)
{
$fieldDefinitionForm
->add('QueryType',Type\ChoiceType::class,
->add('QueryType', Type\ChoiceType::class,
[
'label' => 'Query type',
'property_path' => 'fieldSettings[QueryType]',
Expand All @@ -51,7 +56,7 @@ public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, Field
->add('Parameters', Type\TextareaType::class,
[
'label' => 'Parameters',
'property_path' => 'fieldSettings[Parameters]'
'property_path' => 'fieldSettings[Parameters]',
]
);
}
Expand Down
12 changes: 8 additions & 4 deletions src/FieldType/Query/SearchField.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\FieldType\Query;

use eZ\Publish\SPI\Persistence\Content\Field;
Expand All @@ -19,7 +23,7 @@ class SearchField implements Indexable
*/
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
{
return array(
return [
new Search\Field(
'value',
$field->value->data,
Expand All @@ -30,7 +34,7 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
$field->value->data,
new Search\FieldType\FullTextField()
),
);
];
}

/**
Expand All @@ -40,9 +44,9 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
*/
public function getIndexDefinition()
{
return array(
return [
'value' => new Search\FieldType\StringField(),
);
];
}

/**
Expand Down
15 changes: 9 additions & 6 deletions src/FieldType/Query/Type.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\FieldType\Query;

use eZ\Publish\Core\FieldType\FieldType;
Expand All @@ -11,15 +15,14 @@

class Type extends FieldType
{
protected $validatorConfigurationSchema = array();
protected $validatorConfigurationSchema = [];

protected $settingsSchema = [
'QueryType' => ['type' => 'string', 'default' => ''],
'Parameters' => ['type' => 'string', 'default' => ''],
'ReturnedType' => ['type' => 'string', 'default' => ''],
];


/**
* Validates the validatorConfiguration of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.
*
Expand Down Expand Up @@ -105,7 +108,7 @@ protected function createValueFromInput($inputValue)
/**
* Throws an exception if value structure is not of expected format.
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the value does not match the expected structure.
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the value does not match the expected structure
*
* @param \eZ\Publish\Core\FieldType\TextLine\Value $value
*/
Expand Down Expand Up @@ -180,16 +183,16 @@ public function validateFieldSettings($fieldSettings)

if (isset($fieldSettings['QueryType'])) {
/**
* $errors[] = new ValidationError("Query type %query_type does not exist", null, ['%query_type%' => $fieldSettings['QueryType']]);
* $errors[] = new ValidationError("Query type %query_type does not exist", null, ['%query_type%' => $fieldSettings['QueryType']]);.
*/
}

if (isset($fieldSettings['Parameters']) && $fieldSettings['Parameters']) {
if (json_decode($fieldSettings['Parameters']) === null) {
$errors[] = new ValidationError("Parameters is not a valid json structure");
$errors[] = new ValidationError('Parameters is not a valid json structure');
}
}

return $errors;
return $errors;
}
}
4 changes: 4 additions & 0 deletions src/FieldType/Query/Value.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\FieldType\Query;

use eZ\Publish\Core\FieldType\Value as BaseValue;
Expand Down
4 changes: 4 additions & 0 deletions src/Form/Type/FieldType/QueryFieldType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\Form\Type\FieldType;

use eZ\Publish\API\Repository\FieldTypeService;
Expand Down
7 changes: 6 additions & 1 deletion src/GraphQL/QueryFieldDefinitionMapper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\GraphQL;

use eZ\Publish\API\Repository\ContentTypeService;
Expand Down Expand Up @@ -51,4 +56,4 @@ private function getDomainTypeName($typeIdentifier)
$this->contentTypeService->loadContentTypeByIdentifier($typeIdentifier)
);
}
}
}
10 changes: 8 additions & 2 deletions src/GraphQL/QueryFieldResolver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\GraphQL;

use EzSystems\EzPlatformQueryFieldType\API\QueryFieldService;
Expand All @@ -12,12 +17,13 @@ class QueryFieldResolver
*/
private $queryFieldService;

public function __construct(QueryFieldService $queryFieldService) {
public function __construct(QueryFieldService $queryFieldService)
{
$this->queryFieldService = $queryFieldService;
}

public function resolveQueryField(Field $field, Content $content)
{
return $this->queryFieldService->loadFieldData($content, $field->fieldDefIdentifier);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\Persistence\Legacy\Content\FieldValue\Converter;

use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
Expand Down Expand Up @@ -72,7 +76,7 @@ public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefin
$fieldDef->fieldTypeConstraints->fieldSettings = [
'QueryType' => $storageDef->dataText1 ?: null,
'ReturnedType' => $storageDef->dataText2 ?: null,
'Parameters' => $storageDef->dataText5 ?: ''
'Parameters' => $storageDef->dataText5 ?: '',
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformQueryFieldType\Symfony\DependencyInjection;

use EzSystems\EzPlatformQueryFieldType\Controller\QueryFieldController;
Expand Down Expand Up @@ -52,9 +57,9 @@ protected function setContentViewConfig(ContainerBuilder $container): void
$contentViewDefaults['query_field'] = [
'default' => [
'controller' => QueryFieldController::class . ':renderQueryFieldAction',
'template' => "BDEzPlatformQueryFieldTypeBundle::query_field_view.html.twig",
'template' => 'BDEzPlatformQueryFieldTypeBundle::query_field_view.html.twig',
'match' => [],
]
],
];
$container->setParameter('ezsettings.default.content_view_defaults', $contentViewDefaults);
}
Expand Down
Loading

0 comments on commit e97d89d

Please sign in to comment.