Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Oct 30, 2024
1 parent 8a43ba8 commit d665faa
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 40 deletions.
14 changes: 7 additions & 7 deletions src/ContextGenerator/JsonldContextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Drupal\jsonld\ContextGenerator;

use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\rdf\RdfMappingInterface;
use Drupal\rdf\Entity\RdfMapping;
use Drupal\rdf\RdfMappingInterface;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -206,7 +206,7 @@ public function getFieldsRdf(RdfMappingInterface $rdfMapping, $field_name, Field

// Now we start overriding from config entity defined mappings.
// Assume all non defined mapping types as "property".
$reltype = isset($fieldRDFMapping['mapping_type']) ? $fieldRDFMapping['mapping_type'] : 'property';
$reltype = $fieldRDFMapping['mapping_type'] ?? 'property';

if (isset($fieldRDFMapping['datatype']) && ($reltype == 'property')) {
$termDefinition = ['@type' => $fieldRDFMapping['datatype']];
Expand Down Expand Up @@ -277,7 +277,7 @@ protected function writeCache(RdfMappingInterface $rdfMapping, $cid) {
* And array with the entity type and the bundle id
*/
protected function entityBundleIdsSplitter($ids) {
list($entity_type_id, $bundle_id) = explode(".", $ids, 2);
[$entity_type_id, $bundle_id] = explode(".", $ids, 2);
return ['entityTypeId' => $entity_type_id, 'bundleId' => $bundle_id];
}

Expand All @@ -297,7 +297,7 @@ protected function entityBundleIdsSplitter($ids) {
*/
protected function parseCompactedIri($iri) {
// As naive as it gets.
list($prefix, $rest) = array_pad(explode(":", $iri, 2), 2, '');
[$prefix, $rest] = array_pad(explode(":", $iri, 2), 2, '');
if ((substr($rest, 0, 2) == "//") || ($prefix == $iri)) {
// Means this was never a compacted IRI.
return ['prefix' => NULL, 'term' => $iri];
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/JsonldContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Drupal\jsonld\Controller;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerBase;
use Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface;
use Drupal\rdf\Entity\RdfMapping;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\rdf\Entity\RdfMapping;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableMetadata;

/**
* Controller for retrieving jsonld contexts.
Expand Down
10 changes: 6 additions & 4 deletions src/Normalizer/ContentEntityNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ class ContentEntityNormalizer extends NormalizerBase {
* @param \Drupal\Jsonld\Utils\JsonldNormalizerUtilsInterface $normalizer_utils
* The json-ld normalizer utilities.
*/
public function __construct(LinkManagerInterface $link_manager,
EntityTypeManagerInterface $entity_manager,
ModuleHandlerInterface $module_handler,
JsonldNormalizerUtilsInterface $normalizer_utils) {
public function __construct(
LinkManagerInterface $link_manager,
EntityTypeManagerInterface $entity_manager,
ModuleHandlerInterface $module_handler,
JsonldNormalizerUtilsInterface $normalizer_utils,
) {

$this->linkManager = $link_manager;
$this->entityManager = $entity_manager;
Expand Down
15 changes: 8 additions & 7 deletions src/Normalizer/EntityReferenceItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
* @param \Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface $jsonld_context
* The Json-Ld context service.
*/
public function __construct(LinkManagerInterface $link_manager,
EntityResolverInterface $entity_Resolver,
JsonldContextGeneratorInterface $jsonld_context) {
public function __construct(
LinkManagerInterface $link_manager,
EntityResolverInterface $entity_Resolver,
JsonldContextGeneratorInterface $jsonld_context,
) {
parent::__construct($jsonld_context);
$this->linkManager = $link_manager;
$this->entityResolver = $entity_Resolver;
Expand All @@ -69,7 +71,7 @@ public function normalize($field_item, $format = NULL, array $context = []): arr
// If the parent entity passed in a langcode, unset it before normalizing
// the target entity. Otherwise, untranslatable fields of the target entity
// will include the langcode.
$langcode = isset($context['langcode']) ? $context['langcode'] : NULL;
$langcode = $context['langcode'] ?? NULL;
unset($context['langcode']);
// Limiting to uuid makes sure that we only get one child from base entity
// if not we could end traversing forever since there is no way
Expand All @@ -91,15 +93,14 @@ public function normalize($field_item, $format = NULL, array $context = []): arr
$field_item->getParent()
->getName()
);
$field_keys = isset($field_mappings['properties']) ?
$field_mappings['properties'] :
$field_keys = $field_mappings['properties'] ??
[$field_item->getParent()->getName()];

// Value in this case is the target entity, so if a callback exists
// it should work against that.
if (!empty($field_mappings['datatype_callback'])) {
$callback = $field_mappings['datatype_callback']['callable'];
$arguments = isset($field_mappings['datatype_callback']['arguments']) ? $field_mappings['datatype_callback']['arguments'] : NULL;
$arguments = $field_mappings['datatype_callback']['arguments'] ?? NULL;
$transformed_value = call_user_func($callback, $target_entity, $arguments);
// If the config says it is an @id, we'll save it as an @id.
if (!empty($field_mappings['datatype']) && $field_mappings['datatype'] == '@id') {
Expand Down
6 changes: 3 additions & 3 deletions src/Normalizer/FieldItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public function normalize($field_item, $format = NULL, array $context = []): arr
}
else {
// Set the uri here, and then convert it to '@id' later on.
$values_clean['@value'] = isset($values['value']) ? $values['value'] : $values['uri'];
$values_clean['@value'] = $values['value'] ?? $values['uri'];
if (isset($context['current_entity_rdf_mapping'])) {
// So why i am passing the whole rdf mapping object and not
// only the predicate? Well because i hope i will be able
// to MAP to RDF also sub fields of a complex field someday
// and somehow.
$field_mappings = $context['current_entity_rdf_mapping']->getPreparedFieldMapping($field->getName());
$field_keys = isset($field_mappings['properties']) ? $field_mappings['properties'] : [$field->getName()];
$field_keys = $field_mappings['properties'] ?? [$field->getName()];

if (!empty($field_mappings['datatype'])) {
$values_clean['@type'] = $field_mappings['datatype'];
Expand All @@ -76,7 +76,7 @@ public function normalize($field_item, $format = NULL, array $context = []): arr
// For now this is a dirty solution.
if (!empty($field_mappings['datatype_callback'])) {
$callback = $field_mappings['datatype_callback']['callable'];
$arguments = isset($field_mappings['datatype_callback']['arguments']) ? $field_mappings['datatype_callback']['arguments'] : NULL;
$arguments = $field_mappings['datatype_callback']['arguments'] ?? NULL;
$values_clean['@value'] = call_user_func($callback, $values, $arguments);
}
$field_context = $this->jsonldContextgenerator->getFieldsRdf(
Expand Down
14 changes: 8 additions & 6 deletions src/Normalizer/FileEntityNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
* @param \Drupal\jsonld\Utils\JsonldNormalizerUtilsInterface $normalizer_utils
* The json-ld normalizer utils.
*/
public function __construct(EntityTypeManagerInterface $entity_manager,
ClientInterface $http_client,
LinkManagerInterface $link_manager,
ModuleHandlerInterface $module_handler,
FileSystemInterface $file_system,
JsonldNormalizerUtilsInterface $normalizer_utils) {
public function __construct(
EntityTypeManagerInterface $entity_manager,
ClientInterface $http_client,
LinkManagerInterface $link_manager,
ModuleHandlerInterface $module_handler,
FileSystemInterface $file_system,
JsonldNormalizerUtilsInterface $normalizer_utils,
) {

parent::__construct($link_manager, $entity_manager, $module_handler, $normalizer_utils);

Expand Down
2 changes: 1 addition & 1 deletion src/Utils/JsonldNormalizerUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class JsonldNormalizerUtils implements JsonldNormalizerUtilsInterface {
public function __construct(
ConfigFactoryInterface $config_factory,
LanguageManagerInterface $language_manager,
RouteProviderInterface $route_provider
RouteProviderInterface $route_provider,
) {
$this->config = $config_factory->get(JsonLdSettingsForm::CONFIG_NAME);
$this->languageManager = $language_manager;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/JsonldHookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function setUp() : void {
*/
public function testAlterNormalizedJsonld() {

list($entity, $expected) = JsonldTestEntityGenerator::create()->generateNewEntity();
[$entity, $expected] = JsonldTestEntityGenerator::create()->generateNewEntity();
$expected['@graph'][] = [
"@id" => "json_alter_normalize_hooks",
"http://purl.org/dc/elements/1.1/title" => "The hook is tested.",
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Kernel/JsonldKernelTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\Tests\jsonld\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\jsonld\Encoder\JsonldEncoder;
Expand All @@ -10,11 +11,10 @@
use Drupal\jsonld\Normalizer\FieldItemNormalizer;
use Drupal\jsonld\Normalizer\FieldNormalizer;
use Drupal\jsonld\Utils\JsonldNormalizerUtils;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\serialization\EntityResolver\ChainEntityResolver;
use Drupal\serialization\EntityResolver\TargetIdResolver;
use Symfony\Component\Serializer\Serializer;
use Drupal\language\Entity\ConfigurableLanguage;

/**
* Base class for Json-LD Kernel tests.
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/JsonldTestEntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Drupal\Tests\jsonld\Kernel;

use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\RandomGeneratorTrait;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\user\Entity\User;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp() :void {
*/
public function testSimpleNormalizeJsonld() {

list($entity, $expected) = JsonldTestEntityGenerator::create()->generateNewEntity();
[$entity, $expected] = JsonldTestEntityGenerator::create()->generateNewEntity();

$normalized = $this->serializer->normalize($entity, $this->format);
$this->assertEquals($expected, $normalized, "Did not normalize correctly.");
Expand All @@ -52,7 +52,7 @@ public function testSimpleNormalizeJsonld() {
*/
public function testLocalizedNormalizeJsonld() {

list($entity, $expected) = JsonldTestEntityGenerator::create()->generateNewEntity();
[$entity, $expected] = JsonldTestEntityGenerator::create()->generateNewEntity();

$existing_entity_values = $entity->toArray();
$target_entity_tl_id = $existing_entity_values['field_test_entity_reference'][0]['target_id'];
Expand Down Expand Up @@ -96,7 +96,7 @@ public function testLocalizedNormalizeJsonld() {
*/
public function testDeduplicateEntityReferenceMappings(): void {

list($entity, $expected) = JsonldTestEntityGenerator::create()->makeDuplicateReferenceMapping()->generateNewEntity();
[$entity, $expected] = JsonldTestEntityGenerator::create()->makeDuplicateReferenceMapping()->generateNewEntity();

$normalized = $this->serializer->normalize($entity, $this->format);

Expand All @@ -108,7 +108,7 @@ public function testDeduplicateEntityReferenceMappings(): void {
*/
public function testDeduplicateEntityReferenceIds(): void {

list($entity, $expected) = JsonldTestEntityGenerator::create()->makeDuplicateReference()->generateNewEntity();
[$entity, $expected] = JsonldTestEntityGenerator::create()->makeDuplicateReference()->generateNewEntity();

$normalized = $this->serializer->normalize($entity, $this->format);

Expand All @@ -122,7 +122,7 @@ public function testDeduplicateEntityReferenceIds(): void {
* - sharing the same RDF mapping.
*/
public function testDuplicateEntityReferenceAndMappings(): void {
list($entity, $expected) = JsonldTestEntityGenerator::create()->makeDuplicateReference()->makeDuplicateReferenceMapping()
[$entity, $expected] = JsonldTestEntityGenerator::create()->makeDuplicateReference()->makeDuplicateReferenceMapping()
->generateNewEntity();

$normalized = $this->serializer->normalize($entity, $this->format);
Expand Down

0 comments on commit d665faa

Please sign in to comment.