Skip to content

Commit

Permalink
chore: clean-up code styles.
Browse files Browse the repository at this point in the history
  • Loading branch information
vbyndych committed Oct 13, 2023
1 parent fa1e105 commit 93296c4
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 105 deletions.
1 change: 1 addition & 0 deletions common/persistence/Graph/BasicTransactionManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down
1 change: 1 addition & 0 deletions common/persistence/Graph/GraphTransactionException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down
1 change: 1 addition & 0 deletions common/persistence/Graph/NestedTransactionWrapper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down
1 change: 1 addition & 0 deletions common/persistence/Graph/TransactionManagerInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down
5 changes: 3 additions & 2 deletions common/persistence/class.GraphPersistence.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -26,8 +27,8 @@
use oat\generis\persistence\Graph\NestedTransactionWrapper;
use oat\generis\persistence\Graph\TransactionManagerInterface;

class common_persistence_GraphPersistence extends common_persistence_Persistence
implements common_persistence_Transactional
class common_persistence_GraphPersistence extends common_persistence_Persistence implements
common_persistence_Transactional
{
private TransactionManagerInterface $transactionManager;

Expand Down
1 change: 1 addition & 0 deletions common/persistence/class.PhpNeo4jDriver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down
3 changes: 2 additions & 1 deletion common/persistence/class.SqlPersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
/**
* Persistence base on SQL
*/
class common_persistence_SqlPersistence extends common_persistence_Persistence implements common_persistence_Transactional
class common_persistence_SqlPersistence extends common_persistence_Persistence implements
common_persistence_Transactional
{
/**
* @return common_persistence_sql_SchemaManager
Expand Down
10 changes: 9 additions & 1 deletion core/kernel/classes/class.Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,15 @@ public function isRelationship(): bool

$range = $this->getRange();

return $range && !in_array($range->getUri(), [OntologyRdfs::RDFS_LITERAL, GenerisRdf::CLASS_GENERIS_FILE], true);
return $range
&& !in_array(
$range->getUri(),
[
OntologyRdfs::RDFS_LITERAL,
GenerisRdf::CLASS_GENERIS_FILE
],
true
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions core/kernel/persistence/starsql/FlatRecursiveIterator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down
27 changes: 18 additions & 9 deletions core/kernel/persistence/starsql/class.Class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
use function WikibaseSolutions\CypherDSL\query;
use function WikibaseSolutions\CypherDSL\variable;

class core_kernel_persistence_starsql_Class extends core_kernel_persistence_starsql_Resource implements core_kernel_persistence_ClassInterface
class core_kernel_persistence_starsql_Class extends core_kernel_persistence_starsql_Resource implements
core_kernel_persistence_ClassInterface
{
use EventManagerAwareTrait;

Expand Down Expand Up @@ -221,7 +222,9 @@ public function createInstance(core_kernel_classes_Class $resource, $label = '',
);

$nodeForRelationship = node()->withVariable($variableForRelatedResource = variable());
$relatedResource = node('Resource')->withProperties(['uri' => $relatedUri = parameter()])->withVariable($variableForRelatedResource);
$relatedResource = node('Resource')
->withProperties(['uri' => $relatedUri = parameter()])
->withVariable($variableForRelatedResource);
$node = $node->relationshipTo($nodeForRelationship, OntologyRdf::RDF_TYPE);

$query = query()
Expand Down Expand Up @@ -260,8 +263,12 @@ public function createSubClass(core_kernel_classes_Class $resource, $label = '',
return $returnValue;
}

public function createProperty(core_kernel_classes_Class $resource, $label = '', $comment = '', $isLgDependent = false)
{
public function createProperty(
core_kernel_classes_Class $resource,
$label = '',
$comment = '',
$isLgDependent = false
) {
$returnValue = null;

$propertyClass = $this->getModel()->getClass(OntologyRdf::RDF_PROPERTY);
Expand Down Expand Up @@ -334,7 +341,7 @@ public function getInstancesPropertyValues(

$valueList = [];
/** @var core_kernel_classes_Triple $triple */
foreach($resultSet as $triple) {
foreach ($resultSet as $triple) {
$valueList[] = common_Utils::toResource($triple->object);
}

Expand All @@ -351,14 +358,16 @@ public function unsetProperty(core_kernel_classes_Class $resource, core_kernel_c

public function createInstanceWithProperties(core_kernel_classes_Class $type, $properties)
{
$returnValue = null;

if (isset($properties[OntologyRdf::RDF_TYPE])) {
throw new core_kernel_persistence_Exception('Additional types in createInstanceWithProperties not permited');
throw new core_kernel_persistence_Exception(
'Additional types in createInstanceWithProperties not permitted'
);
}

$properties[OntologyRdf::RDF_TYPE] = $type;
$returnValue = $this->getModel()->getResource($this->getServiceLocator()->get(UriProvider::SERVICE_ID)->provide());
$returnValue = $this->getModel()->getResource(
$this->getServiceLocator()->get(UriProvider::SERVICE_ID)->provide()
);
$returnValue->setPropertiesValues($properties);

return $returnValue;
Expand Down
21 changes: 12 additions & 9 deletions core/kernel/persistence/starsql/class.Property.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -21,12 +22,12 @@

use oat\generis\model\GenerisRdf;
use oat\generis\model\OntologyRdfs;

use function WikibaseSolutions\CypherDSL\node;
use function WikibaseSolutions\CypherDSL\query;
use function WikibaseSolutions\CypherDSL\procedure;
use function WikibaseSolutions\CypherDSL\relationshipTo;

class core_kernel_persistence_starsql_Property extends core_kernel_persistence_starsql_Resource implements core_kernel_persistence_PropertyInterface
class core_kernel_persistence_starsql_Property extends core_kernel_persistence_starsql_Resource implements
core_kernel_persistence_PropertyInterface
{
public static $instance = null;

Expand All @@ -46,16 +47,18 @@ public function isLgDependent(core_kernel_classes_Resource $resource): bool

public function isMultiple(core_kernel_classes_Resource $resource): bool
{
$returnValue = (bool) false;
throw new core_kernel_persistence_ProhibitedFunctionException("not implemented => The function (" . __METHOD__ . ") is not available in this persistence implementation (" . __CLASS__ . ")");
return (bool) $returnValue;
throw new core_kernel_persistence_ProhibitedFunctionException(
"not implemented => The function (" . __METHOD__
. ") is not available in this persistence implementation (" . __CLASS__ . ")"
);
}

public function getRange(core_kernel_classes_Resource $resource): core_kernel_classes_Class
{
$returnValue = null;
throw new core_kernel_persistence_ProhibitedFunctionException("not implemented => The function (" . __METHOD__ . ") is not available in this persistence implementation (" . __CLASS__ . ")");
return $returnValue;
throw new core_kernel_persistence_ProhibitedFunctionException(
"not implemented => The function (" . __METHOD__
. ") is not available in this persistence implementation (" . __CLASS__ . ")"
);
}

public function delete(core_kernel_classes_Resource $resource, $deleteReference = false): bool
Expand Down
88 changes: 61 additions & 27 deletions core/kernel/persistence/starsql/class.Resource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -20,17 +21,15 @@
declare(strict_types=1);

use oat\generis\model\OntologyRdf;
use oat\generis\model\OntologyRdfs;
use oat\oatbox\session\SessionService;
use oat\oatbox\user\UserLanguageServiceInterface;
use oat\generis\model\kernel\uri\UriProvider;
use oat\tao\model\TaoOntology;
use WikibaseSolutions\CypherDSL\Clauses\SetClause;
use Zend\ServiceManager\ServiceLocatorInterface;

use function WikibaseSolutions\CypherDSL\node;
use function WikibaseSolutions\CypherDSL\query;
use function WikibaseSolutions\CypherDSL\parameter;
use function WikibaseSolutions\CypherDSL\procedure;
use function WikibaseSolutions\CypherDSL\query;
use function WikibaseSolutions\CypherDSL\raw;
use function WikibaseSolutions\CypherDSL\relationshipTo;
use function WikibaseSolutions\CypherDSL\variable;
Expand Down Expand Up @@ -89,8 +88,11 @@ public function getTypes(core_kernel_classes_Resource $resource): array
return (array) $returnValue;
}

public function getPropertyValues(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property, $options = []): array
{
public function getPropertyValues(
core_kernel_classes_Resource $resource,
core_kernel_classes_Property $property,
$options = []
): array {
if (isset($options['last'])) {
throw new core_kernel_persistence_Exception('Option \'last\' no longer supported');
}
Expand All @@ -110,7 +112,10 @@ public function getPropertyValues(core_kernel_classes_Resource $resource, core_k
->returning($node->property($property->getUri()));
}

$results = $this->getPersistence()->run($query->build(), [$uriParameter->getParameter() => $resource->getUri()]);
$results = $this->getPersistence()->run(
$query->build(),
[$uriParameter->getParameter() => $resource->getUri()]
);
$values = [];
$selectedLanguage = $options['lg'] ?? null;
$dataLanguage = $this->getDataLanguage();
Expand All @@ -125,7 +130,10 @@ public function getPropertyValues(core_kernel_classes_Resource $resource, core_k
if (isset($selectedLanguage)) {
$values = array_merge($values, $this->filterRecordsByLanguage($value, [$selectedLanguage]));
} else {
$values = array_merge($values, $this->filterRecordsByAvailableLanguage($value, $dataLanguage, $defaultLanguage));
$values = array_merge(
$values,
$this->filterRecordsByAvailableLanguage($value, $dataLanguage, $defaultLanguage)
);
}
} else {
$values[] = $this->parseTranslatedValue($value);
Expand All @@ -135,8 +143,11 @@ public function getPropertyValues(core_kernel_classes_Resource $resource, core_k
return $values;
}

public function getPropertyValuesByLg(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property, $lg): core_kernel_classes_ContainerCollection
{
public function getPropertyValuesByLg(
core_kernel_classes_Resource $resource,
core_kernel_classes_Property $property,
$lg
): core_kernel_classes_ContainerCollection {
$options = ['lg' => $lg];

$returnValue = new core_kernel_classes_ContainerCollection($resource);
Expand All @@ -147,8 +158,12 @@ public function getPropertyValuesByLg(core_kernel_classes_Resource $resource, co
return $returnValue;
}

public function setPropertyValue(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property, $object, $lg = null): ?bool
{
public function setPropertyValue(
core_kernel_classes_Resource $resource,
core_kernel_classes_Property $property,
$object,
$lg = null
): ?bool {
$uri = $resource->getUri();
$propertyUri = $property->getUri();
if ($object instanceof core_kernel_classes_Resource) {
Expand All @@ -171,7 +186,8 @@ public function setPropertyValue(core_kernel_classes_Resource $resource, core_ke
WHERE a.uri = \$uri AND b.uri = \$object
CREATE (a)-[r:`{$propertyUri}`]->(b)
RETURN type(r)
CYPHER; } else if($property->isLgDependent()) {
CYPHER;
} elseif ($property->isLgDependent()) {
$query = <<<CYPHER
MATCH (n:Resource {uri: \$uri})
SET n.`{$propertyUri}` = coalesce(n.`{$propertyUri}`, []) + \$object
Expand Down Expand Up @@ -257,7 +273,9 @@ public function setPropertiesValues(core_kernel_classes_Resource $resource, $pro
foreach ($relationshipTypes as $type) {
$variableForRelatedResource = variable();
$nodeForRelationship = node()->withVariable($variableForRelatedResource);
$relatedResource = node('Resource')->withProperties(['uri' => $relatedUriParameter = parameter()])->withVariable($variableForRelatedResource);
$relatedResource = node('Resource')
->withProperties(['uri' => $relatedUriParameter = parameter()])
->withVariable($variableForRelatedResource);
$parameters[$relatedUriParameter->getParameter()] = $target;
$node = $node->relationshipTo($nodeForRelationship, $type);
$relatedResources[] = $relatedResource;
Expand All @@ -275,13 +293,20 @@ public function setPropertiesValues(core_kernel_classes_Resource $resource, $pro
return true;
}

public function setPropertyValueByLg(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property, $value, $lg): ?bool
{
public function setPropertyValueByLg(
core_kernel_classes_Resource $resource,
core_kernel_classes_Property $property,
$value,
$lg
): ?bool {
return $this->setPropertyValue($resource, $property, $value, $lg);
}

public function removePropertyValues(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property, $options = []): ?bool
{
public function removePropertyValues(
core_kernel_classes_Resource $resource,
core_kernel_classes_Property $property,
$options = []
): ?bool {
$uri = $resource->getUri();
$propertyUri = $property->getUri();
$conditions = [];
Expand Down Expand Up @@ -325,16 +350,20 @@ public function removePropertyValues(core_kernel_classes_Resource $resource, cor
RETURN n
CYPHER;

// @FIXME if value is array, then query should be for update. Try to deduce if $prop->isLgDependent or isMultiple
// @FIXME if property is represented as node relationship, query should remove that instead
//@FIXME if value is array, then query should be for update. Try to deduce if $prop->isLgDependent or isMultiple
//@FIXME if property is represented as node relationship, query should remove that instead

$this->getPersistence()->run($query);

return true;
}

public function removePropertyValueByLg(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property, $lg, $options = []): ?bool
{
public function removePropertyValueByLg(
core_kernel_classes_Resource $resource,
core_kernel_classes_Property $property,
$lg,
$options = []
): ?bool {
if (!$property->isLgDependent()) {
return $this->removePropertyValues($resource, $property, $options);
}
Expand Down Expand Up @@ -404,8 +433,10 @@ public function isWritable(core_kernel_classes_Resource $resource): bool
return $this->model->isWritable($resource);
}

public function getUsedLanguages(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property): array
{
public function getUsedLanguages(
core_kernel_classes_Resource $resource,
core_kernel_classes_Property $property
): array {
$node = node()->withProperties(['uri' => $uriParameter = parameter()])
->withLabels(['Resource']);
$query = query()
Expand All @@ -431,8 +462,10 @@ public function getUsedLanguages(core_kernel_classes_Resource $resource, core_ke
return (array) $foundLanguages;
}

public function duplicate(core_kernel_classes_Resource $resource, $excludedProperties = []): core_kernel_classes_Resource
{
public function duplicate(
core_kernel_classes_Resource $resource,
$excludedProperties = []
): core_kernel_classes_Resource {
throw new common_Exception('Not implemented! ' . __FILE__ . ' line: ' . __LINE__);
}

Expand Down Expand Up @@ -463,7 +496,8 @@ public function getPropertiesValues(core_kernel_classes_Resource $resource, $pro
$query = <<<CYPHER
MATCH (resource:Resource)-[relationshipTo]->(relatedResource:Resource)
WHERE resource.uri = \$uri
RETURN resource, collect({relationship: type(relationshipTo), relatedResourceUri: relatedResource.uri}) AS relationships
RETURN resource,
collect({relationship: type(relationshipTo), relatedResourceUri: relatedResource.uri}) AS relationships
CYPHER;

$results = $this->getPersistence()->run($query, ['uri' => $resource->getUri()]);
Expand Down
Loading

0 comments on commit 93296c4

Please sign in to comment.