diff --git a/common/persistence/class.GraphPersistence.php b/common/persistence/class.GraphPersistence.php index 3a28f5f7a..44abd3ca9 100644 --- a/common/persistence/class.GraphPersistence.php +++ b/common/persistence/class.GraphPersistence.php @@ -1,4 +1,5 @@ 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 + ); } /** diff --git a/core/kernel/persistence/starsql/FlatRecursiveIterator.php b/core/kernel/persistence/starsql/FlatRecursiveIterator.php index 881c06030..0b114b2d2 100644 --- a/core/kernel/persistence/starsql/FlatRecursiveIterator.php +++ b/core/kernel/persistence/starsql/FlatRecursiveIterator.php @@ -1,4 +1,5 @@ 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() @@ -249,14 +252,20 @@ 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); $properties = [ OntologyRdfs::RDFS_DOMAIN => $resource->getUri(), - GenerisRdf::PROPERTY_IS_LG_DEPENDENT => ((bool)$isLgDependent) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE + GenerisRdf::PROPERTY_IS_LG_DEPENDENT => ((bool)$isLgDependent) + ? GenerisRdf::GENERIS_TRUE + : GenerisRdf::GENERIS_FALSE, ]; if (!empty($label)) { $properties[OntologyRdfs::RDFS_LABEL] = $label; @@ -334,14 +343,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; diff --git a/core/kernel/persistence/starsql/class.Property.php b/core/kernel/persistence/starsql/class.Property.php index f20c0ca3e..1ddd2c626 100644 --- a/core/kernel/persistence/starsql/class.Property.php +++ b/core/kernel/persistence/starsql/class.Property.php @@ -1,4 +1,5 @@ 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 diff --git a/core/kernel/persistence/starsql/class.Resource.php b/core/kernel/persistence/starsql/class.Resource.php index 223b538fe..8c8007ce4 100644 --- a/core/kernel/persistence/starsql/class.Resource.php +++ b/core/kernel/persistence/starsql/class.Resource.php @@ -1,4 +1,5 @@ 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(); @@ -124,7 +132,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); @@ -134,8 +145,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); @@ -146,8 +160,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) { @@ -170,7 +188,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 = <<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; @@ -274,13 +295,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 = []; @@ -324,16 +352,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 { throw new common_Exception('Not implemented! ' . __FILE__ . ' line: ' . __LINE__); } @@ -383,8 +415,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() @@ -410,8 +444,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__); } @@ -442,7 +478,8 @@ public function getPropertiesValues(core_kernel_classes_Resource $resource, $pro $query = <<(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()]); diff --git a/core/kernel/persistence/starsql/class.StarModel.php b/core/kernel/persistence/starsql/class.StarModel.php index eb3df26a7..6ba42395c 100644 --- a/core/kernel/persistence/starsql/class.StarModel.php +++ b/core/kernel/persistence/starsql/class.StarModel.php @@ -1,4 +1,5 @@ setModel($this); return $resource; } - function getClass($uri) + public function getClass($uri) { $class = new \core_kernel_classes_Class($uri); $class->setModel($this); return $class; } - function getProperty($uri) + public function getProperty($uri) { $property = new \core_kernel_classes_Property($uri); $property->setModel($this); diff --git a/core/kernel/persistence/starsql/class.StarRdf.php b/core/kernel/persistence/starsql/class.StarRdf.php index 1ac072b17..24d0ed118 100644 --- a/core/kernel/persistence/starsql/class.StarRdf.php +++ b/core/kernel/persistence/starsql/class.StarRdf.php @@ -1,4 +1,5 @@ modelid) && $triple->modelid != \core_kernel_persistence_starsql_StarModel::DEFAULT_WRITABLE_MODEL) { + if ( + !empty($triple->modelid) + && $triple->modelid != \core_kernel_persistence_starsql_StarModel::DEFAULT_WRITABLE_MODEL + ) { $systemSubjectList[$triple->subject] = true; } } diff --git a/core/kernel/persistence/starsql/class.StarRdfs.php b/core/kernel/persistence/starsql/class.StarRdfs.php index a0a24290a..1a4782365 100644 --- a/core/kernel/persistence/starsql/class.StarRdfs.php +++ b/core/kernel/persistence/starsql/class.StarRdfs.php @@ -1,4 +1,5 @@ '\\.', '\\_' => '_', '\\%' => '%', diff --git a/core/kernel/persistence/starsql/search/Neo4jEscapeDriver.php b/core/kernel/persistence/starsql/search/Neo4jEscapeDriver.php index 3baf89c07..3dcb17ebe 100644 --- a/core/kernel/persistence/starsql/search/Neo4jEscapeDriver.php +++ b/core/kernel/persistence/starsql/search/Neo4jEscapeDriver.php @@ -1,22 +1,21 @@ like(); } } diff --git a/test/integration/ClassTest.php b/test/integration/ClassTest.php index e3d720b85..00207281d 100755 --- a/test/integration/ClassTest.php +++ b/test/integration/ClassTest.php @@ -385,9 +385,9 @@ public function testSearchInstancesWithOrder() { $class = new core_kernel_classes_Class(WidgetRdf::CLASS_URI_WIDGET); $subClass = $class->createSubClass(); - $sub1ClassInstance = $subClass->createInstance( 'test case instance'); - $sub2ClassInstance = $subClass->createInstance( 'second test case instance'); - $sub3ClassInstance = $subClass->createInstance( 'test case instance 3'); + $sub1ClassInstance = $subClass->createInstance('test case instance'); + $sub2ClassInstance = $subClass->createInstance('second test case instance'); + $sub3ClassInstance = $subClass->createInstance('test case instance 3'); $instances = $class->searchInstances( [ @@ -517,17 +517,17 @@ public function testSearchInstancesLanguageSpecific() $class = new core_kernel_classes_Class(WidgetRdf::CLASS_URI_WIDGET); $labelProperty = new \core_kernel_classes_Property(OntologyRdfs::RDFS_LABEL); $sub1Class = $class->createSubClass(); - $sub1ClassInstance = $sub1Class->createInstance( 'test case instance'); //en-US + $sub1ClassInstance = $sub1Class->createInstance('test case instance'); //en-US $sub1ClassInstance->setPropertyValueByLg($labelProperty, 'instance de cas de test', 'fr-FR'); $sub1ClassInstance->setPropertyValueByLg($labelProperty, 'Testfallinstanz', 'de-DE'); $sub2Class = $sub1Class->createSubClass(); - $sub2ClassInstance = $sub2Class->createInstance( 'second test case instance'); //en-US + $sub2ClassInstance = $sub2Class->createInstance('second test case instance'); //en-US $sub2ClassInstance->setPropertyValueByLg($labelProperty, 'deuxième instance de cas de test', 'fr-FR'); $sub2ClassInstance->setPropertyValueByLg($labelProperty, 'zweite Testfallinstanz', 'de-DE'); $sub3Class = $sub2Class->createSubClass(); - $sub3ClassInstance = $sub3Class->createInstance( 'test case instance 3'); //en-US + $sub3ClassInstance = $sub3Class->createInstance('test case instance 3'); //en-US $sub3ClassInstance->setPropertyValueByLg($labelProperty, 'exemple de cas de test 3', 'fr-FR'); $sub3ClassInstance->setPropertyValueByLg($labelProperty, 'Testfallinstanz 3', 'de-DE'); diff --git a/test/integration/RdfExportTest.php b/test/integration/RdfExportTest.php index b1f23e7b8..2e3b0f149 100755 --- a/test/integration/RdfExportTest.php +++ b/test/integration/RdfExportTest.php @@ -45,7 +45,7 @@ public function testFullExport() $count = 0; foreach ($descriptions as $description) { foreach ($description as $child) { - $count+=count($child); + $count += count($child); } } diff --git a/test/integration/model/persistence/starsql/ClassTest.php b/test/integration/model/persistence/starsql/ClassTest.php index fb3d9a0ca..32b3541b4 100755 --- a/test/integration/model/persistence/starsql/ClassTest.php +++ b/test/integration/model/persistence/starsql/ClassTest.php @@ -66,7 +66,7 @@ protected function tearDown(): void { $ontologyModel = ModelManager::getModel(); /** @var ClassRepository $classRepo */ - foreach($this->cleanupList as $classUri) { + foreach ($this->cleanupList as $classUri) { $class = new \core_kernel_classes_Class($classUri); $instances = $class->searchInstances( [ @@ -185,12 +185,12 @@ public function testSearchInstancesMultipleImpl() { $class = new core_kernel_classes_Class(WidgetRdf::CLASS_URI_WIDGET); $sub1Class = $class->createSubClass(); - $sub1ClassInstance = $sub1Class->createInstance( 'test case instance'); + $sub1ClassInstance = $sub1Class->createInstance('test case instance'); $sub2Class = $sub1Class->createSubClass(); - $sub2ClassInstance = $sub2Class->createInstance( 'second test case instance'); + $sub2ClassInstance = $sub2Class->createInstance('second test case instance'); $sub3Class = $sub2Class->createSubClass(); - $sub3ClassInstance = $sub3Class->createInstance( 'test case instance 3'); - $sub4ClassInstance = $sub3Class->createInstance( 'non-matching instance'); + $sub3ClassInstance = $sub3Class->createInstance('test case instance 3'); + $sub4ClassInstance = $sub3Class->createInstance('non-matching instance'); $propertyFilter = [ OntologyRdfs::RDFS_LABEL => 'test case instance' @@ -208,9 +208,9 @@ public function testSearchInstancesWithOr() { $class = new core_kernel_classes_Class(WidgetRdf::CLASS_URI_WIDGET); $subClass = $class->createSubClass(); - $sub1ClassInstance = $subClass->createInstance( 'first test case instance', 'first test case instance'); - $sub2ClassInstance = $subClass->createInstance( 'second test case instance', 'second test case instance'); - $sub3ClassInstance = $subClass->createInstance( 'non-matching instance', 'non-matching instance'); + $sub1ClassInstance = $subClass->createInstance('first test case instance', 'first test case instance'); + $sub2ClassInstance = $subClass->createInstance('second test case instance', 'second test case instance'); + $sub3ClassInstance = $subClass->createInstance('non-matching instance', 'non-matching instance'); $propertyFilter = [ OntologyRdfs::RDFS_LABEL => 'first test case instance', @@ -239,8 +239,8 @@ public function testSearchInstancesComplexQuery() ); $relationProperty->setRange($relationSubClass); - $sub1ClassInstance = $subClass->createInstance( 'test case instance'); - $sub2ClassInstance = $relationSubClass->createInstance( 'relation test case instance'); + $sub1ClassInstance = $subClass->createInstance('test case instance'); + $sub2ClassInstance = $relationSubClass->createInstance('relation test case instance'); $sub1ClassInstance->setPropertyValue($relationProperty, $sub2ClassInstance); $instances = $subClass->searchInstances( @@ -260,10 +260,10 @@ public function testSearchInstancesWithOrder() { $class = new core_kernel_classes_Class(WidgetRdf::CLASS_URI_WIDGET); $subClass = $class->createSubClass(); - $sub1ClassInstance = $subClass->createInstance( 'test case instance'); - $sub2ClassInstance = $subClass->createInstance( 'second test case instance'); - $sub3ClassInstance = $subClass->createInstance( 'test case instance 3'); - $sub4ClassInstance = $subClass->createInstance( 'non-matching instance'); + $sub1ClassInstance = $subClass->createInstance('test case instance'); + $sub2ClassInstance = $subClass->createInstance('second test case instance'); + $sub3ClassInstance = $subClass->createInstance('test case instance 3'); + $sub4ClassInstance = $subClass->createInstance('non-matching instance'); $instances = $subClass->searchInstances( [ @@ -397,21 +397,21 @@ public function testSearchInstancesLanguageSpecific() $class = new core_kernel_classes_Class(WidgetRdf::CLASS_URI_WIDGET); $labelProperty = new \core_kernel_classes_Property(OntologyRdfs::RDFS_LABEL); $sub1Class = $class->createSubClass(); - $sub1ClassInstance = $sub1Class->createInstance( 'test case instance'); //en-US + $sub1ClassInstance = $sub1Class->createInstance('test case instance'); //en-US $sub1ClassInstance->setPropertyValueByLg($labelProperty, 'instance de cas de test', 'fr-FR'); $sub1ClassInstance->setPropertyValueByLg($labelProperty, 'Testfallinstanz', 'de-DE'); $sub2Class = $sub1Class->createSubClass(); - $sub2ClassInstance = $sub2Class->createInstance( 'second test case instance'); //en-US + $sub2ClassInstance = $sub2Class->createInstance('second test case instance'); //en-US $sub2ClassInstance->setPropertyValueByLg($labelProperty, 'deuxième instance de cas de test', 'fr-FR'); $sub2ClassInstance->setPropertyValueByLg($labelProperty, 'zweite Testfallinstanz', 'de-DE'); $sub3Class = $sub2Class->createSubClass(); - $sub3ClassInstance = $sub3Class->createInstance( 'test case instance 3'); //en-US + $sub3ClassInstance = $sub3Class->createInstance('test case instance 3'); //en-US $sub3ClassInstance->setPropertyValueByLg($labelProperty, 'exemple de cas de test 3', 'fr-FR'); $sub3ClassInstance->setPropertyValueByLg($labelProperty, 'Testfallinstanz 3', 'de-DE'); - $sub4ClassInstance = $sub3Class->createInstance( 'non-matching instance'); //en-US + $sub4ClassInstance = $sub3Class->createInstance('non-matching instance'); //en-US $sub4ClassInstance->setPropertyValueByLg($labelProperty, 'instance non correspondante', 'fr-FR'); $sub4ClassInstance->setPropertyValueByLg($labelProperty, 'nicht passende Instanz', 'de-DE');