Skip to content

Commit

Permalink
PredicateTemplate and QuadTemplate: make immutable and add with*() me…
Browse files Browse the repository at this point in the history
…thods

PredicateTemplate: add $negate parameter to the constructor
  • Loading branch information
zozlak committed Sep 1, 2023
1 parent b35d8e6 commit bac9480
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
30 changes: 25 additions & 5 deletions src/termTemplates/PredicateTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace termTemplates;

use rdfInterface\TermInterface;
use rdfInterface\TermCompareInterface;
use rdfInterface\QuadCompareInterface;

Expand All @@ -39,10 +38,11 @@ class PredicateTemplate implements TermCompareInterface, QuadCompareInterface {

private QuadTemplate $tmpl;

public function __construct(TermCompareInterface | TermInterface | null $predicate = null,
TermCompareInterface | TermInterface | null $object = null,
TermCompareInterface | TermInterface | null $graph = null) {
$this->tmpl = new QuadTemplate(null, $predicate, $object, $graph);
public function __construct(TermCompareInterface | null $predicate = null,
TermCompareInterface | null $object = null,
TermCompareInterface | null $graph = null,
bool $negate = false) {
$this->tmpl = new QuadTemplate(null, $predicate, $object, $graph, $negate);
}

public function __toString(): string {
Expand All @@ -68,4 +68,24 @@ public function getObject(): TermCompareInterface | null {
public function getGraph(): TermCompareInterface | null {
return $this->tmpl->getGraph();
}

public function withSubject(TermCompareInterface | string | null $subject = null): self {
return $this->tmpl->withSubject($subject);

Check failure on line 73 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withSubject() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.

Check failure on line 73 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withSubject() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.
}

public function withPredicate(TermCompareInterface | string | null $predicate = null): self {
return $this->tmpl->withPredicate($predicate);

Check failure on line 77 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withPredicate() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.

Check failure on line 77 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withPredicate() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.
}

public function withObject(TermCompareInterface | string | null $object = null): self {
return $this->tmpl->withObject($object);

Check failure on line 81 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withObject() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.

Check failure on line 81 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withObject() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.
}

public function withGraph(TermCompareInterface | string | null $graph = null): self {
return $this->tmpl->withGraph($graph);

Check failure on line 85 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withGraph() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.

Check failure on line 85 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withGraph() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.
}

public function withNegate(bool $negate): self {
return $this->tmpl->withNegate($negate);

Check failure on line 89 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withNegate() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.

Check failure on line 89 in src/termTemplates/PredicateTemplate.php

View workflow job for this annotation

GitHub Actions / phpstan

Method termTemplates\PredicateTemplate::withNegate() should return termTemplates\PredicateTemplate but returns termTemplates\QuadTemplate.
}
}
39 changes: 29 additions & 10 deletions src/termTemplates/QuadTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace termTemplates;

use rdfInterface\QuadInterface;
use rdfInterface\TermInterface;
use rdfInterface\TermCompareInterface;
use rdfInterface\QuadCompareInterface;
use rdfInterface\DefaultGraphInterface;
Expand All @@ -39,16 +38,16 @@
*/
class QuadTemplate implements TermCompareInterface, QuadCompareInterface {

public TermCompareInterface | TermInterface | null $subject;
public TermCompareInterface | TermInterface | null $predicate;
public TermCompareInterface | TermInterface | null $object;
public TermCompareInterface | TermInterface | null $graph;
public bool $negate;
private TermCompareInterface | null $subject;
private TermCompareInterface | null $predicate;
private TermCompareInterface | null $object;
private TermCompareInterface | null $graph;
private bool $negate;

public function __construct(TermCompareInterface | TermInterface | string | null $subject = null,
TermCompareInterface | TermInterface | string | null $predicate = null,
TermCompareInterface | TermInterface | string | null $object = null,
TermCompareInterface | TermInterface | string | null $graph = null,
public function __construct(TermCompareInterface | string | null $subject = null,
TermCompareInterface | string | null $predicate = null,
TermCompareInterface | string | null $object = null,
TermCompareInterface | string | null $graph = null,
bool $negate = false) {
$this->subject = is_string($subject) ? new ValueTemplate($subject) : $subject;
$this->predicate = is_string($predicate) ? new ValueTemplate($predicate) : $predicate;
Expand Down Expand Up @@ -88,4 +87,24 @@ public function getObject(): TermCompareInterface | null {
public function getGraph(): TermCompareInterface | null {
return $this->graph;
}

public function withSubject(TermCompareInterface | string | null $subject = null): self {
return new QuadTemplate($subject, $this->predicate, $this->object, $this->graph, $this->negate);
}

public function withPredicate(TermCompareInterface | string | null $predicate = null): self {
return new QuadTemplate($this->subject, $predicate, $this->object, $this->graph, $this->negate);
}

public function withObject(TermCompareInterface | string | null $object = null): self {
return new QuadTemplate($this->subject, $this->predicate, $object, $this->graph, $this->negate);
}

public function withGraph(TermCompareInterface | string | null $graph = null): self {
return new QuadTemplate($this->subject, $this->predicate, $this->object, $graph, $this->negate);
}

public function withNegate(bool $negate): self {
return new QuadTemplate($this->subject, $this->predicate, $this->object, $this->graph, $negate);
}
}

0 comments on commit bac9480

Please sign in to comment.